@@ -98,6 +98,28 @@ static void rerere_io_putstr(const char *str, struct rerere_io *io)
98
98
ferr_puts (str , io -> output , & io -> wrerror );
99
99
}
100
100
101
+ static void rerere_io_putconflict (int ch , int size , struct rerere_io * io )
102
+ {
103
+ char buf [64 ];
104
+
105
+ while (size ) {
106
+ if (size < sizeof (buf ) - 2 ) {
107
+ memset (buf , ch , size );
108
+ buf [size ] = '\n' ;
109
+ buf [size + 1 ] = '\0' ;
110
+ size = 0 ;
111
+ } else {
112
+ int sz = sizeof (buf ) - 1 ;
113
+ if (size <= sz )
114
+ sz -= (sz - size ) + 1 ;
115
+ memset (buf , ch , sz );
116
+ buf [sz ] = '\0' ;
117
+ size -= sz ;
118
+ }
119
+ rerere_io_putstr (buf , io );
120
+ }
121
+ }
122
+
101
123
static void rerere_io_putmem (const char * mem , size_t sz , struct rerere_io * io )
102
124
{
103
125
if (io -> output )
@@ -115,7 +137,17 @@ static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
115
137
return strbuf_getwholeline (sb , io -> input , '\n' );
116
138
}
117
139
118
- static int handle_path (unsigned char * sha1 , struct rerere_io * io )
140
+ static int is_cmarker (char * buf , int marker_char , int marker_size , int want_sp )
141
+ {
142
+ while (marker_size -- )
143
+ if (* buf ++ != marker_char )
144
+ return 0 ;
145
+ if (want_sp && * buf != ' ' )
146
+ return 0 ;
147
+ return isspace (* buf );
148
+ }
149
+
150
+ static int handle_path (unsigned char * sha1 , struct rerere_io * io , int marker_size )
119
151
{
120
152
git_SHA_CTX ctx ;
121
153
int hunk_no = 0 ;
@@ -129,30 +161,30 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io)
129
161
git_SHA1_Init (& ctx );
130
162
131
163
while (!io -> getline (& buf , io )) {
132
- if (! prefixcmp (buf .buf , "<<<<<<< " )) {
164
+ if (is_cmarker (buf .buf , '<' , marker_size , 1 )) {
133
165
if (hunk != RR_CONTEXT )
134
166
goto bad ;
135
167
hunk = RR_SIDE_1 ;
136
- } else if (! prefixcmp (buf .buf , "|||||||" ) && isspace ( buf . buf [ 7 ] )) {
168
+ } else if (is_cmarker (buf .buf , '|' , marker_size , 0 )) {
137
169
if (hunk != RR_SIDE_1 )
138
170
goto bad ;
139
171
hunk = RR_ORIGINAL ;
140
- } else if (! prefixcmp (buf .buf , "=======" ) && isspace ( buf . buf [ 7 ] )) {
172
+ } else if (is_cmarker (buf .buf , '=' , marker_size , 0 )) {
141
173
if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL )
142
174
goto bad ;
143
175
hunk = RR_SIDE_2 ;
144
- } else if (! prefixcmp (buf .buf , ">>>>>>> " )) {
176
+ } else if (is_cmarker (buf .buf , '>' , marker_size , 1 )) {
145
177
if (hunk != RR_SIDE_2 )
146
178
goto bad ;
147
179
if (strbuf_cmp (& one , & two ) > 0 )
148
180
strbuf_swap (& one , & two );
149
181
hunk_no ++ ;
150
182
hunk = RR_CONTEXT ;
151
- rerere_io_putstr ( "<<<<<<<\n" , io );
183
+ rerere_io_putconflict ( '<' , marker_size , io );
152
184
rerere_io_putmem (one .buf , one .len , io );
153
- rerere_io_putstr ( "=======\n" , io );
185
+ rerere_io_putconflict ( '=' , marker_size , io );
154
186
rerere_io_putmem (two .buf , two .len , io );
155
- rerere_io_putstr ( ">>>>>>>\n" , io );
187
+ rerere_io_putconflict ( '>' , marker_size , io );
156
188
if (sha1 ) {
157
189
git_SHA1_Update (& ctx , one .buf ? one .buf : "" ,
158
190
one .len + 1 );
@@ -189,6 +221,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
189
221
{
190
222
int hunk_no = 0 ;
191
223
struct rerere_io_file io ;
224
+ int marker_size = 7 ;
192
225
193
226
memset (& io , 0 , sizeof (io ));
194
227
io .io .getline = rerere_file_getline ;
@@ -205,7 +238,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
205
238
}
206
239
}
207
240
208
- hunk_no = handle_path (sha1 , (struct rerere_io * )& io );
241
+ hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
209
242
210
243
fclose (io .input );
211
244
if (io .io .wrerror )
@@ -255,6 +288,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
255
288
struct cache_entry * ce ;
256
289
int pos , len , i , hunk_no ;
257
290
struct rerere_io_mem io ;
291
+ int marker_size = 7 ;
258
292
259
293
/*
260
294
* Reproduce the conflicted merge in-core
@@ -299,7 +333,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
299
333
strbuf_init (& io .input , 0 );
300
334
strbuf_attach (& io .input , result .ptr , result .size , result .size );
301
335
302
- hunk_no = handle_path (sha1 , (struct rerere_io * )& io );
336
+ hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
303
337
strbuf_release (& io .input );
304
338
if (io .io .output )
305
339
fclose (io .io .output );
0 commit comments