@@ -148,8 +148,25 @@ static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
148
148
return strbuf_getwholeline (sb , io -> input , '\n' );
149
149
}
150
150
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 )
152
157
{
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
+
153
170
while (marker_size -- )
154
171
if (* buf ++ != marker_char )
155
172
return 0 ;
@@ -172,19 +189,19 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz
172
189
git_SHA1_Init (& ctx );
173
190
174
191
while (!io -> getline (& buf , io )) {
175
- if (is_cmarker (buf .buf , '<' , marker_size , 1 )) {
192
+ if (is_cmarker (buf .buf , '<' , marker_size )) {
176
193
if (hunk != RR_CONTEXT )
177
194
goto bad ;
178
195
hunk = RR_SIDE_1 ;
179
- } else if (is_cmarker (buf .buf , '|' , marker_size , 0 )) {
196
+ } else if (is_cmarker (buf .buf , '|' , marker_size )) {
180
197
if (hunk != RR_SIDE_1 )
181
198
goto bad ;
182
199
hunk = RR_ORIGINAL ;
183
- } else if (is_cmarker (buf .buf , '=' , marker_size , 0 )) {
200
+ } else if (is_cmarker (buf .buf , '=' , marker_size )) {
184
201
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL )
185
202
goto bad ;
186
203
hunk = RR_SIDE_2 ;
187
- } else if (is_cmarker (buf .buf , '>' , marker_size , 1 )) {
204
+ } else if (is_cmarker (buf .buf , '>' , marker_size )) {
188
205
if (hunk != RR_SIDE_2 )
189
206
goto bad ;
190
207
if (strbuf_cmp (& one , & two ) > 0 )
0 commit comments