summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-09-15 17:56:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-09-17 16:38:50 (GMT)
commitae9af12287b2c37512f12c137173dde7ea5192a0 (patch)
treec4177e26c27cfd9d282ea4879adb2ced55e0af99 /read-cache.c
parent1d4361b0f344188ab5eec6dcea01f61a3a3a1670 (diff)
downloadgit-ae9af12287b2c37512f12c137173dde7ea5192a0.zip
git-ae9af12287b2c37512f12c137173dde7ea5192a0.tar.gz
git-ae9af12287b2c37512f12c137173dde7ea5192a0.tar.bz2
status: show progress bar if refreshing the index takes too long
Refreshing the index is usually very fast, but it can still take a long time sometimes. Cold cache is one. Or copying a repo to a new place (*). It's good to show something to let the user know "git status" is not hanging, it's just busy doing something. (*) In this case, all stat info in the index becomes invalid and git falls back to rehashing all file content to see if there's any difference between updating stat info in the index. This is quite expensive. Even with a repo as small as git.git, it takes 3 seconds. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 7b1354d..5969ca9 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -23,6 +23,7 @@
#include "split-index.h"
#include "utf8.h"
#include "fsmonitor.h"
+#include "progress.h"
/* Mask for the name length in ce_flags in the on-disk index */
@@ -1477,6 +1478,11 @@ int refresh_index(struct index_state *istate, unsigned int flags,
const char *added_fmt;
const char *unmerged_fmt;
uint64_t start = getnanotime();
+ struct progress *progress = NULL;
+
+ if (flags & REFRESH_PROGRESS && isatty(2))
+ progress = start_delayed_progress(_("Refresh index"),
+ istate->cache_nr);
modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
@@ -1516,6 +1522,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
new_entry = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
if (new_entry == ce)
continue;
+ if (progress)
+ display_progress(progress, i);
if (!new_entry) {
const char *fmt;
@@ -1547,6 +1555,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
replace_index_entry(istate, i, new_entry);
}
+ if (progress) {
+ display_progress(progress, istate->cache_nr);
+ stop_progress(&progress);
+ }
trace_performance_since(start, "refresh index");
return has_errors;
}