Skip to content

Commit

Permalink
status: add warning when a/b calculation takes too long for long/norm…
Browse files Browse the repository at this point in the history
…al format

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Jun 8, 2019
1 parent 74abe74 commit 5ce9921
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions advice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions advice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -1088,14 +1090,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;
Expand Down

0 comments on commit 5ce9921

Please sign in to comment.