diff-files: careful when inspecting work tree items

This fixes the same breakage in diff-files.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2008-03-30 17:30:08 -07:00
parent 948dd346fd
commit f58dbf23c3
2 changed files with 14 additions and 9 deletions

View File

@ -362,10 +362,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
int silent_on_removed = option & DIFF_SILENT_ON_REMOVED; int silent_on_removed = option & DIFF_SILENT_ON_REMOVED;
unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED) unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
? CE_MATCH_RACY_IS_DIRTY : 0); ? CE_MATCH_RACY_IS_DIRTY : 0);
char symcache[PATH_MAX];
if (diff_unmerged_stage < 0) if (diff_unmerged_stage < 0)
diff_unmerged_stage = 2; diff_unmerged_stage = 2;
entries = active_nr; entries = active_nr;
symcache[0] = '\0';
for (i = 0; i < entries; i++) { for (i = 0; i < entries; i++) {
struct stat st; struct stat st;
unsigned int oldmode, newmode; unsigned int oldmode, newmode;
@ -397,16 +399,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
memset(&(dpath->parent[0]), 0, memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5); sizeof(struct combine_diff_parent)*5);
if (lstat(ce->name, &st) < 0) { changed = check_work_tree_entity(ce, &st, symcache);
if (errno != ENOENT && errno != ENOTDIR) { if (!changed)
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
else {
if (changed < 0) {
perror(ce->name); perror(ce->name);
continue; continue;
} }
if (silent_on_removed) if (silent_on_removed)
continue; continue;
} }
else
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
while (i < entries) { while (i < entries) {
struct cache_entry *nce = active_cache[i]; struct cache_entry *nce = active_cache[i];
@ -459,8 +462,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
if (ce_uptodate(ce)) if (ce_uptodate(ce))
continue; continue;
if (lstat(ce->name, &st) < 0) {
if (errno != ENOENT && errno != ENOTDIR) { changed = check_work_tree_entity(ce, &st, symcache);
if (changed) {
if (changed < 0) {
perror(ce->name); perror(ce->name);
continue; continue;
} }

View File

@ -104,7 +104,7 @@ test_expect_success modify '
} >expect-final } >expect-final
' '
test_expect_failure diff-files ' test_expect_success diff-files '
git diff-files --raw >actual && git diff-files --raw >actual &&
diff -u expect-files actual diff -u expect-files actual
' '
@ -114,7 +114,7 @@ test_expect_success diff-index '
diff -u expect-index actual diff -u expect-index actual
' '
test_expect_failure 'add -u' ' test_expect_success 'add -u' '
rm -f ".git/saved-index" && rm -f ".git/saved-index" &&
cp -p ".git/index" ".git/saved-index" && cp -p ".git/index" ".git/saved-index" &&
git add -u && git add -u &&
@ -122,7 +122,7 @@ test_expect_failure 'add -u' '
diff -u expect-final actual diff -u expect-final actual
' '
test_expect_failure 'commit -a' ' test_expect_success 'commit -a' '
if test -f ".git/saved-index" if test -f ".git/saved-index"
then then
rm -f ".git/index" && rm -f ".git/index" &&