status: warn when a/b calculation takes too long
authorJeff Hostetler <jeffhost@microsoft.com>
Tue, 18 Jun 2019 20:21:27 +0000 (13:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Jun 2019 16:35:02 +0000 (09:35 -0700)
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>
Documentation/config/advice.txt
advice.c
advice.h
wt-status.c
index ec4f6ae6585bac4b107134e52f544d53c24cdf86..4bc5b4c74236f2f659c779d45b7efab1ab55a992 100644 (file)
@@ -37,6 +37,12 @@ advice.*::
                we can still suggest that the user push to either
                refs/heads/* or refs/tags/* based on the type of the
                source object.
+       statusAheadBehind::
+               Shown when linkgit:git-status[1] computes the ahead/behind
+               counts for a local ref compared to its remote tracking ref,
+               and that calculation takes longer than expected. Will not
+               appear if `status.aheadBehind` is false or the option
+               `--no-ahead-behind` is given.
        statusHints::
                Show directions on how to proceed from the current
                state in the output of linkgit:git-status[1], in
index ce5f374ecd4917346145c8a380ac8c0e45e849a4..54f8dea30c99ce26cf28dd818eae03404170995d 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -12,6 +12,7 @@ int advice_push_needs_force = 1;
 int advice_push_unqualified_ref_name = 1;
 int advice_status_hints = 1;
 int advice_status_u_option = 1;
+int advice_status_ahead_behind_warning = 1;
 int advice_commit_before_merge = 1;
 int advice_reset_quiet_warning = 1;
 int advice_resolve_conflict = 1;
@@ -68,6 +69,7 @@ static struct {
        { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name },
        { "statusHints", &advice_status_hints },
        { "statusUoption", &advice_status_u_option },
+       { "statusAheadBehindWarning", &advice_status_ahead_behind_warning },
        { "commitBeforeMerge", &advice_commit_before_merge },
        { "resetQuiet", &advice_reset_quiet_warning },
        { "resolveConflict", &advice_resolve_conflict },
index e50f02cdfeff788910699f2d34fff1c93081c24b..c86de9b9b83b7aa78899347216eb17ada59430a8 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -12,6 +12,7 @@ extern int advice_push_needs_force;
 extern int advice_push_unqualified_ref_name;
 extern int advice_status_hints;
 extern int advice_status_u_option;
+extern int advice_status_ahead_behind_warning;
 extern int advice_commit_before_merge;
 extern int advice_reset_quiet_warning;
 extern int advice_resolve_conflict;
index 0bccef542fccee5deaa6ee3c740f60879aa97fb3..d4e45f9e6a94d6d59536f5e9e29f3bc238733e63 100644 (file)
@@ -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;