@@ -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 flag );
21+ int flag ,
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 flag )
42+ int flag , int marker_size )
4243{
4344 /*
4445 * The tentative merge result is "ours" for the final round,
@@ -59,9 +60,9 @@ 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 flag )
63+ int flag , int marker_size )
6364{
64- xpparam_t xpp ;
65+ xmparam_t xmp ;
6566 int style = 0 ;
6667 int favor = (flag >> 1 ) & 03 ;
6768
@@ -73,16 +74,19 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
7374 return ll_binary_merge (drv_unused , result ,
7475 path ,
7576 orig , src1 , name1 ,
76- src2 , name2 , flag );
77+ src2 , name2 ,
78+ flag , marker_size );
7779 }
7880
79- memset (& xpp , 0 , sizeof (xpp ));
81+ memset (& xmp , 0 , sizeof (xmp ));
8082 if (git_xmerge_style >= 0 )
8183 style = git_xmerge_style ;
84+ if (marker_size > 0 )
85+ xmp .marker_size = marker_size ;
8286 return xdl_merge (orig ,
8387 src1 , name1 ,
8488 src2 , name2 ,
85- & xpp , XDL_MERGE_FLAGS (XDL_MERGE_ZEALOUS , style , favor ),
89+ & xmp , XDL_MERGE_FLAGS (XDL_MERGE_ZEALOUS , style , favor ),
8690 result );
8791}
8892
@@ -92,19 +96,18 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
9296 mmfile_t * orig ,
9397 mmfile_t * src1 , const char * name1 ,
9498 mmfile_t * src2 , const char * name2 ,
95- int flag )
99+ int flag , int marker_size )
96100{
97101 char * src , * dst ;
98102 long size ;
99- const int marker_size = 7 ;
100103 int status , saved_style ;
101104
102105 /* We have to force the RCS "merge" style */
103106 saved_style = git_xmerge_style ;
104107 git_xmerge_style = 0 ;
105108 status = ll_xdl_merge (drv_unused , result , path_unused ,
106109 orig , src1 , NULL , src2 , NULL ,
107- flag );
110+ flag , marker_size );
108111 git_xmerge_style = saved_style ;
109112 if (status <= 0 )
110113 return status ;
@@ -165,14 +168,15 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
165168 mmfile_t * orig ,
166169 mmfile_t * src1 , const char * name1 ,
167170 mmfile_t * src2 , const char * name2 ,
168- int flag )
171+ int flag , int marker_size )
169172{
170- char temp [3 ][50 ];
173+ char temp [4 ][50 ];
171174 struct strbuf cmd = STRBUF_INIT ;
172175 struct strbuf_expand_dict_entry dict [] = {
173176 { "O" , temp [0 ] },
174177 { "A" , temp [1 ] },
175178 { "B" , temp [2 ] },
179+ { "L" , temp [3 ] },
176180 { NULL }
177181 };
178182 const char * args [] = { NULL , NULL };
@@ -187,6 +191,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
187191 create_temp (orig , temp [0 ]);
188192 create_temp (src1 , temp [1 ]);
189193 create_temp (src2 , temp [2 ]);
194+ sprintf (temp [3 ], "%d" , marker_size );
190195
191196 strbuf_expand (& cmd , fn -> cmdline , strbuf_expand_dict_cb , & dict );
192197
@@ -279,6 +284,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
279284 * %O - temporary file name for the merge base.
280285 * %A - temporary file name for our version.
281286 * %B - temporary file name for the other branches' version.
287+ * %L - conflict marker length
282288 *
283289 * The external merge driver should write the results in the
284290 * file named by %A, and signal that it has done with zero exit
@@ -339,16 +345,13 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
339345 return & ll_merge_drv [LL_TEXT_MERGE ];
340346}
341347
342- static const char * git_path_check_merge (const char * path )
348+ static int git_path_check_merge (const char * path , struct git_attr_check check [ 2 ] )
343349{
344- static struct git_attr_check attr_merge_check ;
345-
346- if (!attr_merge_check .attr )
347- attr_merge_check .attr = git_attr ("merge" , 5 );
348-
349- if (git_checkattr (path , 1 , & attr_merge_check ))
350- return NULL ;
351- return attr_merge_check .value ;
350+ if (!check [0 ].attr ) {
351+ check [0 ].attr = git_attr ("merge" );
352+ check [1 ].attr = git_attr ("conflict-marker-size" );
353+ }
354+ return git_checkattr (path , 2 , check );
352355}
353356
354357int ll_merge (mmbuffer_t * result_buf ,
@@ -358,17 +361,39 @@ int ll_merge(mmbuffer_t *result_buf,
358361 mmfile_t * theirs , const char * their_label ,
359362 int flag )
360363{
361- const char * ll_driver_name ;
364+ static struct git_attr_check check [2 ];
365+ const char * ll_driver_name = NULL ;
366+ int marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
362367 const struct ll_merge_driver * driver ;
363368 int virtual_ancestor = flag & 01 ;
364369
365- ll_driver_name = git_path_check_merge (path );
370+ if (!git_path_check_merge (path , check )) {
371+ ll_driver_name = check [0 ].value ;
372+ if (check [1 ].value ) {
373+ marker_size = atoi (check [1 ].value );
374+ if (marker_size <= 0 )
375+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
376+ }
377+ }
366378 driver = find_ll_merge_driver (ll_driver_name );
367-
368379 if (virtual_ancestor && driver -> recursive )
369380 driver = find_ll_merge_driver (driver -> recursive );
370- return driver -> fn (driver , result_buf , path ,
371- ancestor ,
372- ours , our_label ,
373- theirs , their_label , flag );
381+ return driver -> fn (driver , result_buf , path , ancestor ,
382+ ours , our_label , theirs , their_label ,
383+ flag , marker_size );
384+ }
385+
386+ int ll_merge_marker_size (const char * path )
387+ {
388+ static struct git_attr_check check ;
389+ int marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
390+
391+ if (!check .attr )
392+ check .attr = git_attr ("conflict-marker-size" );
393+ if (!git_checkattr (path , 1 , & check ) && check .value ) {
394+ marker_size = atoi (check .value );
395+ if (marker_size <= 0 )
396+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE ;
397+ }
398+ return marker_size ;
374399}
0 commit comments