]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/maint-1.6.0-diff-borrow-carefully' into maint-1.6.1
authorJunio C Hamano <gitster@pobox.com>
Sun, 3 May 2009 22:01:26 +0000 (15:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 May 2009 22:01:26 +0000 (15:01 -0700)
* jc/maint-1.6.0-diff-borrow-carefully:
  diff --cached: do not borrow from a work tree when a path is marked as assume-unchanged

diff.c
t/t4020-diff-external.sh

diff --git a/diff.c b/diff.c
index 416c5aa722afc8d10e4bc910e7b297b3eb0a2760..635fbc9d98995359b045de8a7a8594af2fe0e335 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1649,7 +1649,8 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
        struct stat st;
        int pos, len;
 
-       /* We do not read the cache ourselves here, because the
+       /*
+        * We do not read the cache ourselves here, because the
         * benchmark with my previous version that always reads cache
         * shows that it makes things worse for diff-tree comparing
         * two linux-2.6 kernel trees in an already checked out work
@@ -1689,6 +1690,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
        if (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode))
                return 0;
 
+       /*
+        * If ce is marked as "assume unchanged", there is no
+        * guarantee that work tree matches what we are looking for.
+        */
+       if (ce->ce_flags & CE_VALID)
+               return 0;
+
        /*
         * If ce matches the file in the work tree, we can reuse it.
         */
index caea292f15437f50fd324496ff511971cc9d1d0c..2a72e751e290ad59d5277695a1128aebb678c2a1 100755 (executable)
@@ -128,4 +128,12 @@ test_expect_success 'force diff with "diff"' '
        test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 '
 
+test_expect_success 'diff --cached' '
+       git add file &&
+       git update-index --assume-unchanged file &&
+       echo second >file &&
+       git diff --cached >actual &&
+       test_cmp ../t4020/diff.NUL actual
+'
+
 test_done