@matheusbsbs / matheus-bagliano / commits / a3a32e7f08
Fork 0

cherry: split off function to print output lines

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>

Jonathan Nieder committed Mar 16, 2011 at 02:12 UTC a3a32e7f083cdd3b8e68419d2f012b5561a9ccde
1 file changed +18 -16
builtin/log.c
+18 -16
@@ -1352,6 +1352,23 @@ static const char * const cherry_usage[] = {
1352 NULL
1353 };
1354
1355 +static void print_commit(char sign, struct commit *commit, int verbose,
1356 + int abbrev)
1357 +{
1358 + if (!verbose) {
1359 + printf("%c %s\n", sign,
1360 + find_unique_abbrev(commit->object.sha1, abbrev));
1361 + } else {
1362 + struct strbuf buf = STRBUF_INIT;
1363 + struct pretty_print_context ctx = {0};
1364 + pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
1365 + printf("%c %s %s\n", sign,
1366 + find_unique_abbrev(commit->object.sha1, abbrev),
1367 + buf.buf);
1368 + strbuf_release(&buf);
1369 + }
1370 +}
1371 +
1372 int cmd_cherry(int argc, const char **argv, const char *prefix)
1373 {
1374 struct rev_info revs;
@@ -1436,22 +1453,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1453 commit = list->item;
1454 if (has_commit_patch_id(commit, &ids))
1455 sign = '-';
1439 -
1440 - if (verbose) {
1441 - struct strbuf buf = STRBUF_INIT;
1442 - struct pretty_print_context ctx = {0};
1443 - pretty_print_commit(CMIT_FMT_ONELINE, commit,
1444 - &buf, &ctx);
1445 - printf("%c %s %s\n", sign,
1446 - find_unique_abbrev(commit->object.sha1, abbrev),
1447 - buf.buf);
1448 - strbuf_release(&buf);
1449 - }
1450 - else {
1451 - printf("%c %s\n", sign,
1452 - find_unique_abbrev(commit->object.sha1, abbrev));
1453 - }
1454 -
1456 + print_commit(sign, commit, verbose, abbrev);
1457 list = list->next;
1458 }
1459