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 <adlternative@gmail.com> [jc: fixed misindented code] Signed-off-by: Junio C Hamano <gitster@pobox.com>

ZheNing Hu committed Jan 23, 2021 at 10:20 UTC f1c462ea4119f58a230abd62096a174483930a18
1 file changed +7 -4
builtin/ls-files.c
+7 -4
@@ -335,7 +335,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
335 for (i = 0; i < repo->index->cache_nr; i++) {
336 const struct cache_entry *ce = repo->index->cache[i];
337 struct stat st;
338 - int err;
338 + int stat_err;
339
340 construct_fullname(&fullname, repo, ce);
341
@@ -346,10 +346,13 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
346 continue;
347 if (ce_skip_worktree(ce))
348 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)
353 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)))
356 show_ce(repo, dir, ce, fullname.buf, tag_modified);
357 }
358 }