From: Ben Peart <peartben@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, benpeart@microsoft.com, peartben@gmail.com,
peff@peff.net, sunshine@sunshineco.com
Subject: [PATCH v4 3/3] reset: warn when refresh_index() takes more than 2 seconds
Date: Tue, 23 Oct 2018 15:04:23 -0400 [thread overview]
Message-ID: <20181023190423.5772-4-peartben@gmail.com> (raw)
In-Reply-To: <20181023190423.5772-1-peartben@gmail.com>
From: Ben Peart <benpeart@microsoft.com>
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>
---
Documentation/config.txt | 4 ++++
advice.c | 2 ++
advice.h | 1 +
builtin/reset.c | 14 +++++++++++++-
4 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index a2d1b8b116..415db31def 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -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.
diff --git a/advice.c b/advice.c
index 3561cd64e9..5f35656409 100644
--- 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 },
diff --git a/advice.h b/advice.h
index ab24df0fd0..696bf0e7d2 100644
--- 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;
diff --git a/builtin/reset.c b/builtin/reset.c
index 3b43aee544..b31a0eae8a 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -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>..."),
@@ -376,9 +378,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)
--
2.18.0.windows.1
prev parent reply other threads:[~2018-10-23 19:04 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-17 16:40 [PATCH v1 0/2] speed up git reset Ben Peart
2018-10-17 16:40 ` [PATCH v1 1/2] reset: don't compute unstaged changes after reset when --quiet Ben Peart
2018-10-17 18:14 ` Eric Sunshine
2018-10-17 18:22 ` Jeff King
2018-10-18 3:40 ` Junio C Hamano
2018-10-18 6:36 ` Jeff King
2018-10-18 18:15 ` Ben Peart
2018-10-18 18:26 ` Duy Nguyen
2018-10-18 19:03 ` Ben Peart
2018-10-19 0:34 ` Junio C Hamano
2018-10-17 16:40 ` [PATCH v1 2/2] reset: add new reset.quietDefault config setting Ben Peart
2018-10-17 18:19 ` Eric Sunshine
2018-10-17 18:23 ` Jeff King
2018-10-23 9:13 ` Ævar Arnfjörð Bjarmason
2018-10-23 18:11 ` Ben Peart
2018-10-23 20:02 ` Jeff King
2018-10-23 20:03 ` Ævar Arnfjörð Bjarmason
2018-10-24 15:48 ` Recommended configurations (was Re: [PATCH v1 2/2] reset: add new reset.quietDefault config setting) Derrick Stolee
2018-10-24 23:58 ` Jeff King
2018-10-25 4:09 ` Junio C Hamano
2018-10-19 16:12 ` [PATCH v2 0/3] speed up git reset Ben Peart
2018-10-19 16:12 ` [PATCH v2 1/3] reset: don't compute unstaged changes after reset when --quiet Ben Peart
2018-10-19 16:12 ` [PATCH v2 2/3] reset: add new reset.quiet config setting Ben Peart
2018-10-19 16:36 ` Eric Sunshine
2018-10-19 16:46 ` Jeff King
2018-10-19 17:10 ` Eric Sunshine
2018-10-19 17:11 ` Jeff King
2018-10-19 17:23 ` Ben Peart
2018-10-19 19:08 ` Jeff King
2018-10-22 5:04 ` Junio C Hamano
2018-10-19 17:11 ` Ben Peart
2018-10-19 16:12 ` [PATCH v2 3/3] reset: warn when refresh_index() takes more than 2 seconds Ben Peart
2018-10-22 13:18 ` [PATCH v3 0/3] speed up git reset Ben Peart
2018-10-22 13:18 ` [PATCH v3 1/3] reset: don't compute unstaged changes after reset when --quiet Ben Peart
2018-10-22 20:44 ` Johannes Schindelin
2018-10-22 22:07 ` Ben Peart
2018-10-23 8:53 ` Johannes Schindelin
2018-10-23 15:46 ` Duy Nguyen
2018-10-23 19:55 ` Johannes Schindelin
2018-10-22 13:18 ` [PATCH v3 2/3] reset: add new reset.quiet config setting Ben Peart
2018-10-22 14:45 ` Duy Nguyen
2018-10-23 18:47 ` Ben Peart
2018-10-24 2:56 ` Junio C Hamano
2018-10-24 7:21 ` Junio C Hamano
2018-10-24 14:54 ` Duy Nguyen
2018-10-25 1:12 ` Junio C Hamano
2018-10-24 14:49 ` Duy Nguyen
2018-10-22 19:13 ` Ramsay Jones
2018-10-22 20:06 ` Jeff King
2018-10-23 17:31 ` Ben Peart
2018-10-23 17:35 ` Jeff King
2018-10-22 13:18 ` [PATCH v3 3/3] reset: warn when refresh_index() takes more than 2 seconds Ben Peart
2018-10-23 0:23 ` Junio C Hamano
2018-10-23 17:12 ` Ben Peart
2018-10-23 19:04 ` [PATCH v4 0/3] speed up git reset Ben Peart
2018-10-23 19:04 ` [PATCH v4 1/3] reset: don't compute unstaged changes after reset when --quiet Ben Peart
2018-10-23 19:04 ` [PATCH v4 2/3] reset: add new reset.quiet config setting Ben Peart
2018-10-24 0:39 ` Ramsay Jones
2018-10-25 4:56 ` Junio C Hamano
2018-10-25 9:26 ` Junio C Hamano
2018-10-25 13:26 ` Ben Peart
2018-10-25 17:04 ` Ramsay Jones
2018-10-23 19:04 ` Ben Peart [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181023190423.5772-4-peartben@gmail.com \
--to=peartben@gmail.com \
--cc=benpeart@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).