Skip to content

Commit

Permalink
branch: show upstream branch when double verbose
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Apr 8, 2009
1 parent 7c2b302 commit 2d8a7f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Documentation/git-branch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ OPTIONS

-v::
--verbose::
Show sha1 and commit subject line for each head.
Show sha1 and commit subject line for each head, along with
relationship to upstream branch (if any). If given twice, print
the name of the upstream branch, as well.

--abbrev=<length>::
Alter the sha1's minimum display length in the output listing.
Expand Down
23 changes: 17 additions & 6 deletions builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,30 @@ static int ref_cmp(const void *r1, const void *r2)
return strcmp(c1->name, c2->name);
}

static void fill_tracking_info(struct strbuf *stat, const char *branch_name)
static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
int show_upstream_ref)
{
int ours, theirs;
struct branch *branch = branch_get(branch_name);

if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
if (!stat_tracking_info(branch, &ours, &theirs)) {
if (branch && branch->merge && branch->merge[0]->dst &&
show_upstream_ref)
strbuf_addf(stat, "[%s] ",
shorten_unambiguous_ref(branch->merge[0]->dst));
return;
}

strbuf_addch(stat, '[');
if (show_upstream_ref)
strbuf_addf(stat, "%s: ",
shorten_unambiguous_ref(branch->merge[0]->dst));
if (!ours)
strbuf_addf(stat, "[behind %d] ", theirs);
strbuf_addf(stat, "behind %d] ", theirs);
else if (!theirs)
strbuf_addf(stat, "[ahead %d] ", ours);
strbuf_addf(stat, "ahead %d] ", ours);
else
strbuf_addf(stat, "[ahead %d, behind %d] ", ours, theirs);
strbuf_addf(stat, "ahead %d, behind %d] ", ours, theirs);
}

static int matches_merge_filter(struct commit *commit)
Expand Down Expand Up @@ -379,7 +390,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
}

if (item->kind == REF_LOCAL_BRANCH)
fill_tracking_info(&stat, item->name);
fill_tracking_info(&stat, item->name, verbose > 1);

strbuf_addf(&out, " %s %s%s",
find_unique_abbrev(item->commit->object.sha1, abbrev),
Expand Down

0 comments on commit 2d8a7f0

Please sign in to comment.