Skip to content

Commit 15b2127

Browse files
jeffhostetlerGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
status: support --no-ahead-behind in long format
Teach long (normal) status format to respect the --no-ahead-behind parameter and skip the possibly expensive ahead/behind computation between the branch and the upstream. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6343699 commit 15b2127

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static void report_tracking(struct branch_info *new)
610610
struct strbuf sb = STRBUF_INIT;
611611
struct branch *branch = branch_get(new->name);
612612

613-
if (!format_tracking_info(branch, &sb))
613+
if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
614614
return;
615615
fputs(sb.buf, stdout);
616616
strbuf_release(&sb);

remote.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,15 +2096,16 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
20962096
/*
20972097
* Return true when there is anything to report, otherwise false.
20982098
*/
2099-
int format_tracking_info(struct branch *branch, struct strbuf *sb)
2099+
int format_tracking_info(struct branch *branch, struct strbuf *sb,
2100+
enum ahead_behind_flags abf)
21002101
{
2101-
int ours, theirs;
2102+
int ours, theirs, sti;
21022103
const char *full_base;
21032104
char *base;
21042105
int upstream_is_gone = 0;
21052106

2106-
if (stat_tracking_info(branch, &ours, &theirs, &full_base,
2107-
AHEAD_BEHIND_FULL) < 0) {
2107+
sti = stat_tracking_info(branch, &ours, &theirs, &full_base, abf);
2108+
if (sti < 0) {
21082109
if (!full_base)
21092110
return 0;
21102111
upstream_is_gone = 1;
@@ -2118,10 +2119,17 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
21182119
if (advice_status_hints)
21192120
strbuf_addstr(sb,
21202121
_(" (use \"git branch --unset-upstream\" to fixup)\n"));
2121-
} else if (!ours && !theirs) {
2122+
} else if (!sti) {
21222123
strbuf_addf(sb,
21232124
_("Your branch is up to date with '%s'.\n"),
21242125
base);
2126+
} else if (abf == AHEAD_BEHIND_QUICK) {
2127+
strbuf_addf(sb,
2128+
_("Your branch and '%s' refer to different commits.\n"),
2129+
base);
2130+
if (advice_status_hints)
2131+
strbuf_addf(sb, _(" (use \"%s\" for details)\n"),
2132+
"git status --ahead-behind");
21252133
} else if (!theirs) {
21262134
strbuf_addf(sb,
21272135
Q_("Your branch is ahead of '%s' by %d commit.\n",

remote.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ enum ahead_behind_flags {
267267
/* Reporting of tracking info */
268268
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
269269
const char **upstream_name, enum ahead_behind_flags abf);
270-
int format_tracking_info(struct branch *branch, struct strbuf *sb);
270+
int format_tracking_info(struct branch *branch, struct strbuf *sb,
271+
enum ahead_behind_flags abf);
271272

272273
struct ref *get_local_heads(void);
273274
/*

t/t6040-tracking-info.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,35 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
159159
test_i18ncmp expect actual
160160
'
161161

162+
cat >expect <<\EOF
163+
On branch b1
164+
Your branch and 'origin/master' have diverged,
165+
and have 1 and 1 different commits each, respectively.
166+
EOF
167+
168+
test_expect_success 'status --long --branch' '
169+
(
170+
cd test &&
171+
git checkout b1 >/dev/null &&
172+
git status --long -b | head -3
173+
) >actual &&
174+
test_i18ncmp expect actual
175+
'
176+
177+
cat >expect <<\EOF
178+
On branch b1
179+
Your branch and 'origin/master' refer to different commits.
180+
EOF
181+
182+
test_expect_success 'status --long --branch --no-ahead-behind' '
183+
(
184+
cd test &&
185+
git checkout b1 >/dev/null &&
186+
git status --long -b --no-ahead-behind | head -2
187+
) >actual &&
188+
test_i18ncmp expect actual
189+
'
190+
162191
cat >expect <<\EOF
163192
## b5...brokenbase [gone]
164193
EOF

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
10111011
if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
10121012
return;
10131013
branch = branch_get(branch_name);
1014-
if (!format_tracking_info(branch, &sb))
1014+
if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
10151015
return;
10161016

10171017
i = 0;

0 commit comments

Comments
 (0)