rerere: lift PATH_MAX limitation
The MERGE_RR file records a collection of NUL-terminated entries, each of which consists of - a hash that identifies the conflict - a HT - the pathname We used to read this piece-by-piece, and worse yet, read the pathname part a byte at a time into a fixed buffer of size PATH_MAX. Instead, read a whole entry using strbuf_getwholeline() and parse out the fields. This way, we issue fewer read(2) calls and more importantly we do not have to limit the pathname to PATH_MAX. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
8d9b5a4ada
commit
f5800f6ad8
35
rerere.c
35
rerere.c
@ -35,32 +35,27 @@ static int has_rerere_resolution(const char *hex)
|
|||||||
|
|
||||||
static void read_rr(struct string_list *rr)
|
static void read_rr(struct string_list *rr)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
struct strbuf buf = STRBUF_INIT;
|
||||||
char buf[PATH_MAX];
|
|
||||||
FILE *in = fopen(merge_rr_path, "r");
|
FILE *in = fopen(merge_rr_path, "r");
|
||||||
|
|
||||||
if (!in)
|
if (!in)
|
||||||
return;
|
return;
|
||||||
while (fread(buf, 40, 1, in) == 1) {
|
while (!strbuf_getwholeline(&buf, in, '\0')) {
|
||||||
int i;
|
char *path;
|
||||||
char *name;
|
unsigned char sha1[20];
|
||||||
if (get_sha1_hex(buf, sha1))
|
|
||||||
|
/* There has to be the hash, tab, path and then NUL */
|
||||||
|
if (buf.len < 42 || get_sha1_hex(buf.buf, sha1))
|
||||||
die("corrupt MERGE_RR");
|
die("corrupt MERGE_RR");
|
||||||
buf[40] = '\0';
|
|
||||||
name = xstrdup(buf);
|
if (buf.buf[40] != '\t')
|
||||||
if (fgetc(in) != '\t')
|
|
||||||
die("corrupt MERGE_RR");
|
die("corrupt MERGE_RR");
|
||||||
for (i = 0; i < sizeof(buf); i++) {
|
buf.buf[40] = '\0';
|
||||||
int c = fgetc(in);
|
path = buf.buf + 41;
|
||||||
if (c < 0)
|
|
||||||
die("corrupt MERGE_RR");
|
string_list_insert(rr, path)->util = xstrdup(buf.buf);
|
||||||
buf[i] = c;
|
|
||||||
if (c == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == sizeof(buf))
|
|
||||||
die("filename too long");
|
|
||||||
string_list_insert(rr, buf)->util = name;
|
|
||||||
}
|
}
|
||||||
|
strbuf_release(&buf);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user