[prev in list] [next in list] [prev in thread] [next in thread]
List: git
Subject: [PATCH 15/19] list-files: do not show duplicate cached entries
From: Nguyễn Thái Ngọc Duy <pclouds () gmail ! com>
Date: 2014-11-30 8:56:03
Message-ID: 1417337767-4505-16-git-send-email-pclouds () gmail ! com
[Download RAW message or body]
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>
---
builtin/ls-files.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 42c530d..fc70265 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_stage || 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, &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();
--
2.2.0.60.gb7b3c64
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic