ls_files.c: consolidate two for loops into one

This will make it easier to show only one entry per filename in the
next step.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
[jc: corrected the log message]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
ZheNing Hu 2021-01-23 10:20:09 +00:00 коммит произвёл Junio C Hamano
Родитель f1c462ea41
Коммит ed644d1666
1 изменённых файлов: 27 добавлений и 36 удалений

Просмотреть файл

@ -312,49 +312,40 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (show_killed) if (show_killed)
show_killed_files(repo->index, dir); show_killed_files(repo->index, dir);
} }
if (show_cached || show_stage) {
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
construct_fullname(&fullname, repo, ce); if (!(show_cached || show_stage || show_deleted || show_modified))
return;
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int stat_err;
if ((dir->flags & DIR_SHOW_IGNORED) && construct_fullname(&fullname, repo, ce);
!ce_excluded(dir, repo->index, fullname.buf, ce))
continue; if ((dir->flags & DIR_SHOW_IGNORED) &&
if (show_unmerged && !ce_stage(ce)) !ce_excluded(dir, repo->index, fullname.buf, ce))
continue; continue;
if (ce->ce_flags & CE_UPDATE) if (ce->ce_flags & CE_UPDATE)
continue; continue;
if ((show_cached || show_stage) &&
(!show_unmerged || ce_stage(ce)))
show_ce(repo, dir, ce, fullname.buf, show_ce(repo, dir, ce, fullname.buf,
ce_stage(ce) ? tag_unmerged : ce_stage(ce) ? tag_unmerged :
(ce_skip_worktree(ce) ? tag_skip_worktree : (ce_skip_worktree(ce) ? tag_skip_worktree :
tag_cached)); tag_cached));
}
}
if (show_deleted || show_modified) {
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int stat_err;
construct_fullname(&fullname, repo, ce); if (!(show_deleted || show_modified))
continue;
if ((dir->flags & DIR_SHOW_IGNORED) && if (ce_skip_worktree(ce))
!ce_excluded(dir, repo->index, fullname.buf, ce)) continue;
continue; stat_err = lstat(fullname.buf, &st);
if (ce->ce_flags & CE_UPDATE) if (stat_err && (errno != ENOENT && errno != ENOTDIR))
continue; error_errno("cannot lstat '%s'", fullname.buf);
if (ce_skip_worktree(ce)) if (stat_err && show_deleted)
continue; show_ce(repo, dir, ce, fullname.buf, tag_removed);
stat_err = lstat(fullname.buf, &st); if (show_modified &&
if (stat_err && (errno != ENOENT && errno != ENOTDIR)) (stat_err || ie_modified(repo->index, ce, &st, 0)))
error_errno("cannot lstat '%s'", fullname.buf); show_ce(repo, dir, ce, fullname.buf, tag_modified);
if (stat_err && show_deleted)
show_ce(repo, dir, ce, fullname.buf, tag_removed);
if (show_modified &&
(stat_err || ie_modified(repo->index, ce, &st, 0)))
show_ce(repo, dir, ce, fullname.buf, tag_modified);
}
} }
strbuf_release(&fullname); strbuf_release(&fullname);