summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2018-01-09 18:50:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-24 21:48:38 (GMT)
commitfd9b544a2991ad74d73ad1bc0af4d24f91a6802b (patch)
tree175285017f510542e6bf558d94d025518bd3dd5d /wt-status.c
parentd7d1b496aeea5a151c826683ed28c57ef0ac9389 (diff)
downloadgit-fd9b544a2991ad74d73ad1bc0af4d24f91a6802b.zip
git-fd9b544a2991ad74d73ad1bc0af4d24f91a6802b.tar.gz
git-fd9b544a2991ad74d73ad1bc0af4d24f91a6802b.tar.bz2
status: add --[no-]ahead-behind to status and commit for V2 format.
Teach "git status" and "git commit" to accept "--no-ahead-behind" and "--ahead-behind" arguments to request quick or full ahead/behind reporting. When "--no-ahead-behind" is given, the existing porcelain V2 line "branch.ab +x -y" is replaced with a new "branch.ab +? -?" line. This indicates that the branch and its upstream are or are not equal without the expense of computing the full ahead/behind values. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/wt-status.c b/wt-status.c
index 1137f27..7a560c1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -136,6 +136,7 @@ void wt_status_prepare(struct wt_status *s)
s->ignored.strdup_strings = 1;
s->show_branch = -1; /* unspecified */
s->show_stash = 0;
+ s->ahead_behind_flags = AHEAD_BEHIND_UNSPECIFIED;
s->display_comment_prefix = 0;
}
@@ -1883,18 +1884,19 @@ static void wt_porcelain_print(struct wt_status *s)
*
* <upstream> ::= the upstream branch name, when set.
*
- * <ahead> ::= integer ahead value, when upstream set
- * and the commit is present (not gone).
- *
- * <behind> ::= integer behind value, when upstream set
- * and commit is present.
+ * <ahead> ::= integer ahead value or '?'.
*
+ * <behind> ::= integer behind value or '?'.
*
* The end-of-line is defined by the -z flag.
*
* <eol> ::= NUL when -z,
* LF when NOT -z.
*
+ * When an upstream is set and present, the 'branch.ab' line will
+ * be printed with the ahead/behind counts for the branch and the
+ * upstream. When AHEAD_BEHIND_QUICK is requested and the branches
+ * are different, '?' will be substituted for the actual count.
*/
static void wt_porcelain_v2_print_tracking(struct wt_status *s)
{
@@ -1934,15 +1936,25 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
/* Lookup stats on the upstream tracking branch, if set. */
branch = branch_get(branch_name);
base = NULL;
- ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind,
- &base, AHEAD_BEHIND_FULL) >= 0);
+ ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
+ &base, s->ahead_behind_flags);
if (base) {
base = shorten_unambiguous_ref(base, 0);
fprintf(s->fp, "# branch.upstream %s%c", base, eol);
free((char *)base);
- if (ab_info)
- fprintf(s->fp, "# branch.ab +%d -%d%c", nr_ahead, nr_behind, eol);
+ if (ab_info > 0) {
+ /* different */
+ if (nr_ahead || nr_behind)
+ fprintf(s->fp, "# branch.ab +%d -%d%c",
+ nr_ahead, nr_behind, eol);
+ else
+ fprintf(s->fp, "# branch.ab +? -?%c",
+ eol);
+ } else if (!ab_info) {
+ /* same */
+ fprintf(s->fp, "# branch.ab +0 -0%c", eol);
+ }
}
}