Skip to content

Commit e2cb6a9

Browse files
committed
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 <[email protected]>
1 parent f5800f6 commit e2cb6a9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rerere.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ static int write_rr(struct string_list *rr, int out_fd)
6565
{
6666
int i;
6767
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);
7071
if (!rr->items[i].util)
7172
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)
7777
die("unable to write rerere record");
78+
79+
strbuf_release(&buf);
7880
}
7981
if (commit_lock_file(&write_lock) != 0)
8082
die("unable to write rerere record");

0 commit comments

Comments
 (0)