Skip to content

Commit 649bf3a

Browse files
benpeartgitster
authored andcommitted
reset: warn when refresh_index() takes more than 2 seconds
refresh_index() is done after a reset command as an optimization. Because it can be an expensive call, warn the user if it takes more than 2 seconds and tell them how to avoid it using the --quiet command line option or reset.quiet config setting. Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c3abd0 commit 649bf3a

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ advice.*::
333333
commitBeforeMerge::
334334
Advice shown when linkgit:git-merge[1] refuses to
335335
merge to avoid overwriting local changes.
336+
resetQuiet::
337+
Advice to consider using the `--quiet` option to linkgit:git-reset[1]
338+
when the command takes more than 2 seconds to enumerate unstaged
339+
changes after reset.
336340
resolveConflict::
337341
Advice shown by various commands when conflicts
338342
prevent the operation from being performed.

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int advice_push_needs_force = 1;
1212
int advice_status_hints = 1;
1313
int advice_status_u_option = 1;
1414
int advice_commit_before_merge = 1;
15+
int advice_reset_quiet_warning = 1;
1516
int advice_resolve_conflict = 1;
1617
int advice_implicit_identity = 1;
1718
int advice_detached_head = 1;
@@ -65,6 +66,7 @@ static struct {
6566
{ "statusHints", &advice_status_hints },
6667
{ "statusUoption", &advice_status_u_option },
6768
{ "commitBeforeMerge", &advice_commit_before_merge },
69+
{ "resetQuiet", &advice_reset_quiet_warning },
6870
{ "resolveConflict", &advice_resolve_conflict },
6971
{ "implicitIdentity", &advice_implicit_identity },
7072
{ "detachedHead", &advice_detached_head },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern int advice_push_needs_force;
1212
extern int advice_status_hints;
1313
extern int advice_status_u_option;
1414
extern int advice_commit_before_merge;
15+
extern int advice_reset_quiet_warning;
1516
extern int advice_resolve_conflict;
1617
extern int advice_implicit_identity;
1718
extern int advice_detached_head;

builtin/reset.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "submodule.h"
2626
#include "submodule-config.h"
2727

28+
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
29+
2830
static const char * const git_reset_usage[] = {
2931
N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
3032
N_("git reset [-q] [<tree-ish>] [--] <paths>..."),
@@ -377,9 +379,19 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
377379
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
378380
if (read_from_tree(&pathspec, &oid, intent_to_add))
379381
return 1;
380-
if (!quiet && get_git_work_tree())
382+
if (!quiet && get_git_work_tree()) {
383+
uint64_t t_begin, t_delta_in_ms;
384+
385+
t_begin = getnanotime();
381386
refresh_index(&the_index, flags, NULL, NULL,
382387
_("Unstaged changes after reset:"));
388+
t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
389+
if (advice_reset_quiet_warning && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
390+
printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset. You can\n"
391+
"use '--quiet' to avoid this. Set the config setting reset.quiet to true\n"
392+
"to make this the default.\n"), t_delta_in_ms / 1000.0);
393+
}
394+
}
383395
} else {
384396
int err = reset_index(&oid, reset_type, quiet);
385397
if (reset_type == KEEP && !err)

0 commit comments

Comments
 (0)