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>
Junio C Hamano committed
Jul 2, 2008 at 00:52 UTC
94fcb730ff665d356689f3d30e20e0fd75c6f62f
1 file changed
+25
-2
builtin-branch.c
+25
-2
@@ -282,6 +282,23 @@ static int ref_cmp(const void *r1, const void *r2)
282
return strcmp(c1->name, c2->name);
283
}
284
285
+static void fill_tracking_info(char *stat, const char *branch_name)
286
+{
287
+ int ours, theirs;
288
+ struct branch *branch = branch_get(branch_name);
289
+
290
+ if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) {
291
+ stat[0] = '\0';
292
+ return;
293
+ }
294
+ if (!ours)
295
+ sprintf(stat, "[behind %d] ", theirs);
296
+ else if (!theirs)
297
+ sprintf(stat, "[ahead %d] ", ours);
298
+ else
299
+ sprintf(stat, "[ahead %d, behind %d] ", ours, theirs);
300
+}
301
+
302
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
303
int abbrev, int current)
304
{
@@ -310,6 +327,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
327
if (verbose) {
328
struct strbuf subject;
329
const char *sub = " **** invalid ref ****";
330
+ char stat[128];
331
332
strbuf_init(&subject, 0);
333
@@ -319,10 +337,15 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
337
&subject, 0, NULL, NULL, 0, 0);
338
sub = subject.buf;
339
}
322
- printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
340
+
341
+ if (item->kind == REF_LOCAL_BRANCH)
342
+ fill_tracking_info(stat, item->name);
343
+
344
+ printf("%c %s%-*s%s %s %s%s\n", c, branch_get_color(color),
345
maxwidth, item->name,
346
branch_get_color(COLOR_BRANCH_RESET),
325
- find_unique_abbrev(item->sha1, abbrev), sub);
347
+ find_unique_abbrev(item->sha1, abbrev),
348
+ stat, sub);
349
strbuf_release(&subject);
350
} else {
351
printf("%c %s%s%s\n", c, branch_get_color(color), item->name,