rerere: write out each record of MERGE_RR in one go

Instead of writing the hash for a conflict, a HT, and the path with three separate write_in_full() calls, format them into a single record into a strbuf and write it out in one go. As a more recent "rerere remaining" codepath abuses the .util field of the merge_rr data to store a sentinel token, make sure that codepath does not call into this function (of course, "remaining" is a read-only operation and currently does not call it). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 28, 2015 at 16:28 UTC e2cb6a950b4617edc3d07b372063b624b2b5c420
1 file changed +9 -7
rerere.c
+9 -7
@@ -65,16 +65,18 @@ static int write_rr(struct string_list *rr, int out_fd)
65 {
66 int i;
67 for (i = 0; i < rr->nr; i++) {
68 - const char *path;
69 - int length;
68 + struct strbuf buf = STRBUF_INIT;
69 +
70 + assert(rr->items[i].util != RERERE_RESOLVED);
71 if (!rr->items[i].util)
72 continue;
72 - path = rr->items[i].string;
73 - length = strlen(path) + 1;
74 - if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
75 - write_str_in_full(out_fd, "\t") != 1 ||
76 - write_in_full(out_fd, path, length) != length)
73 + strbuf_addf(&buf, "%s\t%s%c",
74 + (char *)rr->items[i].util,
75 + rr->items[i].string, 0);
76 + if (write_in_full(out_fd, buf.buf, buf.len) != buf.len)
77 die("unable to write rerere record");
78 +
79 + strbuf_release(&buf);
80 }
81 if (commit_lock_file(&write_lock) != 0)
82 die("unable to write rerere record");