summaryrefslogtreecommitdiff
path: root/builtin/branch.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-03-16 02:10:14 -0500
committerJunio C Hamano <gitster@pobox.com>2011-03-16 12:52:15 -0700
commit6e0332ec3ea74e635258a30d360bd2e00a51730e (patch)
tree80a38c518e629e2dbdde4d295b11c7b8f3eea6e5 /builtin/branch.c
parent9cba13ca5d233a4e1a7068f3f5ed5836a081dcc0 (diff)
downloadgit-6e0332ec3ea74e635258a30d360bd2e00a51730e.tar.gz
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>
Diffstat (limited to 'builtin/branch.c')
-rw-r--r--builtin/branch.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index fe8f2fcd52..b9ba011f7b 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -390,6 +390,30 @@ static int matches_merge_filter(struct commit *commit)
return (is_merged == (merge_filter == SHOW_MERGED));
}
+static void add_verbose_info(struct strbuf *out, struct ref_item *item,
+ int verbose, int abbrev)
+{
+ struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
+ const char *sub = " **** invalid ref ****";
+ struct commit *commit = item->commit;
+
+ if (commit && !parse_commit(commit)) {
+ struct pretty_print_context ctx = {0};
+ pretty_print_commit(CMIT_FMT_ONELINE, commit,
+ &subject, &ctx);
+ sub = subject.buf;
+ }
+
+ if (item->kind == REF_LOCAL_BRANCH)
+ fill_tracking_info(&stat, item->name, verbose > 1);
+
+ strbuf_addf(out, " %s %s%s",
+ find_unique_abbrev(item->commit->object.sha1, abbrev),
+ stat.buf, sub);
+ strbuf_release(&stat);
+ strbuf_release(&subject);
+}
+
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
int abbrev, int current, char *prefix)
{
@@ -430,27 +454,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
if (item->dest)
strbuf_addf(&out, " -> %s", item->dest);
- else if (verbose) {
- struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
- const char *sub = " **** invalid ref ****";
-
- commit = item->commit;
- if (commit && !parse_commit(commit)) {
- struct pretty_print_context ctx = {0};
- pretty_print_commit(CMIT_FMT_ONELINE, commit,
- &subject, &ctx);
- sub = subject.buf;
- }
-
- if (item->kind == REF_LOCAL_BRANCH)
- fill_tracking_info(&stat, item->name, verbose > 1);
-
- strbuf_addf(&out, " %s %s%s",
- find_unique_abbrev(item->commit->object.sha1, abbrev),
- stat.buf, sub);
- strbuf_release(&stat);
- strbuf_release(&subject);
- }
+ else if (verbose)
+ /* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */
+ add_verbose_info(&out, item, verbose, abbrev);
printf("%s\n", out.buf);
strbuf_release(&name);
strbuf_release(&out);