Skip to content

Commit

Permalink
Merge branches 'jc/apply', 'lt/ls-tree', 'lt/bisect' and 'lt/merge'
Browse files Browse the repository at this point in the history
  • Loading branch information
Junio C Hamano committed Nov 30, 2005
5 parents 0738fc2 + 830273d + 246cc52 + e9a45d7 + 0501c24 commit 5401f30
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 320 deletions.
9 changes: 9 additions & 0 deletions Documentation/git-diff-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ OPTIONS
-------
include::diff-options.txt[]

-1 -2 -3 or --base --ours --theirs, and -0::
Diff against the "base" version, "our branch" or "their
branch" respectively. With these options, diffs for
merged entries are not shown.
+
The default is to diff against our branch (-2) and the
cleanly resolved paths. The option -0 can be given to
omit diff output for unmerged entries and just show "Unmerged".

-q::
Remain silent even on nonexisting files

Expand Down
15 changes: 7 additions & 8 deletions Documentation/tutorial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,8 @@ file, which had no differences in the `mybranch` branch), and say:
fatal: Merge requires file-level merging
Nope.
...
merge: warning: conflicts during merge
ERROR: Merge conflict in hello.
fatal: merge program failed
Auto-merging hello
CONFLICT (content): Merge conflict in hello
Automatic merge failed/prevented; fix up by hand
----------------

Expand Down Expand Up @@ -942,10 +941,10 @@ environment, is `git show-branch`.

------------------------------------------------
$ git show-branch master mybranch
* [master] Merged "mybranch" changes.
* [master] Merge work in mybranch
! [mybranch] Some work.
--
+ [master] Merged "mybranch" changes.
+ [master] Merge work in mybranch
++ [mybranch] Some work.
------------------------------------------------

Expand Down Expand Up @@ -998,10 +997,10 @@ looks like, or run `show-branch`, which tells you this.

------------------------------------------------
$ git show-branch master mybranch
! [master] Merged "mybranch" changes.
* [mybranch] Merged "mybranch" changes.
! [master] Merge work in mybranch
* [mybranch] Merge work in mybranch
--
++ [master] Merged "mybranch" changes.
++ [master] Merge work in mybranch
------------------------------------------------


Expand Down
43 changes: 36 additions & 7 deletions diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include "diff.h"

static const char diff_files_usage[] =
"git-diff-files [-q] "
"[<common diff options>] [<path>...]"
"git-diff-files [-q] [-0/-1/2/3] [<common diff options>] [<path>...]"
COMMON_DIFF_OPTIONS_HELP;

static struct diff_options diff_options;
static int silent = 0;
static int diff_unmerged_stage = 2;

static void show_unmerge(const char *path)
{
Expand Down Expand Up @@ -46,7 +46,21 @@ int main(int argc, const char **argv)
argc--;
break;
}
if (!strcmp(argv[1], "-q"))
if (!strcmp(argv[1], "-0"))
diff_unmerged_stage = 0;
else if (!strcmp(argv[1], "-1"))
diff_unmerged_stage = 1;
else if (!strcmp(argv[1], "-2"))
diff_unmerged_stage = 2;
else if (!strcmp(argv[1], "-3"))
diff_unmerged_stage = 3;
else if (!strcmp(argv[1], "--base"))
diff_unmerged_stage = 1;
else if (!strcmp(argv[1], "--ours"))
diff_unmerged_stage = 2;
else if (!strcmp(argv[1], "--theirs"))
diff_unmerged_stage = 3;
else if (!strcmp(argv[1], "-q"))
silent = 1;
else if (!strcmp(argv[1], "-r"))
; /* no-op */
Expand Down Expand Up @@ -95,11 +109,26 @@ int main(int argc, const char **argv)

if (ce_stage(ce)) {
show_unmerge(ce->name);
while (i < entries &&
!strcmp(ce->name, active_cache[i]->name))
while (i < entries) {
struct cache_entry *nce = active_cache[i];

if (strcmp(ce->name, nce->name))
break;
/* diff against the proper unmerged stage */
if (ce_stage(nce) == diff_unmerged_stage)
ce = nce;
i++;
i--; /* compensate for loop control increments */
continue;
}
/*
* Compensate for loop update
*/
i--;
/*
* Show the diff for the 'ce' if we found the one
* from the desired stage.
*/
if (ce_stage(ce) != diff_unmerged_stage)
continue;
}

if (lstat(ce->name, &st) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion git-applymbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ do
-k) keep_subject=-k ;;
-q) query_apply=t ;;
-c) continue="$2"; resume=f; shift ;;
-m) fallback_3way=t ;;
-m) fall_back_3way=t ;;
-*) usage ;;
*) break ;;
esac
Expand Down
37 changes: 24 additions & 13 deletions git-applypatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,36 @@ git-apply --index "$PATCHFILE" || {
O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
rm -fr .patch-merge-*

if git-apply -z --index-info "$PATCHFILE" \
>.patch-merge-index-info 2>/dev/null &&
GIT_INDEX_FILE=.patch-merge-tmp-index \
git-update-index -z --index-info <.patch-merge-index-info &&
GIT_INDEX_FILE=.patch-merge-tmp-index \
git-write-tree >.patch-merge-tmp-base &&
(
mkdir .patch-merge-tmp-dir &&
cd .patch-merge-tmp-dir &&
GIT_INDEX_FILE="../.patch-merge-tmp-index" \
GIT_OBJECT_DIRECTORY="$O_OBJECT" \
git-apply $binary --index
) <"$PATCHFILE"
then
echo Using index info to reconstruct a base tree...
mv .patch-merge-tmp-base .patch-merge-base
mv .patch-merge-tmp-index .patch-merge-index
else
(
N=10

# if the patch records the base tree...
sed -ne '
/^diff /q
/^applies-to: \([0-9a-f]*\)$/{
s//\1/p
q
}
' "$PATCHFILE"

# or hoping the patch is against our recent commits...
# Otherwise, try nearby trees that can be used to apply the
# patch.
git-rev-list --max-count=$N HEAD

# or hoping the patch is against known tags...
git-ls-remote --tags .
) |
while read base junk
do
while read base junk
do
# Try it if we have it as a tree.
git-cat-file tree "$base" >/dev/null 2>&1 || continue

Expand All @@ -155,7 +165,8 @@ git-apply --index "$PATCHFILE" || {
mv ../.patch-merge-tmp-index ../.patch-merge-index &&
echo "$base" >../.patch-merge-base
) <"$PATCHFILE" 2>/dev/null && break
done
done
fi

test -f .patch-merge-index &&
his_tree=$(GIT_INDEX_FILE=.patch-merge-index git-write-tree) &&
Expand Down
29 changes: 22 additions & 7 deletions git-bisect.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/bin/sh
. git-sh-setup

sq() {
perl -e '
for (@ARGV) {
s/'\''/'\'\\\\\'\''/g;
print " '\''$_'\''";
}
print "\n";
' "$@"
}

usage() {
echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
git bisect start reset bisect state and start bisection.
git bisect start [<pathspec>] reset bisect state and start bisection.
git bisect bad [<rev>] mark <rev> a known-bad revision.
git bisect good [<rev>...] mark <rev>... known-good revisions.
git bisect next find next bisection to test and check it out.
Expand Down Expand Up @@ -33,7 +43,6 @@ bisect_autostart() {
}

bisect_start() {
case "$#" in 0) ;; *) usage ;; esac
#
# Verify HEAD. If we were bisecting before this, reset to the
# top-of-line master first!
Expand All @@ -57,7 +66,11 @@ bisect_start() {
rm -f "$GIT_DIR/refs/heads/bisect"
rm -rf "$GIT_DIR/refs/bisect/"
mkdir "$GIT_DIR/refs/bisect"
echo "git-bisect start" >"$GIT_DIR/BISECT_LOG"
{
echo -n "git-bisect start"
sq "$@"
} >"$GIT_DIR/BISECT_LOG"
sq "$@" >"$GIT_DIR/BISECT_NAMES"
}

bisect_bad() {
Expand Down Expand Up @@ -121,7 +134,7 @@ bisect_next() {
bad=$(git-rev-parse --verify refs/bisect/bad) &&
good=$(git-rev-parse --sq --revs-only --not \
$(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
rev=$(eval "git-rev-list --bisect $good $bad") || exit
rev=$(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") || exit
if [ -z "$rev" ]; then
echo "$bad was both good and bad"
exit 1
Expand All @@ -131,7 +144,7 @@ bisect_next() {
git-diff-tree --pretty $rev
exit 0
fi
nr=$(eval "git-rev-list $rev $good" | wc -l) || exit
nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
echo "Bisecting: $nr revisions left to test after this"
echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
git checkout new-bisect || exit
Expand All @@ -142,7 +155,8 @@ bisect_next() {

bisect_visualize() {
bisect_next_check fail
gitk bisect/bad --not `cd "$GIT_DIR/refs" && echo bisect/good-*`
not=`cd "$GIT_DIR/refs" && echo bisect/good-*`
eval gitk bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES")
}

bisect_reset() {
Expand Down Expand Up @@ -173,7 +187,8 @@ bisect_replay () {
test "$bisect" = "git-bisect" || continue
case "$command" in
start)
bisect_start
cmd="bisect_start $rev"
eval "$cmd"
;;
good)
echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
Expand Down
9 changes: 6 additions & 3 deletions git-format-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

. git-sh-setup

# Force diff to run in C locale.
LANG=C LC_ALL=C
export LANG LC_ALL

usage () {
echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
[--check] [--signoff] [-<diff options>...]
Expand Down Expand Up @@ -202,7 +206,7 @@ process_one () {
;;
esac

eval "$(LANG=C LC_ALL=C sed -ne "$whosepatchScript" $commsg)"
eval "$(sed -ne "$whosepatchScript" $commsg)"
test "$author,$au" = ",$me" || {
mailScript="$mailScript"'
a\
Expand Down Expand Up @@ -238,9 +242,8 @@ Date: '"$ad"
echo
git-diff-tree -p $diff_opts "$commit" | git-apply --stat --summary
echo
git-cat-file commit "$commit^" | sed -e 's/^tree /applies-to: /' -e q
git-diff-tree -p $diff_opts "$commit"
echo "---"
echo "-- "
echo "@@GIT_VERSION@@"

case "$mbox" in
Expand Down
6 changes: 1 addition & 5 deletions git-merge-one-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ case "${1:-.}${2:-.}${3:-.}" in
;;
esac

# We reset the index to the first branch, making
# git-diff-file useful
git-update-index --add --cacheinfo "$6" "$2" "$4"
git-checkout-index -u -f -- "$4" &&
merge "$4" "$orig" "$src2"
merge "$4" "$orig" "$src2"
ret=$?
rm -f -- "$orig" "$src2"

Expand Down
2 changes: 0 additions & 2 deletions git-merge-recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ def processEntry(entry, branch1Name, branch2Name):
if cacheOnly:
updateFile(False, sha, mode, path)
else:
updateFileExt(aSha, aMode, path,
updateCache=True, updateWd=False)
updateFileExt(sha, mode, path, updateCache=False, updateWd=True)
else:
die("ERROR: Fatal merge failure, shouldn't happen.")
Expand Down
Loading

0 comments on commit 5401f30

Please sign in to comment.