mirror of
https://github.com/git/git
synced 2024-08-28 03:59:25 +00:00
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>
This commit is contained in:
parent
9cba13ca5d
commit
6e0332ec3e
|
@ -390,6 +390,30 @@ static int matches_merge_filter(struct commit *commit)
|
||||||
return (is_merged == (merge_filter == SHOW_MERGED));
|
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,
|
static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
|
||||||
int abbrev, int current, char *prefix)
|
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)
|
if (item->dest)
|
||||||
strbuf_addf(&out, " -> %s", item->dest);
|
strbuf_addf(&out, " -> %s", item->dest);
|
||||||
else if (verbose) {
|
else if (verbose)
|
||||||
struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
|
/* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */
|
||||||
const char *sub = " **** invalid ref ****";
|
add_verbose_info(&out, item, verbose, abbrev);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
printf("%s\n", out.buf);
|
printf("%s\n", out.buf);
|
||||||
strbuf_release(&name);
|
strbuf_release(&name);
|
||||||
strbuf_release(&out);
|
strbuf_release(&out);
|
||||||
|
|
Loading…
Reference in a new issue