Skip to content

Commit 67711cd

Browse files
committed
rerere: drop want_sp parameter from is_cmarker()
As the nature of the conflict marker line determines if there should be a SP and label after it, the caller shouldn't have to pass the parameter redundantly. Signed-off-by: Junio C Hamano <[email protected]>
1 parent a14c7ab commit 67711cd

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

rerere.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,25 @@ static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
148148
return strbuf_getwholeline(sb, io->input, '\n');
149149
}
150150

151-
static int is_cmarker(char *buf, int marker_char, int marker_size, int want_sp)
151+
/*
152+
* Require the exact number of conflict marker letters, no more, no
153+
* less, followed by SP or any whitespace
154+
* (including LF).
155+
*/
156+
static int is_cmarker(char *buf, int marker_char, int marker_size)
152157
{
158+
int want_sp;
159+
160+
/*
161+
* The beginning of our version and the end of their version
162+
* always are labeled like "<<<<< ours" or ">>>>> theirs",
163+
* hence we set want_sp for them. Note that the version from
164+
* the common ancestor in diff3-style output is not always
165+
* labelled (e.g. "||||| common" is often seen but "|||||"
166+
* alone is also valid), so we do not set want_sp.
167+
*/
168+
want_sp = (marker_char == '<') || (marker_char == '>');
169+
153170
while (marker_size--)
154171
if (*buf++ != marker_char)
155172
return 0;
@@ -172,19 +189,19 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
172189
git_SHA1_Init(&ctx);
173190

174191
while (!io->getline(&buf, io)) {
175-
if (is_cmarker(buf.buf, '<', marker_size, 1)) {
192+
if (is_cmarker(buf.buf, '<', marker_size)) {
176193
if (hunk != RR_CONTEXT)
177194
goto bad;
178195
hunk = RR_SIDE_1;
179-
} else if (is_cmarker(buf.buf, '|', marker_size, 0)) {
196+
} else if (is_cmarker(buf.buf, '|', marker_size)) {
180197
if (hunk != RR_SIDE_1)
181198
goto bad;
182199
hunk = RR_ORIGINAL;
183-
} else if (is_cmarker(buf.buf, '=', marker_size, 0)) {
200+
} else if (is_cmarker(buf.buf, '=', marker_size)) {
184201
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
185202
goto bad;
186203
hunk = RR_SIDE_2;
187-
} else if (is_cmarker(buf.buf, '>', marker_size, 1)) {
204+
} else if (is_cmarker(buf.buf, '>', marker_size)) {
188205
if (hunk != RR_SIDE_2)
189206
goto bad;
190207
if (strbuf_cmp(&one, &two) > 0)

0 commit comments

Comments
 (0)