Merge branch 'jk/diff-do-not-reuse-wtf-needs-cleaning' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:28 +0000 (11:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2016 18:55:28 +0000 (11:55 -0700)
There is an optimization used in "git diff $treeA $treeB" to borrow
an already checked-out copy in the working tree when it is known to
be the same as the blob being compared, expecting that open/mmap of
such a file is faster than reading it from the object store, which
involves inflating and applying delta. This however kicked in even
when the checked-out copy needs to go through the convert-to-git
conversion (including the clean filter), which defeats the whole
point of the optimization. The optimization has been disabled when
the conversion is necessary.

* jk/diff-do-not-reuse-wtf-needs-cleaning:
diff: do not reuse worktree files that need "clean" conversion

diff.c
t/t0021-conversion.sh
diff --git a/diff.c b/diff.c
index fa78fc189cd7225767817a2d24ef6c3b19bef9d8..abff2eec2b0604786b09ff0ac7fae24e1df6677f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -2682,6 +2682,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
        if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1))
                return 0;
 
+       /*
+        * Similarly, if we'd have to convert the file contents anyway, that
+        * makes the optimization not worthwhile.
+        */
+       if (!want_file && would_convert_to_git(name))
+               return 0;
+
        len = strlen(name);
        pos = cache_name_pos(name, len);
        if (pos < 0)
index 7bac2bcf260794bbfeb795b210ed0c9eceb45937..e799e5954437e08df4a013f9796c5ec5a9bb077d 100755 (executable)
@@ -268,4 +268,15 @@ test_expect_success 'disable filter with empty override' '
        test_must_be_empty err
 '
 
+test_expect_success 'diff does not reuse worktree files that need cleaning' '
+       test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
+       echo "file filter=counter" >.gitattributes &&
+       test_commit one file &&
+       test_commit two file &&
+
+       >count &&
+       git diff-tree -p HEAD &&
+       test_line_count = 0 count
+'
+
 test_done