@@ -98,6 +98,28 @@ static void rerere_io_putstr(const char *str, struct rerere_io *io)
9898 ferr_puts (str , io -> output , & io -> wrerror );
9999}
100100
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+
101123static void rerere_io_putmem (const char * mem , size_t sz , struct rerere_io * io )
102124{
103125 if (io -> output )
@@ -115,7 +137,17 @@ static int rerere_file_getline(struct strbuf *sb, struct rerere_io *io_)
115137 return strbuf_getwholeline (sb , io -> input , '\n' );
116138}
117139
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 )
119151{
120152 git_SHA_CTX ctx ;
121153 int hunk_no = 0 ;
@@ -129,30 +161,30 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io)
129161 git_SHA1_Init (& ctx );
130162
131163 while (!io -> getline (& buf , io )) {
132- if (! prefixcmp (buf .buf , "<<<<<<< " )) {
164+ if (is_cmarker (buf .buf , '<' , marker_size , 1 )) {
133165 if (hunk != RR_CONTEXT )
134166 goto bad ;
135167 hunk = RR_SIDE_1 ;
136- } else if (! prefixcmp (buf .buf , "|||||||" ) && isspace ( buf . buf [ 7 ] )) {
168+ } else if (is_cmarker (buf .buf , '|' , marker_size , 0 )) {
137169 if (hunk != RR_SIDE_1 )
138170 goto bad ;
139171 hunk = RR_ORIGINAL ;
140- } else if (! prefixcmp (buf .buf , "=======" ) && isspace ( buf . buf [ 7 ] )) {
172+ } else if (is_cmarker (buf .buf , '=' , marker_size , 0 )) {
141173 if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL )
142174 goto bad ;
143175 hunk = RR_SIDE_2 ;
144- } else if (! prefixcmp (buf .buf , ">>>>>>> " )) {
176+ } else if (is_cmarker (buf .buf , '>' , marker_size , 1 )) {
145177 if (hunk != RR_SIDE_2 )
146178 goto bad ;
147179 if (strbuf_cmp (& one , & two ) > 0 )
148180 strbuf_swap (& one , & two );
149181 hunk_no ++ ;
150182 hunk = RR_CONTEXT ;
151- rerere_io_putstr ( "<<<<<<<\n" , io );
183+ rerere_io_putconflict ( '<' , marker_size , io );
152184 rerere_io_putmem (one .buf , one .len , io );
153- rerere_io_putstr ( "=======\n" , io );
185+ rerere_io_putconflict ( '=' , marker_size , io );
154186 rerere_io_putmem (two .buf , two .len , io );
155- rerere_io_putstr ( ">>>>>>>\n" , io );
187+ rerere_io_putconflict ( '>' , marker_size , io );
156188 if (sha1 ) {
157189 git_SHA1_Update (& ctx , one .buf ? one .buf : "" ,
158190 one .len + 1 );
@@ -189,6 +221,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
189221{
190222 int hunk_no = 0 ;
191223 struct rerere_io_file io ;
224+ int marker_size = 7 ;
192225
193226 memset (& io , 0 , sizeof (io ));
194227 io .io .getline = rerere_file_getline ;
@@ -205,7 +238,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
205238 }
206239 }
207240
208- hunk_no = handle_path (sha1 , (struct rerere_io * )& io );
241+ hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
209242
210243 fclose (io .input );
211244 if (io .io .wrerror )
@@ -255,6 +288,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
255288 struct cache_entry * ce ;
256289 int pos , len , i , hunk_no ;
257290 struct rerere_io_mem io ;
291+ int marker_size = 7 ;
258292
259293 /*
260294 * Reproduce the conflicted merge in-core
@@ -299,7 +333,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
299333 strbuf_init (& io .input , 0 );
300334 strbuf_attach (& io .input , result .ptr , result .size , result .size );
301335
302- hunk_no = handle_path (sha1 , (struct rerere_io * )& io );
336+ hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
303337 strbuf_release (& io .input );
304338 if (io .io .output )
305339 fclose (io .io .output );
0 commit comments