@@ -18,7 +18,8 @@ typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
18
18
mmfile_t * orig ,
19
19
mmfile_t * src1 , const char * name1 ,
20
20
mmfile_t * src2 , const char * name2 ,
21
- int virtual_ancestor );
21
+ int virtual_ancestor ,
22
+ int marker_size );
22
23
23
24
struct ll_merge_driver {
24
25
const char * name ;
@@ -38,7 +39,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
38
39
mmfile_t * orig ,
39
40
mmfile_t * src1 , const char * name1 ,
40
41
mmfile_t * src2 , const char * name2 ,
41
- int virtual_ancestor )
42
+ int virtual_ancestor , int marker_size )
42
43
{
43
44
/*
44
45
* 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,
59
60
mmfile_t * orig ,
60
61
mmfile_t * src1 , const char * name1 ,
61
62
mmfile_t * src2 , const char * name2 ,
62
- int virtual_ancestor )
63
+ int virtual_ancestor , int marker_size )
63
64
{
64
65
xmparam_t xmp ;
65
66
int style = 0 ;
@@ -73,12 +74,14 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
73
74
path ,
74
75
orig , src1 , name1 ,
75
76
src2 , name2 ,
76
- virtual_ancestor );
77
+ virtual_ancestor , marker_size );
77
78
}
78
79
79
80
memset (& xmp , 0 , sizeof (xmp ));
80
81
if (git_xmerge_style >= 0 )
81
82
style = git_xmerge_style ;
83
+ if (marker_size > 0 )
84
+ xmp .marker_size = marker_size ;
82
85
return xdl_merge (orig ,
83
86
src1 , name1 ,
84
87
src2 , name2 ,
@@ -92,19 +95,18 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
92
95
mmfile_t * orig ,
93
96
mmfile_t * src1 , const char * name1 ,
94
97
mmfile_t * src2 , const char * name2 ,
95
- int virtual_ancestor )
98
+ int virtual_ancestor , int marker_size )
96
99
{
97
100
char * src , * dst ;
98
101
long size ;
99
- const int marker_size = 7 ;
100
102
int status , saved_style ;
101
103
102
104
/* We have to force the RCS "merge" style */
103
105
saved_style = git_xmerge_style ;
104
106
git_xmerge_style = 0 ;
105
107
status = ll_xdl_merge (drv_unused , result , path_unused ,
106
108
orig , src1 , NULL , src2 , NULL ,
107
- virtual_ancestor );
109
+ virtual_ancestor , marker_size );
108
110
git_xmerge_style = saved_style ;
109
111
if (status <= 0 )
110
112
return status ;
@@ -165,14 +167,15 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
165
167
mmfile_t * orig ,
166
168
mmfile_t * src1 , const char * name1 ,
167
169
mmfile_t * src2 , const char * name2 ,
168
- int virtual_ancestor )
170
+ int virtual_ancestor , int marker_size )
169
171
{
170
- char temp [3 ][50 ];
172
+ char temp [4 ][50 ];
171
173
struct strbuf cmd = STRBUF_INIT ;
172
174
struct strbuf_expand_dict_entry dict [] = {
173
175
{ "O" , temp [0 ] },
174
176
{ "A" , temp [1 ] },
175
177
{ "B" , temp [2 ] },
178
+ { "L" , temp [3 ] },
176
179
{ NULL }
177
180
};
178
181
const char * args [] = { "sh" , "-c" , NULL , NULL };
@@ -187,6 +190,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
187
190
create_temp (orig , temp [0 ]);
188
191
create_temp (src1 , temp [1 ]);
189
192
create_temp (src2 , temp [2 ]);
193
+ sprintf (temp [3 ], "%d" , marker_size );
190
194
191
195
strbuf_expand (& cmd , fn -> cmdline , strbuf_expand_dict_cb , & dict );
192
196
@@ -279,6 +283,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
279
283
* %O - temporary file name for the merge base.
280
284
* %A - temporary file name for our version.
281
285
* %B - temporary file name for the other branches' version.
286
+ * %L - conflict marker length
282
287
*
283
288
* The external merge driver should write the results in the
284
289
* 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
339
344
return & ll_merge_drv [LL_TEXT_MERGE ];
340
345
}
341
346
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 ] )
343
348
{
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 );
352
354
}
353
355
354
356
int ll_merge (mmbuffer_t * result_buf ,
@@ -358,16 +360,23 @@ int ll_merge(mmbuffer_t *result_buf,
358
360
mmfile_t * theirs , const char * their_label ,
359
361
int virtual_ancestor )
360
362
{
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 ;
362
366
const struct ll_merge_driver * driver ;
363
367
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
+ }
365
376
driver = find_ll_merge_driver (ll_driver_name );
366
-
367
377
if (virtual_ancestor && driver -> recursive )
368
378
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 );
373
382
}
0 commit comments