]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls_files.c: bugfix for --deleted and --modified
authorZheNing Hu <adlternative@gmail.com>
Sat, 23 Jan 2021 10:20:08 +0000 (10:20 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Jan 2021 19:48:11 +0000 (11:48 -0800)
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>
builtin/ls-files.c

index c8eae899b82a83ebc3487ffa99ba2bcf73d3369f..ce6f6ad00ed9ae1b8b695a0dd1b340ecb5ae1459 100644 (file)
@@ -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);
                }
        }