summaryrefslogtreecommitdiff
path: root/builtin/ls-files.c
diff options
context:
space:
mode:
authorZheNing Hu <adlternative@gmail.com>2021-01-23 10:20:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-23 19:48:11 (GMT)
commitf1c462ea4119f58a230abd62096a174483930a18 (patch)
tree74af5f75e258ed99d8015c27eda4889d15d128ed /builtin/ls-files.c
parent66e871b6647ffea61a77a0f82c7ef3415f1ee79c (diff)
downloadgit-f1c462ea4119f58a230abd62096a174483930a18.zip
git-f1c462ea4119f58a230abd62096a174483930a18.tar.gz
git-f1c462ea4119f58a230abd62096a174483930a18.tar.bz2
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>
Diffstat (limited to 'builtin/ls-files.c')
-rw-r--r--builtin/ls-files.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae89..ce6f6ad 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -335,7 +335,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
- int err;
+ int stat_err;
construct_fullname(&fullname, repo, ce);
@@ -346,10 +346,13 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
continue;
if (ce_skip_worktree(ce))
continue;
- err = lstat(fullname.buf, &st);
- if (show_deleted && err)
+ stat_err = lstat(fullname.buf, &st);
+ if (stat_err && (errno != ENOENT && errno != ENOTDIR))
+ error_errno("cannot lstat '%s'", fullname.buf);
+ if (stat_err && show_deleted)
show_ce(repo, dir, ce, fullname.buf, tag_removed);
- if (show_modified && ie_modified(repo->index, ce, &st, 0))
+ if (show_modified &&
+ (stat_err || ie_modified(repo->index, ce, &st, 0)))
show_ce(repo, dir, ce, fullname.buf, tag_modified);
}
}