@matheusbsbs / matheus-bagliano / commits / 6e0332ec3e
Fork 0

branch: split off function that writes tracking info and commit subject

Introduce a add_verbose_info function that takes care of adding - an abbreviated object name; - a summary of the form [ahead x, behind y] of the relationship to the corresponding upstream branch; - a one line commit subject for the tip commit of a branch, for use in "git branch -v" output. No functional change intended. This just unindents the code a little and makes it easier to skip on first reading. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 16, 2011 at 02:10 UTC 6e0332ec3ea74e635258a30d360bd2e00a51730e
1 file changed +27 -21
builtin/branch.c
+27 -21
@@ -390,6 +390,30 @@ static int matches_merge_filter(struct commit *commit)
390 return (is_merged == (merge_filter == SHOW_MERGED));
391 }
392
393 +static void add_verbose_info(struct strbuf *out, struct ref_item *item,
394 + int verbose, int abbrev)
395 +{
396 + struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
397 + const char *sub = " **** invalid ref ****";
398 + struct commit *commit = item->commit;
399 +
400 + if (commit && !parse_commit(commit)) {
401 + struct pretty_print_context ctx = {0};
402 + pretty_print_commit(CMIT_FMT_ONELINE, commit,
403 + &subject, &ctx);
404 + sub = subject.buf;
405 + }
406 +
407 + if (item->kind == REF_LOCAL_BRANCH)
408 + fill_tracking_info(&stat, item->name, verbose > 1);
409 +
410 + strbuf_addf(out, " %s %s%s",
411 + find_unique_abbrev(item->commit->object.sha1, abbrev),
412 + stat.buf, sub);
413 + strbuf_release(&stat);
414 + strbuf_release(&subject);
415 +}
416 +
417 static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
418 int abbrev, int current, char *prefix)
419 {
@@ -430,27 +454,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
454
455 if (item->dest)
456 strbuf_addf(&out, " -> %s", item->dest);
433 - else if (verbose) {
434 - struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
435 - const char *sub = " **** invalid ref ****";
436 -
437 - commit = item->commit;
438 - if (commit && !parse_commit(commit)) {
439 - struct pretty_print_context ctx = {0};
440 - pretty_print_commit(CMIT_FMT_ONELINE, commit,
441 - &subject, &ctx);
442 - sub = subject.buf;
443 - }
444 -
445 - if (item->kind == REF_LOCAL_BRANCH)
446 - fill_tracking_info(&stat, item->name, verbose > 1);
447 -
448 - strbuf_addf(&out, " %s %s%s",
449 - find_unique_abbrev(item->commit->object.sha1, abbrev),
450 - stat.buf, sub);
451 - strbuf_release(&stat);
452 - strbuf_release(&subject);
453 - }
457 + else if (verbose)
458 + /* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */
459 + add_verbose_info(&out, item, verbose, abbrev);
460 printf("%s\n", out.buf);
461 strbuf_release(&name);
462 strbuf_release(&out);