@matheusbsbs / matheus-bagliano / commits / 9991030c0c
Fork 0

git-blame: refactor code to emit "porcelain format" output

Both the --porcelain and --incremental format shared the same output format but implemented with two identical codepaths. This merges them into one shared function. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 4, 2008 at 22:48 UTC 9991030c0c97285087e5da86cfdbaf143a8a74cb
1 file changed +31 -34
builtin-blame.c
+31 -34
@@ -1490,6 +1490,34 @@ static void write_filename_info(const char *path)
1490 write_name_quoted(path, stdout, '\n');
1491 }
1492
1493 +/*
1494 + * Porcelain/Incremental format wants to show a lot of details per
1495 + * commit. Instead of repeating this every line, emit it only once,
1496 + * the first time each commit appears in the output.
1497 + */
1498 +static int emit_one_suspect_detail(struct origin *suspect)
1499 +{
1500 + struct commit_info ci;
1501 +
1502 + if (suspect->commit->object.flags & METAINFO_SHOWN)
1503 + return 0;
1504 +
1505 + suspect->commit->object.flags |= METAINFO_SHOWN;
1506 + get_commit_info(suspect->commit, &ci, 1);
1507 + printf("author %s\n", ci.author);
1508 + printf("author-mail %s\n", ci.author_mail);
1509 + printf("author-time %lu\n", ci.author_time);
1510 + printf("author-tz %s\n", ci.author_tz);
1511 + printf("committer %s\n", ci.committer);
1512 + printf("committer-mail %s\n", ci.committer_mail);
1513 + printf("committer-time %lu\n", ci.committer_time);
1514 + printf("committer-tz %s\n", ci.committer_tz);
1515 + printf("summary %s\n", ci.summary);
1516 + if (suspect->commit->object.flags & UNINTERESTING)
1517 + printf("boundary\n");
1518 + return 1;
1519 +}
1520 +
1521 /*
1522 * The blame_entry is found to be guilty for the range. Mark it
1523 * as such, and show it in incremental output.
@@ -1505,22 +1533,7 @@ static void found_guilty_entry(struct blame_entry *ent)
1533 printf("%s %d %d %d\n",
1534 sha1_to_hex(suspect->commit->object.sha1),
1535 ent->s_lno + 1, ent->lno + 1, ent->num_lines);
1508 - if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
1509 - struct commit_info ci;
1510 - suspect->commit->object.flags |= METAINFO_SHOWN;
1511 - get_commit_info(suspect->commit, &ci, 1);
1512 - printf("author %s\n", ci.author);
1513 - printf("author-mail %s\n", ci.author_mail);
1514 - printf("author-time %lu\n", ci.author_time);
1515 - printf("author-tz %s\n", ci.author_tz);
1516 - printf("committer %s\n", ci.committer);
1517 - printf("committer-mail %s\n", ci.committer_mail);
1518 - printf("committer-time %lu\n", ci.committer_time);
1519 - printf("committer-tz %s\n", ci.committer_tz);
1520 - printf("summary %s\n", ci.summary);
1521 - if (suspect->commit->object.flags & UNINTERESTING)
1522 - printf("boundary\n");
1523 - }
1536 + emit_one_suspect_detail(suspect);
1537 write_filename_info(suspect->path);
1538 maybe_flush_or_die(stdout, "stdout");
1539 }
@@ -1627,24 +1640,8 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
1640 ent->s_lno + 1,
1641 ent->lno + 1,
1642 ent->num_lines);
1630 - if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
1631 - struct commit_info ci;
1632 - suspect->commit->object.flags |= METAINFO_SHOWN;
1633 - get_commit_info(suspect->commit, &ci, 1);
1634 - printf("author %s\n", ci.author);
1635 - printf("author-mail %s\n", ci.author_mail);
1636 - printf("author-time %lu\n", ci.author_time);
1637 - printf("author-tz %s\n", ci.author_tz);
1638 - printf("committer %s\n", ci.committer);
1639 - printf("committer-mail %s\n", ci.committer_mail);
1640 - printf("committer-time %lu\n", ci.committer_time);
1641 - printf("committer-tz %s\n", ci.committer_tz);
1642 - write_filename_info(suspect->path);
1643 - printf("summary %s\n", ci.summary);
1644 - if (suspect->commit->object.flags & UNINTERESTING)
1645 - printf("boundary\n");
1646 - }
1647 - else if (suspect->commit->object.flags & MORE_THAN_ONE_PATH)
1643 + if (emit_one_suspect_detail(suspect) ||
1644 + (suspect->commit->object.flags & MORE_THAN_ONE_PATH))
1645 write_filename_info(suspect->path);
1646
1647 cp = nth_line(sb, ent->lno);