@@ -18,7 +18,8 @@ typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
1818 mmfile_t * orig ,
1919 mmfile_t * src1 , const char * name1 ,
2020 mmfile_t * src2 , const char * name2 ,
21- int virtual_ancestor );
21+ int virtual_ancestor ,
22+ int marker_size );
2223
2324struct ll_merge_driver {
2425 const char * name ;
@@ -38,7 +39,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
3839 mmfile_t * orig ,
3940 mmfile_t * src1 , const char * name1 ,
4041 mmfile_t * src2 , const char * name2 ,
41- int virtual_ancestor )
42+ int virtual_ancestor , int marker_size )
4243{
4344 /*
4445 * The tentative merge result is "ours" for the final round,
@@ -59,7 +60,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
5960 mmfile_t * orig ,
6061 mmfile_t * src1 , const char * name1 ,
6162 mmfile_t * src2 , const char * name2 ,
62- int virtual_ancestor )
63+ int virtual_ancestor , int marker_size )
6364{
6465 xmparam_t xmp ;
6566 int style = 0 ;
@@ -73,12 +74,14 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
7374 path ,
7475 orig , src1 , name1 ,
7576 src2 , name2 ,
76- virtual_ancestor );
77+ virtual_ancestor , marker_size );
7778 }
7879
7980 memset (& xmp , 0 , sizeof (xmp ));
8081 if (git_xmerge_style >= 0 )
8182 style = git_xmerge_style ;
83+ if (marker_size > 0 )
84+ xmp .marker_size = marker_size ;
8285 return xdl_merge (orig ,
8386 src1 , name1 ,
8487 src2 , name2 ,
@@ -92,19 +95,18 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
9295 mmfile_t * orig ,
9396 mmfile_t * src1 , const char * name1 ,
9497 mmfile_t * src2 , const char * name2 ,
95- int virtual_ancestor )
98+ int virtual_ancestor , int marker_size )
9699{
97100 char * src , * dst ;
98101 long size ;
99- const int marker_size = 7 ;
100102 int status , saved_style ;
101103
102104 /* We have to force the RCS "merge" style */
103105 saved_style = git_xmerge_style ;
104106 git_xmerge_style = 0 ;
105107 status = ll_xdl_merge (drv_unused , result , path_unused ,
106108 orig , src1 , NULL , src2 , NULL ,
107- virtual_ancestor );
109+ virtual_ancestor , marker_size );
108110 git_xmerge_style = saved_style ;
109111 if (status <= 0 )
110112 return status ;
@@ -165,14 +167,15 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
165167 mmfile_t * orig ,
166168 mmfile_t * src1 , const char * name1 ,
167169 mmfile_t * src2 , const char * name2 ,
168- int virtual_ancestor )
170+ int virtual_ancestor , int marker_size )
169171{
170- char temp [3 ][50 ];
172+ char temp [4 ][50 ];
171173 struct strbuf cmd = STRBUF_INIT ;
172174 struct strbuf_expand_dict_entry dict [] = {
173175 { "O" , temp [0 ] },
174176 { "A" , temp [1 ] },
175177 { "B" , temp [2 ] },
178+ { "L" , temp [3 ] },
176179 { NULL }
177180 };
178181 const char * args [] = { "sh" , "-c" , NULL , NULL };
@@ -187,6 +190,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
187190 create_temp (orig , temp [0 ]);
188191 create_temp (src1 , temp [1 ]);
189192 create_temp (src2 , temp [2 ]);
193+ sprintf (temp [3 ], "%d" , marker_size );
190194
191195 strbuf_expand (& cmd , fn -> cmdline , strbuf_expand_dict_cb , & dict );
192196
@@ -279,6 +283,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
279283 * %O - temporary file name for the merge base.
280284 * %A - temporary file name for our version.
281285 * %B - temporary file name for the other branches' version.
286+ * %L - conflict marker length
282287 *
283288 * The external merge driver should write the results in the
284289 * file named by %A, and signal that it has done with zero exit
@@ -339,16 +344,13 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
339344 return & ll_merge_drv [LL_TEXT_MERGE ];
340345}
341346
342- static const char * git_path_check_merge (const char * path )
347+ static int git_path_check_merge (const char * path , struct git_attr_check check [ 2 ] )
343348{
344- static struct git_attr_check attr_merge_check ;
345-
346- if (!attr_merge_check .attr )
347- attr_merge_check .attr = git_attr ("merge" );
348-
349- if (git_checkattr (path , 1 , & attr_merge_check ))
350- return NULL ;
351- return attr_merge_check .value ;
349+ if (!check [0 ].attr ) {
350+ check [0 ].attr = git_attr ("merge" );
351+ check [1 ].attr = git_attr ("conflict-marker-size" );
352+ }
353+ return git_checkattr (path , 2 , check );
352354}
353355
354356int ll_merge (mmbuffer_t * result_buf ,
@@ -358,16 +360,23 @@ int ll_merge(mmbuffer_t *result_buf,
358360 mmfile_t * theirs , const char * their_label ,
359361 int virtual_ancestor )
360362{
361- const char * ll_driver_name ;
363+ static struct git_attr_check check [2 ];
364+ const char * ll_driver_name = NULL ;
365+ int marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
362366 const struct ll_merge_driver * driver ;
363367
364- ll_driver_name = git_path_check_merge (path );
368+ if (!git_path_check_merge (path , check )) {
369+ ll_driver_name = check [0 ].value ;
370+ if (check [1 ].value ) {
371+ marker_size = atoi (check [1 ].value );
372+ if (marker_size <= 0 )
373+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
374+ }
375+ }
365376 driver = find_ll_merge_driver (ll_driver_name );
366-
367377 if (virtual_ancestor && driver -> recursive )
368378 driver = find_ll_merge_driver (driver -> recursive );
369- return driver -> fn (driver , result_buf , path ,
370- ancestor ,
371- ours , our_label ,
372- theirs , their_label , virtual_ancestor );
379+ return driver -> fn (driver , result_buf , path , ancestor ,
380+ ours , our_label , theirs , their_label ,
381+ virtual_ancestor , marker_size );
373382}
0 commit comments