Skip to content

Commit e86226e

Browse files
peffgitster
authored andcommitted
blame: refactor porcelain output
This is in preparation for adding more porcelain output options. The three changes are: 1. emit_porcelain now receives the format option flags 2. emit_one_suspect_detail takes an optional "repeat" parameter to suppress the "show only once" behavior 3. The code for emitting porcelain suspect is factored into its own function for repeatability. There should be no functional changes. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 838466b commit e86226e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

builtin/blame.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,13 +1484,14 @@ static void write_filename_info(const char *path)
14841484
/*
14851485
* Porcelain/Incremental format wants to show a lot of details per
14861486
* commit. Instead of repeating this every line, emit it only once,
1487-
* the first time each commit appears in the output.
1487+
* the first time each commit appears in the output (unless the
1488+
* user has specifically asked for us to repeat).
14881489
*/
1489-
static int emit_one_suspect_detail(struct origin *suspect)
1490+
static int emit_one_suspect_detail(struct origin *suspect, int repeat)
14901491
{
14911492
struct commit_info ci;
14921493

1493-
if (suspect->commit->object.flags & METAINFO_SHOWN)
1494+
if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN))
14941495
return 0;
14951496

14961497
suspect->commit->object.flags |= METAINFO_SHOWN;
@@ -1529,7 +1530,7 @@ static void found_guilty_entry(struct blame_entry *ent)
15291530
printf("%s %d %d %d\n",
15301531
sha1_to_hex(suspect->commit->object.sha1),
15311532
ent->s_lno + 1, ent->lno + 1, ent->num_lines);
1532-
emit_one_suspect_detail(suspect);
1533+
emit_one_suspect_detail(suspect, 0);
15331534
write_filename_info(suspect->path);
15341535
maybe_flush_or_die(stdout, "stdout");
15351536
}
@@ -1619,7 +1620,15 @@ static const char *format_time(unsigned long time, const char *tz_str,
16191620
#define OUTPUT_NO_AUTHOR 0200
16201621
#define OUTPUT_SHOW_EMAIL 0400
16211622

1622-
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
1623+
static void emit_porcelain_details(struct origin *suspect, int repeat)
1624+
{
1625+
if (emit_one_suspect_detail(suspect, repeat) ||
1626+
(suspect->commit->object.flags & MORE_THAN_ONE_PATH))
1627+
write_filename_info(suspect->path);
1628+
}
1629+
1630+
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
1631+
int opt)
16231632
{
16241633
int cnt;
16251634
const char *cp;
@@ -1633,9 +1642,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
16331642
ent->s_lno + 1,
16341643
ent->lno + 1,
16351644
ent->num_lines);
1636-
if (emit_one_suspect_detail(suspect) ||
1637-
(suspect->commit->object.flags & MORE_THAN_ONE_PATH))
1638-
write_filename_info(suspect->path);
1645+
emit_porcelain_details(suspect, 0);
16391646

16401647
cp = nth_line(sb, ent->lno);
16411648
for (cnt = 0; cnt < ent->num_lines; cnt++) {
@@ -1756,7 +1763,7 @@ static void output(struct scoreboard *sb, int option)
17561763

17571764
for (ent = sb->ent; ent; ent = ent->next) {
17581765
if (option & OUTPUT_PORCELAIN)
1759-
emit_porcelain(sb, ent);
1766+
emit_porcelain(sb, ent, option);
17601767
else {
17611768
emit_other(sb, ent, option);
17621769
}

0 commit comments

Comments
 (0)