@matheusbsbs / matheus-bagliano / commits / d58ee6dbf6
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Dec 25, 2009 at 13:55 UTC d58ee6dbf67614ef4854e0d8af8188cd84ae5107
1 file changed +10 -9
rerere.c
+10 -9
@@ -87,12 +87,12 @@ static int handle_file(const char *path,
87 unsigned char *sha1, const char *output)
88 {
89 git_SHA_CTX ctx;
90 - char buf[1024];
90 int hunk_no = 0;
91 enum {
92 RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
93 } hunk = RR_CONTEXT;
94 struct strbuf one = STRBUF_INIT, two = STRBUF_INIT;
95 + struct strbuf buf = STRBUF_INIT;
96 FILE *f = fopen(path, "r");
97 FILE *out = NULL;
98 int wrerror = 0;
@@ -111,20 +111,20 @@ static int handle_file(const char *path,
111 if (sha1)
112 git_SHA1_Init(&ctx);
113
114 - while (fgets(buf, sizeof(buf), f)) {
115 - if (!prefixcmp(buf, "<<<<<<< ")) {
114 + while (!strbuf_getwholeline(&buf, f, '\n')) {
115 + if (!prefixcmp(buf.buf, "<<<<<<< ")) {
116 if (hunk != RR_CONTEXT)
117 goto bad;
118 hunk = RR_SIDE_1;
119 - } else if (!prefixcmp(buf, "|||||||") && isspace(buf[7])) {
119 + } else if (!prefixcmp(buf.buf, "|||||||") && isspace(buf.buf[7])) {
120 if (hunk != RR_SIDE_1)
121 goto bad;
122 hunk = RR_ORIGINAL;
123 - } else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
123 + } else if (!prefixcmp(buf.buf, "=======") && isspace(buf.buf[7])) {
124 if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
125 goto bad;
126 hunk = RR_SIDE_2;
127 - } else if (!prefixcmp(buf, ">>>>>>> ")) {
127 + } else if (!prefixcmp(buf.buf, ">>>>>>> ")) {
128 if (hunk != RR_SIDE_2)
129 goto bad;
130 if (strbuf_cmp(&one, &two) > 0)
@@ -147,13 +147,13 @@ static int handle_file(const char *path,
147 strbuf_reset(&one);
148 strbuf_reset(&two);
149 } else if (hunk == RR_SIDE_1)
150 - strbuf_addstr(&one, buf);
150 + strbuf_addstr(&one, buf.buf);
151 else if (hunk == RR_ORIGINAL)
152 ; /* discard */
153 else if (hunk == RR_SIDE_2)
154 - strbuf_addstr(&two, buf);
154 + strbuf_addstr(&two, buf.buf);
155 else if (out)
156 - ferr_puts(buf, out, &wrerror);
156 + ferr_puts(buf.buf, out, &wrerror);
157 continue;
158 bad:
159 hunk = 99; /* force error exit */
@@ -161,6 +161,7 @@ static int handle_file(const char *path,
161 }
162 strbuf_release(&one);
163 strbuf_release(&two);
164 + strbuf_release(&buf);
165
166 fclose(f);
167 if (wrerror)