Merge branch 'jc/maint-1.6.0-diff-borrow-carefully' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2009 06:23:17 +0000 (23:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2009 06:23:17 +0000 (23:23 -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 37f99209a0580a1ac304d0c1a8a55c12da64c9f2..4f980aded6aa0f61b0a6354b0157b8711a2c4627 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1759,7 +1759,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
@@ -1799,6 +1800,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 f8c99f1a985ba14a4361e9d1e75486d6806c8f77..0720001281db6aeb5a3b6bb46cd6914ad7d78d33 100755 (executable)
@@ -152,4 +152,12 @@ test_expect_success 'external diff with autocrlf = true' '
        test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
 '
 
+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