status: update short status to respect --no-ahead-behind

Teach "git status --short --branch" to respect "--no-ahead-behind" parameter to skip computing ahead/behind counts for the branch and its upstream and just report '[different]'. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Jan 9, 2018 at 18:50 UTC 3ca1897cc1a23f3ad140d759280b73ad7affe696
2 files changed +20 -4
t/t6040-tracking-info.sh
+13
@@ -146,6 +146,19 @@ test_expect_success 'status -s -b (diverged from upstream)' '
146 test_i18ncmp expect actual
147 '
148
149 +cat >expect <<\EOF
150 +## b1...origin/master [different]
151 +EOF
152 +
153 +test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
154 + (
155 + cd test &&
156 + git checkout b1 >/dev/null &&
157 + git status -s -b --no-ahead-behind | head -1
158 + ) >actual &&
159 + test_i18ncmp expect actual
160 +'
161 +
162 cat >expect <<\EOF
163 ## b5...brokenbase [gone]
164 EOF
wt-status.c
+7 -4
@@ -1771,7 +1771,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1771 const char *base;
1772 char *short_base;
1773 const char *branch_name;
1774 - int num_ours, num_theirs;
1774 + int num_ours, num_theirs, sti;
1775 int upstream_is_gone = 0;
1776
1777 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1797,8 +1797,9 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1797
1798 color_fprintf(s->fp, branch_color_local, "%s", branch_name);
1799
1800 - if (stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1801 - AHEAD_BEHIND_FULL) < 0) {
1800 + sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1801 + s->ahead_behind_flags);
1802 + if (sti < 0) {
1803 if (!base)
1804 goto conclude;
1805
@@ -1810,12 +1811,14 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1811 color_fprintf(s->fp, branch_color_remote, "%s", short_base);
1812 free(short_base);
1813
1813 - if (!upstream_is_gone && !num_ours && !num_theirs)
1814 + if (!upstream_is_gone && !sti)
1815 goto conclude;
1816
1817 color_fprintf(s->fp, header_color, " [");
1818 if (upstream_is_gone) {
1819 color_fprintf(s->fp, header_color, LABEL(N_("gone")));
1820 + } else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
1821 + color_fprintf(s->fp, header_color, LABEL(N_("different")));
1822 } else if (!num_ours) {
1823 color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
1824 color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);