diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2015-02-08 16:01:34 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-02-09 14:27:29 -0800 |
commit | be258d5d84244c824f5ae7d67640dd97d7500bcf (patch) | |
tree | c94859db97c31bfd9e89f87e1822b8eaaae978f9 | |
parent | 310203b83ca39322e72270574d271d271db12156 (diff) | |
download | git-be258d5d84244c824f5ae7d67640dd97d7500bcf.tar.gz |
list-files: do not show duplicate cached entries
With the current show_files() "list-files -tcm" will show
foo.c
M foo.c
The first item is redundant. If "foo.c" is modified, we know it's in
the cache. Introduce show_files_compact to do that because ls-files is
plumbing and scripts may already depend on current display behavior.
Another difference in show_files_compact() is it does not show
skip-worktree (aka outside sparse checkout) entries anymore, which
makes sense in porcelain context.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/ls-files.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 8f10ab9e2a..457d067ddd 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -333,6 +333,53 @@ static void show_files(struct dir_struct *dir) } } +static void show_files_compact(struct dir_struct *dir) +{ + int i; + + /* For cached/deleted files we don't need to even do the readdir */ + if (show_others || show_killed) { + if (!show_others) + dir->flags |= DIR_COLLECT_KILLED_ONLY; + fill_directory(dir, &pathspec); + if (show_others) + show_other_files(dir); + if (show_killed) + show_killed_files(dir); + } + if (!(show_cached || show_unmerged || show_deleted || show_modified)) + return; + for (i = 0; i < active_nr; i++) { + const struct cache_entry *ce = active_cache[i]; + struct stat st; + int err, shown = 0; + if ((dir->flags & DIR_SHOW_IGNORED) && + !ce_excluded(dir, ce)) + continue; + if (show_unmerged && !ce_stage(ce)) + continue; + if (ce->ce_flags & CE_UPDATE) + continue; + if (ce_skip_worktree(ce)) + continue; + err = lstat(ce->name, &st); + if (show_deleted && err) { + show_ce_entry(tag_removed, ce); + shown = 1; + } + if (show_modified && (err || ce_modified(ce, &st, 0))) { + show_ce_entry(tag_modified, ce); + shown = 1; + } + if (ce_stage(ce)) { + show_ce_entry(tag_unmerged, ce); + shown = 1; + } + if (!shown && show_cached) + show_ce_entry(tag_cached, ce); + } +} + /* * Prune the index to only contain stuff starting with "prefix" */ @@ -743,7 +790,10 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) refresh_index(&the_index, REFRESH_QUIET | REFRESH_UNMERGED, &pathspec, NULL, NULL); setup_pager(); } - show_files(&dir); + if (porcelain) + show_files_compact(&dir); + else + show_files(&dir); if (show_resolve_undo) show_ru_info(); |