]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/fix-diff-files-unmerged'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2011 17:52:58 +0000 (10:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2011 17:52:58 +0000 (10:52 -0700)
* jc/fix-diff-files-unmerged:
  diff-files: show unmerged entries correctly
  diff: remove often unused parameters from diff_unmerge()
  diff.c: return filepair from diff_unmerge()
  test: use $_z40 from test-lib

16 files changed:
diff-lib.c
diff.c
diff.h
t/t1400-update-ref.sh
t/t1501-worktree.sh
t/t2011-checkout-invalid-head.sh
t/t2201-add-update-typechange.sh
t/t3200-branch.sh
t/t3600-rm.sh
t/t4002-diff-basic.sh
t/t4020-diff-external.sh
t/t4027-diff-submodule.sh
t/t4046-diff-unmerged.sh [new file with mode: 0755]
t/t7011-skip-worktree-reading.sh
t/t7012-skip-worktree-writing.sh
t/test-lib.sh

index 2870de400ed533d83c77269ee1654af212c6510c..3b5f2242a597ff1b44a3af6be72cb14e6e0d5455 100644 (file)
@@ -112,6 +112,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
                if (ce_stage(ce)) {
                        struct combine_diff_path *dpath;
+                       struct diff_filepair *pair;
+                       unsigned int wt_mode = 0;
                        int num_compare_stages = 0;
                        size_t path_len;
 
@@ -130,7 +132,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
                        changed = check_removed(ce, &st);
                        if (!changed)
-                               dpath->mode = ce_mode_from_stat(ce, st.st_mode);
+                               wt_mode = ce_mode_from_stat(ce, st.st_mode);
                        else {
                                if (changed < 0) {
                                        perror(ce->name);
@@ -138,7 +140,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                }
                                if (silent_on_removed)
                                        continue;
+                               wt_mode = 0;
                        }
+                       dpath->mode = wt_mode;
 
                        while (i < entries) {
                                struct cache_entry *nce = active_cache[i];
@@ -184,7 +188,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                         * Show the diff for the 'ce' if we found the one
                         * from the desired stage.
                         */
-                       diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
+                       pair = diff_unmerge(&revs->diffopt, ce->name);
+                       if (wt_mode)
+                               pair->two->mode = wt_mode;
                        if (ce_stage(ce) != diff_unmerged_stage)
                                continue;
                }
@@ -373,8 +379,9 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        match_missing = !revs->ignore_merges;
 
        if (cached && idx && ce_stage(idx)) {
-               diff_unmerge(&revs->diffopt, idx->name, idx->ce_mode,
-                            idx->sha1);
+               struct diff_filepair *pair;
+               pair = diff_unmerge(&revs->diffopt, idx->name);
+               fill_filespec(pair->one, idx->sha1, idx->ce_mode);
                return;
        }
 
diff --git a/diff.c b/diff.c
index 3b40e597d5793d13944f9604e5197ac216eb3a3e..feced343433f41c2138f09e10e256b2020c89137 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4416,20 +4416,20 @@ void diff_change(struct diff_options *options,
                DIFF_OPT_SET(options, HAS_CHANGES);
 }
 
-void diff_unmerge(struct diff_options *options,
-                 const char *path,
-                 unsigned mode, const unsigned char *sha1)
+struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)
 {
+       struct diff_filepair *pair;
        struct diff_filespec *one, *two;
 
        if (options->prefix &&
            strncmp(path, options->prefix, options->prefix_length))
-               return;
+               return NULL;
 
        one = alloc_filespec(path);
        two = alloc_filespec(path);
-       fill_filespec(one, sha1, mode);
-       diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
+       pair = diff_queue(&diff_queued_diff, one, two);
+       pair->is_unmerged = 1;
+       return pair;
 }
 
 static char *run_textconv(const char *pgm, struct diff_filespec *spec,
diff --git a/diff.h b/diff.h
index 6fe1597785761b0e6961910214a129a2dde5197f..d83e53e9d465ba73808ff5071b17b7f13ad27b09 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -210,10 +210,7 @@ extern void diff_change(struct diff_options *,
                        const char *fullpath,
                        unsigned dirty_submodule1, unsigned dirty_submodule2);
 
-extern void diff_unmerge(struct diff_options *,
-                        const char *path,
-                        unsigned mode,
-                        const unsigned char *sha1);
+extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
 
 #define DIFF_SETUP_REVERSE             1
 #define DIFF_SETUP_USE_CACHE           2
index ff747f8229bb46df070ea9aad2702f4d1c703420..4fd83a667ac8b08bef090d303bc4434969874780 100755 (executable)
@@ -6,7 +6,7 @@
 test_description='Test git update-ref and basic ref logging'
 . ./test-lib.sh
 
-Z=0000000000000000000000000000000000000000
+Z=$_z40
 
 test_expect_success setup '
 
index da6252b1179c47d39393c983d88c75d84a507cb7..63849836c8b088eb495dc565ff909c367c868301 100755 (executable)
@@ -7,7 +7,6 @@ test_expect_success 'setup' '
        EMPTY_TREE=$(git write-tree) &&
        EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
        CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
-       ZEROES=0000000000000000000000000000000000000000 &&
        EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
        CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
 
@@ -239,10 +238,10 @@ test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
 
 test_expect_success 'diff-index respects work tree under .git dir' '
        cat >diff-index-cached.expected <<-EOF &&
-       :000000 100644 $ZEROES $EMPTY_BLOB A    sub/dir/tracked
+       :000000 100644 $_z40 $EMPTY_BLOB A      sub/dir/tracked
        EOF
        cat >diff-index.expected <<-EOF &&
-       :000000 100644 $ZEROES $ZEROES A        sub/dir/tracked
+       :000000 100644 $_z40 $_z40 A    sub/dir/tracked
        EOF
 
        (
@@ -258,7 +257,7 @@ test_expect_success 'diff-index respects work tree under .git dir' '
 
 test_expect_success 'diff-files respects work tree under .git dir' '
        cat >diff-files.expected <<-EOF &&
-       :100644 100644 $EMPTY_BLOB $ZEROES M    sub/dir/tracked
+       :100644 100644 $EMPTY_BLOB $_z40 M      sub/dir/tracked
        EOF
 
        (
index 15ebdc26ebaaf7881b1f51eb788c2eb2922b6d4f..300f8bf25c34cf4ea4e011d1daa525285ca94c5a 100755 (executable)
@@ -15,7 +15,7 @@ test_expect_success 'checkout should not start branch from a tree' '
 '
 
 test_expect_success 'checkout master from invalid HEAD' '
-       echo 0000000000000000000000000000000000000000 >.git/HEAD &&
+       echo $_z40 >.git/HEAD &&
        git checkout master --
 '
 
index 2e8f70245204bd4dc78e67f227e86838e1cdad5b..954fc51e5b560af918661a0ee051521a43f4efba 100755 (executable)
@@ -4,8 +4,6 @@ test_description='more git add -u'
 
 . ./test-lib.sh
 
-_z40=0000000000000000000000000000000000000000
-
 test_expect_success setup '
        >xyzzy &&
        _empty=$(git hash-object --stdin <xyzzy) &&
index 0ce95c04e50f4662f87600bd3af48da0492a72a2..9e69c8c926620f06343e64e7b3aa3e4ada5a6b69 100755 (executable)
@@ -46,7 +46,7 @@ test_expect_success \
     'git branch a/b/c && test -f .git/refs/heads/a/b/c'
 
 cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
 test_expect_success \
     'git branch -l d/e/f should create a branch and a log' \
@@ -232,7 +232,7 @@ test_expect_success \
 
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
 test_expect_success \
     'git checkout -b g/h/i -l should create a branch and a log' \
index cd093bd34730a3dba6eec7719d3b0170e517fb5e..9fd28bcf3435f831fa24285dd703c82b8396d635 100755 (executable)
@@ -240,11 +240,10 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
        git reset -q --hard &&
-       H=0000000000000000000000000000000000000000 &&
        i=0 &&
        while test $i -lt 12000
        do
-           echo "100644 $H 0   some-file-$i"
+           echo "100644 $_z40 0        some-file-$i"
            i=$(( $i + 1 ))
        done | git update-index --index-info &&
        git rm -n "some-file-*" | :;
index 9fb8ca06a84b3f3e60f466cc33bc2de786a9fc90..a5e8b830834f4b5feb531f8f4f4d08462325b1de 100755 (executable)
@@ -126,15 +126,12 @@ cat >.test-recursive-AB <<\EOF
 :100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d M     Z/NM
 EOF
 
-x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-x40="$x40$x40$x40$x40$x40$x40$x40$x40"
-z40='0000000000000000000000000000000000000000'
 cmp_diff_files_output () {
     # diff-files never reports additions.  Also it does not fill in the
     # object ID for the changed files because it wants you to look at the
     # filesystem.
     sed <"$2" >.test-tmp \
-       -e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\)    /'$z40'\1       /' &&
+       -e '/^:000000 /d;s/'$_x40'\( [MCRNDU][0-9]*\)   /'$_z40'\1      /' &&
     test_cmp "$1" .test-tmp
 }
 
index a7602cf923d95a51643753ce44fa65cf406aba9c..083f62d1d6bb6bfd908b0a03db1a47f80071ef91 100755 (executable)
@@ -4,8 +4,6 @@ test_description='external diff interface test'
 
 . ./test-lib.sh
 
-_z40=0000000000000000000000000000000000000000
-
 test_expect_success setup '
 
        test_tick &&
index 241a74d2a20276d711944d3e203083b515486e77..518bf9524e0b55181f3c440d202b69c12a0b314f 100755 (executable)
@@ -5,7 +5,6 @@ test_description='difference in submodules'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/diff-lib.sh
 
-_z40=0000000000000000000000000000000000000000
 test_expect_success setup '
        test_tick &&
        test_create_repo sub &&
diff --git a/t/t4046-diff-unmerged.sh b/t/t4046-diff-unmerged.sh
new file mode 100755 (executable)
index 0000000..25d50a6
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+test_description='diff with unmerged index entries'
+. ./test-lib.sh
+
+test_expect_success setup '
+       for i in 0 1 2 3
+       do
+               blob=$(echo $i | git hash-object --stdin) &&
+               eval "blob$i=$blob" &&
+               eval "m$i=\"100644 \$blob$i $i\"" || break
+       done &&
+       paths= &&
+       for b in o x
+       do
+               for o in o x
+               do
+                       for t in o x
+                       do
+                               path="$b$o$t" &&
+                               case "$path" in ooo) continue ;; esac
+                               paths="$paths$path " &&
+                               p="     $path" &&
+                               case "$b" in x) echo "$m1$p" ;; esac &&
+                               case "$o" in x) echo "$m2$p" ;; esac &&
+                               case "$t" in x) echo "$m3$p" ;; esac ||
+                               break
+                       done || break
+               done || break
+       done >ls-files-s.expect &&
+       git update-index --index-info <ls-files-s.expect &&
+       git ls-files -s >ls-files-s.actual &&
+       test_cmp ls-files-s.expect ls-files-s.actual
+'
+
+test_expect_success 'diff-files -0' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path"
+       done >diff-files-0.expect &&
+       git diff-files -0 >diff-files-0.actual &&
+       test_cmp diff-files-0.expect diff-files-0.actual
+'
+
+test_expect_success 'diff-files -1' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               x??) echo ":100644 100644 $blob1 $_z40 M        $path"
+               esac
+       done >diff-files-1.expect &&
+       git diff-files -1 >diff-files-1.actual &&
+       test_cmp diff-files-1.expect diff-files-1.actual
+'
+
+test_expect_success 'diff-files -2' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               ?x?) echo ":100644 100644 $blob2 $_z40 M        $path"
+               esac
+       done >diff-files-2.expect &&
+       git diff-files -2 >diff-files-2.actual &&
+       test_cmp diff-files-2.expect diff-files-2.actual &&
+       git diff-files >diff-files-default-2.actual &&
+       test_cmp diff-files-2.expect diff-files-default-2.actual
+'
+
+test_expect_success 'diff-files -3' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               ??x) echo ":100644 100644 $blob3 $_z40 M        $path"
+               esac
+       done >diff-files-3.expect &&
+       git diff-files -3 >diff-files-3.actual &&
+       test_cmp diff-files-3.expect diff-files-3.actual
+'
+
+test_done
index bb4066f76762520b98caeba1cddaf442d80a4bf2..8f3b54d826f5a9c8e7b08df7f6a58398b5a62480 100755 (executable)
@@ -24,7 +24,7 @@ H sub/2
 EOF
 
 NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
-ZERO_SHA0=0000000000000000000000000000000000000000
+
 setup_absent() {
        test -f 1 && rm 1
        git update-index --remove 1 &&
@@ -120,7 +120,7 @@ test_expect_success 'grep with skip-worktree file' '
        test "$(git grep --no-ext-grep test)" = "1:test"
 '
 
-echo ":000000 100644 $ZERO_SHA0 $NULL_SHA1 A   1" > expected
+echo ":000000 100644 $_z40 $NULL_SHA1 A        1" > expected
 test_expect_success 'diff-index does not examine skip-worktree absent entries' '
        setup_absent &&
        git diff-index HEAD -- 1 > result &&
index cffb2696d4b1a1ca7bdc962590dc7cedde1e5e2a..9ceaa4049f960f20ca37d58e58e9e6c4e9ff4398 100755 (executable)
@@ -54,7 +54,7 @@ test_expect_success 'read-tree removes worktree, dirty case' '
 '
 
 NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
-ZERO_SHA0=0000000000000000000000000000000000000000
+
 setup_absent() {
        test -f 1 && rm 1
        git update-index --remove 1 &&
index c5b18e282a7ef4246fb7d725cf94bfc5e7e72dc3..b2ce2bc4b22f43c0b324ab3f596a7f865fa58cc1 100644 (file)
@@ -89,6 +89,9 @@ esac
 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
 
+# Zero SHA-1
+_z40=0000000000000000000000000000000000000000
+
 # Each test should start with something like this, after copyright notices:
 #
 # test_description='Description of this test...