Skip to content

Commit d58ee6d

Browse files
committed
rerere: remove silly 1024-byte line limit
Ever since 658f365 (Make git-rerere a builtin, 2006-12-20) rewrote it, it kept this line-length limit regression, even after we started using strbuf in the same function in 19b358e (Use strbuf API in buitin-rerere.c, 2007-09-06). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8aa3856 commit d58ee6d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

rerere.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ static int handle_file(const char *path,
8787
unsigned char *sha1, const char *output)
8888
{
8989
git_SHA_CTX ctx;
90-
char buf[1024];
9190
int hunk_no = 0;
9291
enum {
9392
RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
9493
} hunk = RR_CONTEXT;
9594
struct strbuf one = STRBUF_INIT, two = STRBUF_INIT;
95+
struct strbuf buf = STRBUF_INIT;
9696
FILE *f = fopen(path, "r");
9797
FILE *out = NULL;
9898
int wrerror = 0;
@@ -111,20 +111,20 @@ static int handle_file(const char *path,
111111
if (sha1)
112112
git_SHA1_Init(&ctx);
113113

114-
while (fgets(buf, sizeof(buf), f)) {
115-
if (!prefixcmp(buf, "<<<<<<< ")) {
114+
while (!strbuf_getwholeline(&buf, f, '\n')) {
115+
if (!prefixcmp(buf.buf, "<<<<<<< ")) {
116116
if (hunk != RR_CONTEXT)
117117
goto bad;
118118
hunk = RR_SIDE_1;
119-
} else if (!prefixcmp(buf, "|||||||") && isspace(buf[7])) {
119+
} else if (!prefixcmp(buf.buf, "|||||||") && isspace(buf.buf[7])) {
120120
if (hunk != RR_SIDE_1)
121121
goto bad;
122122
hunk = RR_ORIGINAL;
123-
} else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
123+
} else if (!prefixcmp(buf.buf, "=======") && isspace(buf.buf[7])) {
124124
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
125125
goto bad;
126126
hunk = RR_SIDE_2;
127-
} else if (!prefixcmp(buf, ">>>>>>> ")) {
127+
} else if (!prefixcmp(buf.buf, ">>>>>>> ")) {
128128
if (hunk != RR_SIDE_2)
129129
goto bad;
130130
if (strbuf_cmp(&one, &two) > 0)
@@ -147,20 +147,21 @@ static int handle_file(const char *path,
147147
strbuf_reset(&one);
148148
strbuf_reset(&two);
149149
} else if (hunk == RR_SIDE_1)
150-
strbuf_addstr(&one, buf);
150+
strbuf_addstr(&one, buf.buf);
151151
else if (hunk == RR_ORIGINAL)
152152
; /* discard */
153153
else if (hunk == RR_SIDE_2)
154-
strbuf_addstr(&two, buf);
154+
strbuf_addstr(&two, buf.buf);
155155
else if (out)
156-
ferr_puts(buf, out, &wrerror);
156+
ferr_puts(buf.buf, out, &wrerror);
157157
continue;
158158
bad:
159159
hunk = 99; /* force error exit */
160160
break;
161161
}
162162
strbuf_release(&one);
163163
strbuf_release(&two);
164+
strbuf_release(&buf);
164165

165166
fclose(f);
166167
if (wrerror)

0 commit comments

Comments
 (0)