aboutsummaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-07-02 00:52:41 -0700
committerJunio C Hamano <gitster@pobox.com>2008-07-02 23:32:25 -0700
commit94fcb730ff665d356689f3d30e20e0fd75c6f62f (patch)
tree6e6676ae1cb950d80a2ef9ae4737969ea76c2de3 /builtin-branch.c
parentb6975ab59b07e5416b3f9b6f077d3cb50ef5ac7e (diff)
downloadgit-94fcb730ff665d356689f3d30e20e0fd75c6f62f.tar.gz
git-94fcb730ff665d356689f3d30e20e0fd75c6f62f.tar.xz
git-branch -v: show the remote tracking statistics
This teaches "git branch -v" to insert the remote tracking statistics in brackets, just before the one-liner commit log message for the branch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-branch.c')
-rw-r--r--builtin-branch.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index d279702ba..e9423d1e4 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -282,6 +282,23 @@ static int ref_cmp(const void *r1, const void *r2)
return strcmp(c1->name, c2->name);
}
+static void fill_tracking_info(char *stat, const char *branch_name)
+{
+ int ours, theirs;
+ struct branch *branch = branch_get(branch_name);
+
+ if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) {
+ stat[0] = '\0';
+ return;
+ }
+ if (!ours)
+ sprintf(stat, "[behind %d] ", theirs);
+ else if (!theirs)
+ sprintf(stat, "[ahead %d] ", ours);
+ else
+ sprintf(stat, "[ahead %d, behind %d] ", ours, theirs);
+}
+
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
int abbrev, int current)
{
@@ -310,6 +327,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
if (verbose) {
struct strbuf subject;
const char *sub = " **** invalid ref ****";
+ char stat[128];
strbuf_init(&subject, 0);
@@ -319,10 +337,15 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
&subject, 0, NULL, NULL, 0, 0);
sub = subject.buf;
}
- printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
+
+ if (item->kind == REF_LOCAL_BRANCH)
+ fill_tracking_info(stat, item->name);
+
+ printf("%c %s%-*s%s %s %s%s\n", c, branch_get_color(color),
maxwidth, item->name,
branch_get_color(COLOR_BRANCH_RESET),
- find_unique_abbrev(item->sha1, abbrev), sub);
+ find_unique_abbrev(item->sha1, abbrev),
+ stat, sub);
strbuf_release(&subject);
} else {
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,