@matheusbsbs / matheus-bagliano / commits / 06aff47b22
Fork 0

Use diff* with --exit-code in git-am, git-rebase and git-merge-ours

This simplifies the shell code, reduces its memory footprint, and speeds things up. The performance improvements should be noticable when git-rebase works on big commits. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Alex Riesen committed Mar 25, 2007 at 01:56 UTC 06aff47b225506c4603a6f5ec5b4b16aa6a9d7ba
3 files changed +12 -18
git-am.sh
+7 -11
@@ -408,12 +408,10 @@ do
408 # trust what the user has in the index file and the
409 # working tree.
410 resolved=
411 - changed="$(git-diff-index --cached --name-only HEAD)"
412 - if test '' = "$changed"
413 - then
411 + git-diff-index --quiet --cached HEAD && {
412 echo "No changes - did you forget to use 'git add'?"
413 stop_here_user_resolve $this
416 - fi
414 + }
415 unmerged=$(git-ls-files -u)
416 if test -n "$unmerged"
417 then
@@ -435,13 +433,11 @@ do
433 then
434 # Applying the patch to an earlier tree and merging the
435 # result may have produced the same tree as ours.
438 - changed="$(git-diff-index --cached --name-only HEAD)"
439 - if test '' = "$changed"
440 - then
441 - echo No changes -- Patch already applied.
442 - go_next
443 - continue
444 - fi
436 + git-diff-index --quiet --cached HEAD && {
437 + echo No changes -- Patch already applied.
438 + go_next
439 + continue
440 + }
441 # clear apply_status -- we have successfully merged.
442 apply_status=0
443 fi
git-merge-ours.sh
+1 -1
@@ -9,6 +9,6 @@
9 # because the current index is what we will be committing as the
10 # merge result.
11
12 -test "$(git-diff-index --cached --name-status HEAD)" = "" || exit 2
12 +git-diff-index --quiet --cached HEAD || exit 2
13
14 exit 0
git-rebase.sh
+4 -6
@@ -59,7 +59,7 @@ continue_merge () {
59 die "$RESOLVEMSG"
60 fi
61
62 - if test -n "`git-diff-index HEAD`"
62 + if ! git-diff-index --quiet HEAD
63 then
64 if ! git-commit -C "`cat $dotest/current`"
65 then
@@ -124,13 +124,11 @@ while case "$#" in 0) break ;; esac
124 do
125 case "$1" in
126 --continue)
127 - diff=$(git-diff-files)
128 - case "$diff" in
129 - ?*) echo "You must edit all merge conflicts and then"
127 + git-diff-files --quiet || {
128 + echo "You must edit all merge conflicts and then"
129 echo "mark them as resolved using git update-index"
130 exit 1
132 - ;;
133 - esac
131 + }
132 if test -d "$dotest"
133 then
134 prev_head="`cat $dotest/prev_head`"