Skip to content

Commit f58dbf2

Browse files
committed
diff-files: careful when inspecting work tree items
This fixes the same breakage in diff-files. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 948dd34 commit f58dbf2

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

diff-lib.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
362362
int silent_on_removed = option & DIFF_SILENT_ON_REMOVED;
363363
unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
364364
? CE_MATCH_RACY_IS_DIRTY : 0);
365+
char symcache[PATH_MAX];
365366

366367
if (diff_unmerged_stage < 0)
367368
diff_unmerged_stage = 2;
368369
entries = active_nr;
370+
symcache[0] = '\0';
369371
for (i = 0; i < entries; i++) {
370372
struct stat st;
371373
unsigned int oldmode, newmode;
@@ -397,16 +399,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
397399
memset(&(dpath->parent[0]), 0,
398400
sizeof(struct combine_diff_parent)*5);
399401

400-
if (lstat(ce->name, &st) < 0) {
401-
if (errno != ENOENT && errno != ENOTDIR) {
402+
changed = check_work_tree_entity(ce, &st, symcache);
403+
if (!changed)
404+
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
405+
else {
406+
if (changed < 0) {
402407
perror(ce->name);
403408
continue;
404409
}
405410
if (silent_on_removed)
406411
continue;
407412
}
408-
else
409-
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
410413

411414
while (i < entries) {
412415
struct cache_entry *nce = active_cache[i];
@@ -459,8 +462,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
459462

460463
if (ce_uptodate(ce))
461464
continue;
462-
if (lstat(ce->name, &st) < 0) {
463-
if (errno != ENOENT && errno != ENOTDIR) {
465+
466+
changed = check_work_tree_entity(ce, &st, symcache);
467+
if (changed) {
468+
if (changed < 0) {
464469
perror(ce->name);
465470
continue;
466471
}

t/t2201-add-update-typechange.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test_expect_success modify '
104104
} >expect-final
105105
'
106106

107-
test_expect_failure diff-files '
107+
test_expect_success diff-files '
108108
git diff-files --raw >actual &&
109109
diff -u expect-files actual
110110
'
@@ -114,15 +114,15 @@ test_expect_success diff-index '
114114
diff -u expect-index actual
115115
'
116116

117-
test_expect_failure 'add -u' '
117+
test_expect_success 'add -u' '
118118
rm -f ".git/saved-index" &&
119119
cp -p ".git/index" ".git/saved-index" &&
120120
git add -u &&
121121
git ls-files -s >actual &&
122122
diff -u expect-final actual
123123
'
124124

125-
test_expect_failure 'commit -a' '
125+
test_expect_success 'commit -a' '
126126
if test -f ".git/saved-index"
127127
then
128128
rm -f ".git/index" &&

0 commit comments

Comments
 (0)