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>
This commit is contained in:
committed by
Junio C Hamano
parent
1d4361b0f3
commit
ae9af12287
12
read-cache.c
12
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user