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 <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3ca1897cc1
commit
f39a757dd9
@ -610,7 +610,7 @@ static void report_tracking(struct branch_info *new)
|
|||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
struct branch *branch = branch_get(new->name);
|
struct branch *branch = branch_get(new->name);
|
||||||
|
|
||||||
if (!format_tracking_info(branch, &sb))
|
if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
|
||||||
return;
|
return;
|
||||||
fputs(sb.buf, stdout);
|
fputs(sb.buf, stdout);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
|
18
remote.c
18
remote.c
@ -2096,15 +2096,16 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
|||||||
/*
|
/*
|
||||||
* Return true when there is anything to report, otherwise false.
|
* Return true when there is anything to report, otherwise false.
|
||||||
*/
|
*/
|
||||||
int format_tracking_info(struct branch *branch, struct strbuf *sb)
|
int format_tracking_info(struct branch *branch, struct strbuf *sb,
|
||||||
|
enum ahead_behind_flags abf)
|
||||||
{
|
{
|
||||||
int ours, theirs;
|
int ours, theirs, sti;
|
||||||
const char *full_base;
|
const char *full_base;
|
||||||
char *base;
|
char *base;
|
||||||
int upstream_is_gone = 0;
|
int upstream_is_gone = 0;
|
||||||
|
|
||||||
if (stat_tracking_info(branch, &ours, &theirs, &full_base,
|
sti = stat_tracking_info(branch, &ours, &theirs, &full_base, abf);
|
||||||
AHEAD_BEHIND_FULL) < 0) {
|
if (sti < 0) {
|
||||||
if (!full_base)
|
if (!full_base)
|
||||||
return 0;
|
return 0;
|
||||||
upstream_is_gone = 1;
|
upstream_is_gone = 1;
|
||||||
@ -2118,10 +2119,17 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
|
|||||||
if (advice_status_hints)
|
if (advice_status_hints)
|
||||||
strbuf_addstr(sb,
|
strbuf_addstr(sb,
|
||||||
_(" (use \"git branch --unset-upstream\" to fixup)\n"));
|
_(" (use \"git branch --unset-upstream\" to fixup)\n"));
|
||||||
} else if (!ours && !theirs) {
|
} else if (!sti) {
|
||||||
strbuf_addf(sb,
|
strbuf_addf(sb,
|
||||||
_("Your branch is up to date with '%s'.\n"),
|
_("Your branch is up to date with '%s'.\n"),
|
||||||
base);
|
base);
|
||||||
|
} else if (abf == AHEAD_BEHIND_QUICK) {
|
||||||
|
strbuf_addf(sb,
|
||||||
|
_("Your branch and '%s' refer to different commits.\n"),
|
||||||
|
base);
|
||||||
|
if (advice_status_hints)
|
||||||
|
strbuf_addf(sb, _(" (use \"%s\" for details)\n"),
|
||||||
|
"git status --ahead-behind");
|
||||||
} else if (!theirs) {
|
} else if (!theirs) {
|
||||||
strbuf_addf(sb,
|
strbuf_addf(sb,
|
||||||
Q_("Your branch is ahead of '%s' by %d commit.\n",
|
Q_("Your branch is ahead of '%s' by %d commit.\n",
|
||||||
|
3
remote.h
3
remote.h
@ -267,7 +267,8 @@ enum ahead_behind_flags {
|
|||||||
/* Reporting of tracking info */
|
/* Reporting of tracking info */
|
||||||
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
const char **upstream_name, enum ahead_behind_flags abf);
|
const char **upstream_name, enum ahead_behind_flags abf);
|
||||||
int format_tracking_info(struct branch *branch, struct strbuf *sb);
|
int format_tracking_info(struct branch *branch, struct strbuf *sb,
|
||||||
|
enum ahead_behind_flags abf);
|
||||||
|
|
||||||
struct ref *get_local_heads(void);
|
struct ref *get_local_heads(void);
|
||||||
/*
|
/*
|
||||||
|
@ -159,6 +159,35 @@ test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
|
|||||||
test_i18ncmp expect actual
|
test_i18ncmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat >expect <<\EOF
|
||||||
|
On branch b1
|
||||||
|
Your branch and 'origin/master' have diverged,
|
||||||
|
and have 1 and 1 different commits each, respectively.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'status --long --branch' '
|
||||||
|
(
|
||||||
|
cd test &&
|
||||||
|
git checkout b1 >/dev/null &&
|
||||||
|
git status --long -b | head -3
|
||||||
|
) >actual &&
|
||||||
|
test_i18ncmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
cat >expect <<\EOF
|
||||||
|
On branch b1
|
||||||
|
Your branch and 'origin/master' refer to different commits.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'status --long --branch --no-ahead-behind' '
|
||||||
|
(
|
||||||
|
cd test &&
|
||||||
|
git checkout b1 >/dev/null &&
|
||||||
|
git status --long -b --no-ahead-behind | head -2
|
||||||
|
) >actual &&
|
||||||
|
test_i18ncmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
cat >expect <<\EOF
|
cat >expect <<\EOF
|
||||||
## b5...brokenbase [gone]
|
## b5...brokenbase [gone]
|
||||||
EOF
|
EOF
|
||||||
|
@ -1011,7 +1011,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
|
|||||||
if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
|
if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
|
||||||
return;
|
return;
|
||||||
branch = branch_get(branch_name);
|
branch = branch_get(branch_name);
|
||||||
if (!format_tracking_info(branch, &sb))
|
if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user