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>
Jeff King committed
May 9, 2011 at 09:34 UTC
e86226e34097ce22ed78a9e759564110f141dda0
1 file changed
+16
-9
builtin/blame.c
+16
-9
@@ -1484,13 +1484,14 @@ static void write_filename_info(const char *path)
1484
/*
1485
* Porcelain/Incremental format wants to show a lot of details per
1486
* 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).
1489
*/
1489
-static int emit_one_suspect_detail(struct origin *suspect)
1490
+static int emit_one_suspect_detail(struct origin *suspect, int repeat)
1491
{
1492
struct commit_info ci;
1493
1493
- if (suspect->commit->object.flags & METAINFO_SHOWN)
1494
+ if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN))
1495
return 0;
1496
1497
suspect->commit->object.flags |= METAINFO_SHOWN;
@@ -1529,7 +1530,7 @@ static void found_guilty_entry(struct blame_entry *ent)
1530
printf("%s %d %d %d\n",
1531
sha1_to_hex(suspect->commit->object.sha1),
1532
ent->s_lno + 1, ent->lno + 1, ent->num_lines);
1532
- emit_one_suspect_detail(suspect);
1533
+ emit_one_suspect_detail(suspect, 0);
1534
write_filename_info(suspect->path);
1535
maybe_flush_or_die(stdout, "stdout");
1536
}
@@ -1619,7 +1620,15 @@ static const char *format_time(unsigned long time, const char *tz_str,
1620
#define OUTPUT_NO_AUTHOR 0200
1621
#define OUTPUT_SHOW_EMAIL 0400
1622
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)
1632
{
1633
int cnt;
1634
const char *cp;
@@ -1633,9 +1642,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
1642
ent->s_lno + 1,
1643
ent->lno + 1,
1644
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);
1646
1647
cp = nth_line(sb, ent->lno);
1648
for (cnt = 0; cnt < ent->num_lines; cnt++) {
@@ -1756,7 +1763,7 @@ static void output(struct scoreboard *sb, int option)
1763
1764
for (ent = sb->ent; ent; ent = ent->next) {
1765
if (option & OUTPUT_PORCELAIN)
1759
- emit_porcelain(sb, ent);
1766
+ emit_porcelain(sb, ent, option);
1767
else {
1768
emit_other(sb, ent, option);
1769
}