Code

Merge branch 'jc/branch-merged'
[git.git] / builtin-branch.c
index 1926c47581050168abd0a5ed4e6ce45100cde2cf..7dae22c0197c2d3d062b0fa34c15b6c9a489eb31 100644 (file)
@@ -289,6 +289,21 @@ 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))
+               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)
 {
@@ -317,8 +332,10 @@ 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);
+               stat[0] = '\0';
 
                commit = lookup_commit(item->sha1);
                if (commit && !parse_commit(commit)) {
@@ -326,10 +343,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,