Skip to content

Commit

Permalink
cherry: split off function to print output lines
Browse files Browse the repository at this point in the history
Readers uninterested in the details of "git cherry"'s output format
can see

	print_commit('-', commit, verbose, abbrev);

and ignore the details.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Mar 16, 2011
1 parent 6e0332e commit a3a32e7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,23 @@ static const char * const cherry_usage[] = {
NULL
};

static void print_commit(char sign, struct commit *commit, int verbose,
int abbrev)
{
if (!verbose) {
printf("%c %s\n", sign,
find_unique_abbrev(commit->object.sha1, abbrev));
} else {
struct strbuf buf = STRBUF_INIT;
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
printf("%c %s %s\n", sign,
find_unique_abbrev(commit->object.sha1, abbrev),
buf.buf);
strbuf_release(&buf);
}
}

int cmd_cherry(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
Expand Down Expand Up @@ -1436,22 +1453,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
commit = list->item;
if (has_commit_patch_id(commit, &ids))
sign = '-';

if (verbose) {
struct strbuf buf = STRBUF_INIT;
struct pretty_print_context ctx = {0};
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&buf, &ctx);
printf("%c %s %s\n", sign,
find_unique_abbrev(commit->object.sha1, abbrev),
buf.buf);
strbuf_release(&buf);
}
else {
printf("%c %s\n", sign,
find_unique_abbrev(commit->object.sha1, abbrev));
}

print_commit(sign, commit, verbose, abbrev);
list = list->next;
}

Expand Down

0 comments on commit a3a32e7

Please sign in to comment.