aboutsummaryrefslogtreecommitdiffstats
path: root/wt-status.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2019-06-18 13:21:27 -0700
committerJunio C Hamano <gitster@pobox.com>2019-06-21 09:35:02 -0700
commit0a53561a6221f989b210797e62e83fb7260fa42c (patch)
treecee0de1cd4a6583ab2e99c249707b0d6c8fc5961 /wt-status.c
parent06b324c1d71411cdd31da03da9e85b1880ef1c4b (diff)
downloadgit-0a53561a6221f989b210797e62e83fb7260fa42c.tar.gz
status: warn when a/b calculation takes too long
The ahead/behind calculation in 'git status' can be slow in some cases. Users may not realize that there are ways to avoid this computation, especially if they are not using the information. Add a warning that appears if this calculation takes more than two seconds. The warning can be disabled through the new config setting advice.statusAheadBehind. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/wt-status.c b/wt-status.c
index 0bccef542f..d4e45f9e6a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -19,6 +19,8 @@
#include "lockfile.h"
#include "sequencer.h"
+#define AB_DELAY_WARNING_IN_MS (2 * 1000)
+
static const char cut_line[] =
"------------------------ >8 ------------------------\n";
@@ -1085,14 +1087,29 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
struct branch *branch;
char comment_line_string[3];
int i;
+ uint64_t t_begin = 0;
assert(s->branch && !s->is_initial);
if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
return;
branch = branch_get(branch_name);
+
+ t_begin = getnanotime();
+
if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
return;
+ if (advice_status_ahead_behind_warning &&
+ s->ahead_behind_flags == AHEAD_BEHIND_FULL) {
+ uint64_t t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
+ if (t_delta_in_ms > AB_DELAY_WARNING_IN_MS) {
+ strbuf_addf(&sb, _("\n"
+ "It took %.2f seconds to compute the branch ahead/behind values.\n"
+ "You can use '--no-ahead-behind' to avoid this.\n"),
+ t_delta_in_ms / 1000.0);
+ }
+ }
+
i = 0;
if (s->display_comment_prefix) {
comment_line_string[i++] = comment_line_char;