Skip to content

Commit f1c462e

Browse files
adlternativegitster
authored andcommitted
ls_files.c: bugfix for --deleted and --modified
This situation may occur in the original code: lstat() failed but we use `&st` to feed ie_modified() later. Therefore, we can directly execute show_ce without the judgment of ie_modified() when lstat() has failed. Signed-off-by: ZheNing Hu <[email protected]> [jc: fixed misindented code] Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66e871b commit f1c462e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

builtin/ls-files.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
335335
for (i = 0; i < repo->index->cache_nr; i++) {
336336
const struct cache_entry *ce = repo->index->cache[i];
337337
struct stat st;
338-
int err;
338+
int stat_err;
339339

340340
construct_fullname(&fullname, repo, ce);
341341

@@ -346,10 +346,13 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
346346
continue;
347347
if (ce_skip_worktree(ce))
348348
continue;
349-
err = lstat(fullname.buf, &st);
350-
if (show_deleted && err)
349+
stat_err = lstat(fullname.buf, &st);
350+
if (stat_err && (errno != ENOENT && errno != ENOTDIR))
351+
error_errno("cannot lstat '%s'", fullname.buf);
352+
if (stat_err && show_deleted)
351353
show_ce(repo, dir, ce, fullname.buf, tag_removed);
352-
if (show_modified && ie_modified(repo->index, ce, &st, 0))
354+
if (show_modified &&
355+
(stat_err || ie_modified(repo->index, ce, &st, 0)))
353356
show_ce(repo, dir, ce, fullname.buf, tag_modified);
354357
}
355358
}

0 commit comments

Comments
 (0)