@matheusbsbs / matheus-bagliano / commits / 2d8a7f0b30
Fork 0

branch: show upstream branch when double verbose

This information is easily accessible when we are calculating the relationship. The only reason not to print it all the time is that it consumes a fair bit of screen space, and may not be of interest to the user. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 7, 2009 at 03:16 UTC 2d8a7f0b30b4f9ef750ab763aabec117ffe4e749
2 files changed +20 -7
Documentation/git-branch.txt
+3 -1
@@ -100,7 +100,9 @@ OPTIONS
100
101 -v::
102 --verbose::
103 - Show sha1 and commit subject line for each head.
103 + Show sha1 and commit subject line for each head, along with
104 + relationship to upstream branch (if any). If given twice, print
105 + the name of the upstream branch, as well.
106
107 --abbrev=<length>::
108 Alter the sha1's minimum display length in the output listing.
builtin-branch.c
+17 -6
@@ -301,19 +301,30 @@ static int ref_cmp(const void *r1, const void *r2)
301 return strcmp(c1->name, c2->name);
302 }
303
304 -static void fill_tracking_info(struct strbuf *stat, const char *branch_name)
304 +static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
305 + int show_upstream_ref)
306 {
307 int ours, theirs;
308 struct branch *branch = branch_get(branch_name);
309
309 - if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
310 + if (!stat_tracking_info(branch, &ours, &theirs)) {
311 + if (branch && branch->merge && branch->merge[0]->dst &&
312 + show_upstream_ref)
313 + strbuf_addf(stat, "[%s] ",
314 + shorten_unambiguous_ref(branch->merge[0]->dst));
315 return;
316 + }
317 +
318 + strbuf_addch(stat, '[');
319 + if (show_upstream_ref)
320 + strbuf_addf(stat, "%s: ",
321 + shorten_unambiguous_ref(branch->merge[0]->dst));
322 if (!ours)
312 - strbuf_addf(stat, "[behind %d] ", theirs);
323 + strbuf_addf(stat, "behind %d] ", theirs);
324 else if (!theirs)
314 - strbuf_addf(stat, "[ahead %d] ", ours);
325 + strbuf_addf(stat, "ahead %d] ", ours);
326 else
316 - strbuf_addf(stat, "[ahead %d, behind %d] ", ours, theirs);
327 + strbuf_addf(stat, "ahead %d, behind %d] ", ours, theirs);
328 }
329
330 static int matches_merge_filter(struct commit *commit)
@@ -379,7 +390,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
390 }
391
392 if (item->kind == REF_LOCAL_BRANCH)
382 - fill_tracking_info(&stat, item->name);
393 + fill_tracking_info(&stat, item->name, verbose > 1);
394
395 strbuf_addf(&out, " %s %s%s",
396 find_unique_abbrev(item->commit->object.sha1, abbrev),