Prevent diff machinery from examining assume-unchanged entries on worktree
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Aug 11, 2009 at 22:43 UTC
540e694b139dd034b21de087001ac9b6d7606c94
2 files changed
+35
-2
diff-lib.c
+4
-2
@@ -162,7 +162,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
162
if (ce_uptodate(ce))
163
continue;
164
165
- changed = check_removed(ce, &st);
165
+ /* If CE_VALID is set, don't look at workdir for file removal */
166
+ changed = (ce->ce_flags & CE_VALID) ? 0 : check_removed(ce, &st);
167
if (changed) {
168
if (changed < 0) {
169
perror(ce->name);
@@ -337,6 +338,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
338
struct rev_info *revs = o->unpack_data;
339
int match_missing, cached;
340
341
+ /* if the entry is not checked out, don't examine work tree */
342
+ cached = o->index_only || (idx && (idx->ce_flags & CE_VALID));
343
/*
344
* Backward compatibility wart - "diff-index -m" does
345
* not mean "do not ignore merges", but "match_missing".
@@ -344,7 +347,6 @@ static void do_oneway_diff(struct unpack_trees_options *o,
347
* But with the revision flag parsing, that's found in
348
* "!revs->ignore_merges".
349
*/
347
- cached = o->index_only;
350
match_missing = !revs->ignore_merges;
351
352
if (cached && idx && ce_stage(idx)) {
t/t4039-diff-assume-unchanged.sh
new
+31
@@ -0,0 +1,31 @@
1
+#!/bin/sh
2
+
3
+test_description='diff with assume-unchanged entries'
4
+
5
+. ./test-lib.sh
6
+
7
+# external diff has been tested in t4020-diff-external.sh
8
+
9
+test_expect_success 'setup' '
10
+ echo zero > zero &&
11
+ git add zero &&
12
+ git commit -m zero &&
13
+ echo one > one &&
14
+ echo two > two &&
15
+ git add one two &&
16
+ git commit -m onetwo &&
17
+ git update-index --assume-unchanged one &&
18
+ echo borked >> one &&
19
+ test "$(git ls-files -v one)" = "h one"
20
+'
21
+
22
+test_expect_success 'diff-index does not examine assume-unchanged entries' '
23
+ git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171
24
+'
25
+
26
+test_expect_success 'diff-files does not examine assume-unchanged entries' '
27
+ rm one &&
28
+ test -z "$(git diff-files -- one)"
29
+'
30
+
31
+test_done