]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reset: warn when refresh_index() takes more than 2 seconds
authorBen Peart <benpeart@microsoft.com>
Tue, 23 Oct 2018 19:04:23 +0000 (15:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Oct 2018 02:57:08 +0000 (11:57 +0900)
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 <benpeart@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
advice.c
advice.h
builtin/reset.c

index fef680f88674b8e47900ad888ecdacd515ff4374..ce26a743bad9f59f352904a749536b1da8ee7e97 100644 (file)
@@ -333,6 +333,10 @@ advice.*::
        commitBeforeMerge::
                Advice shown when linkgit:git-merge[1] refuses to
                merge to avoid overwriting local changes.
+       resetQuiet::
+               Advice to consider using the `--quiet` option to linkgit:git-reset[1]
+               when the command takes more than 2 seconds to enumerate unstaged
+               changes after reset.
        resolveConflict::
                Advice shown by various commands when conflicts
                prevent the operation from being performed.
index 3561cd64e9dab0a5b0c52d117253f37a5926f9c7..5f35656409b1d51abf111efa5bbcc7f5d570aaf0 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -12,6 +12,7 @@ int advice_push_needs_force = 1;
 int advice_status_hints = 1;
 int advice_status_u_option = 1;
 int advice_commit_before_merge = 1;
+int advice_reset_quiet_warning = 1;
 int advice_resolve_conflict = 1;
 int advice_implicit_identity = 1;
 int advice_detached_head = 1;
@@ -65,6 +66,7 @@ static struct {
        { "statusHints", &advice_status_hints },
        { "statusUoption", &advice_status_u_option },
        { "commitBeforeMerge", &advice_commit_before_merge },
+       { "resetQuiet", &advice_reset_quiet_warning },
        { "resolveConflict", &advice_resolve_conflict },
        { "implicitIdentity", &advice_implicit_identity },
        { "detachedHead", &advice_detached_head },
index ab24df0fd0d0c739f6f58bb2650bb4162ef4c7f2..696bf0e7d29ee107c5faf10a59985c0f49612495 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -12,6 +12,7 @@ extern int advice_push_needs_force;
 extern int advice_status_hints;
 extern int advice_status_u_option;
 extern int advice_commit_before_merge;
+extern int advice_reset_quiet_warning;
 extern int advice_resolve_conflict;
 extern int advice_implicit_identity;
 extern int advice_detached_head;
index ff5f1756d511e7f800725992feb84e4620280227..58166964f84ce1b78f703bb10f92f713b2cce6b4 100644 (file)
@@ -25,6 +25,8 @@
 #include "submodule.h"
 #include "submodule-config.h"
 
+#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
+
 static const char * const git_reset_usage[] = {
        N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
        N_("git reset [-q] [<tree-ish>] [--] <paths>..."),
@@ -377,9 +379,19 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                        int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
                        if (read_from_tree(&pathspec, &oid, intent_to_add))
                                return 1;
-                       if (!quiet && get_git_work_tree())
+                       if (!quiet && get_git_work_tree()) {
+                               uint64_t t_begin, t_delta_in_ms;
+
+                               t_begin = getnanotime();
                                refresh_index(&the_index, flags, NULL, NULL,
                                              _("Unstaged changes after reset:"));
+                               t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
+                               if (advice_reset_quiet_warning && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
+                                       printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset.  You can\n"
+                                               "use '--quiet' to avoid this.  Set the config setting reset.quiet to true\n"
+                                               "to make this the default.\n"), t_delta_in_ms / 1000.0);
+                               }
+                       }
                } else {
                        int err = reset_index(&oid, reset_type, quiet);
                        if (reset_type == KEEP && !err)