blob: 14b83620191019e465291d13be023df794ffb645 [file] [log] [blame]
Junio C Hamano525ab632007-12-24 00:36:00 -08001/*
2 * Low level 3-way in-core file merge.
3 *
4 * Copyright (c) 2007 Junio C Hamano
5 */
6
7#include "cache.h"
Brandon Williamsb2141fc2017-06-14 11:07:36 -07008#include "config.h"
Junio C Hamano525ab632007-12-24 00:36:00 -08009#include "attr.h"
10#include "xdiff-interface.h"
11#include "run-command.h"
Junio C Hamano525ab632007-12-24 00:36:00 -080012#include "ll-merge.h"
Junio C Hamanoef45bb12015-06-04 15:10:29 -070013#include "quote.h"
Junio C Hamano525ab632007-12-24 00:36:00 -080014
15struct ll_merge_driver;
16
Elijah Newren35f69672022-02-02 02:37:30 +000017typedef enum ll_merge_result (*ll_merge_fn)(const struct ll_merge_driver *,
Junio C Hamano525ab632007-12-24 00:36:00 -080018 mmbuffer_t *result,
19 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -050020 mmfile_t *orig, const char *orig_name,
Junio C Hamano525ab632007-12-24 00:36:00 -080021 mmfile_t *src1, const char *name1,
22 mmfile_t *src2, const char *name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -050023 const struct ll_merge_options *opts,
Junio C Hamano23a64c92010-01-15 22:37:32 -080024 int marker_size);
Junio C Hamano525ab632007-12-24 00:36:00 -080025
26struct ll_merge_driver {
27 const char *name;
28 const char *description;
29 ll_merge_fn fn;
30 const char *recursive;
31 struct ll_merge_driver *next;
32 char *cmdline;
33};
34
brian m. carlson2c65d902019-09-02 22:39:44 +000035static struct attr_check *merge_attributes;
36static struct attr_check *load_merge_attributes(void)
37{
38 if (!merge_attributes)
39 merge_attributes = attr_check_initl("merge", "conflict-marker-size", NULL);
40 return merge_attributes;
41}
42
43void reset_merge_attributes(void)
44{
45 attr_check_free(merge_attributes);
46 merge_attributes = NULL;
47}
48
Junio C Hamano525ab632007-12-24 00:36:00 -080049/*
50 * Built-in low-levels
51 */
Elijah Newren35f69672022-02-02 02:37:30 +000052static enum ll_merge_result ll_binary_merge(const struct ll_merge_driver *drv_unused,
Junio C Hamano525ab632007-12-24 00:36:00 -080053 mmbuffer_t *result,
Junio C Hamanoe0e20652012-09-12 02:01:52 -070054 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -050055 mmfile_t *orig, const char *orig_name,
Junio C Hamano525ab632007-12-24 00:36:00 -080056 mmfile_t *src1, const char *name1,
57 mmfile_t *src2, const char *name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -050058 const struct ll_merge_options *opts,
59 int marker_size)
Junio C Hamano525ab632007-12-24 00:36:00 -080060{
Elijah Newren35f69672022-02-02 02:37:30 +000061 enum ll_merge_result ret;
Jonathan Nieder712516b2010-08-26 00:49:53 -050062 mmfile_t *stolen;
63 assert(opts);
64
Junio C Hamano525ab632007-12-24 00:36:00 -080065 /*
Junio C Hamanoed345672016-04-14 15:12:15 -070066 * The tentative merge result is the common ancestor for an
67 * internal merge. For the final merge, it is "ours" by
68 * default but -Xours/-Xtheirs can tweak the choice.
Junio C Hamano525ab632007-12-24 00:36:00 -080069 */
Junio C Hamanoa944af12012-09-08 21:27:19 -070070 if (opts->virtual_ancestor) {
71 stolen = orig;
Elijah Newren35f69672022-02-02 02:37:30 +000072 ret = LL_MERGE_OK;
Junio C Hamanoa944af12012-09-08 21:27:19 -070073 } else {
74 switch (opts->variant) {
75 default:
Elijah Newren35f69672022-02-02 02:37:30 +000076 ret = LL_MERGE_BINARY_CONFLICT;
77 stolen = src1;
78 break;
Junio C Hamanoa944af12012-09-08 21:27:19 -070079 case XDL_MERGE_FAVOR_OURS:
Elijah Newren35f69672022-02-02 02:37:30 +000080 ret = LL_MERGE_OK;
Junio C Hamanoa944af12012-09-08 21:27:19 -070081 stolen = src1;
82 break;
83 case XDL_MERGE_FAVOR_THEIRS:
Elijah Newren35f69672022-02-02 02:37:30 +000084 ret = LL_MERGE_OK;
Junio C Hamanoa944af12012-09-08 21:27:19 -070085 stolen = src2;
86 break;
87 }
88 }
Junio C Hamano525ab632007-12-24 00:36:00 -080089
90 result->ptr = stolen->ptr;
91 result->size = stolen->size;
92 stolen->ptr = NULL;
Junio C Hamanoa944af12012-09-08 21:27:19 -070093
Elijah Newren35f69672022-02-02 02:37:30 +000094 return ret;
Junio C Hamano525ab632007-12-24 00:36:00 -080095}
96
Elijah Newren35f69672022-02-02 02:37:30 +000097static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unused,
Junio C Hamano525ab632007-12-24 00:36:00 -080098 mmbuffer_t *result,
Martin Renold606475f2009-07-01 22:18:04 +020099 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -0500100 mmfile_t *orig, const char *orig_name,
Junio C Hamano525ab632007-12-24 00:36:00 -0800101 mmfile_t *src1, const char *name1,
102 mmfile_t *src2, const char *name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500103 const struct ll_merge_options *opts,
104 int marker_size)
Junio C Hamano525ab632007-12-24 00:36:00 -0800105{
Elijah Newren35f69672022-02-02 02:37:30 +0000106 enum ll_merge_result ret;
Junio C Hamano00f8f972010-01-16 21:01:28 -0800107 xmparam_t xmp;
Elijah Newren35f69672022-02-02 02:37:30 +0000108 int status;
Jonathan Nieder712516b2010-08-26 00:49:53 -0500109 assert(opts);
Junio C Hamano525ab632007-12-24 00:36:00 -0800110
Jeff Kingdcd17422015-09-24 19:12:45 -0400111 if (orig->size > MAX_XDIFF_SIZE ||
112 src1->size > MAX_XDIFF_SIZE ||
113 src2->size > MAX_XDIFF_SIZE ||
114 buffer_is_binary(orig->ptr, orig->size) ||
Junio C Hamano525ab632007-12-24 00:36:00 -0800115 buffer_is_binary(src1->ptr, src1->size) ||
116 buffer_is_binary(src2->ptr, src2->size)) {
Junio C Hamano525ab632007-12-24 00:36:00 -0800117 return ll_binary_merge(drv_unused, result,
Martin Renold606475f2009-07-01 22:18:04 +0200118 path,
Jonathan Niederf01de622010-03-20 19:38:58 -0500119 orig, orig_name,
120 src1, name1,
Junio C Hamano525ab632007-12-24 00:36:00 -0800121 src2, name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500122 opts, marker_size);
Junio C Hamano525ab632007-12-24 00:36:00 -0800123 }
124
Junio C Hamano00f8f972010-01-16 21:01:28 -0800125 memset(&xmp, 0, sizeof(xmp));
Bert Wesarg560119b2010-03-01 22:46:26 +0100126 xmp.level = XDL_MERGE_ZEALOUS;
Jonathan Nieder712516b2010-08-26 00:49:53 -0500127 xmp.favor = opts->variant;
Justin Frankel58a1ece2010-08-26 00:50:45 -0500128 xmp.xpp.flags = opts->xdl_opts;
Junio C Hamanoc236bcd2008-08-29 10:59:16 -0700129 if (git_xmerge_style >= 0)
Bert Wesarg560119b2010-03-01 22:46:26 +0100130 xmp.style = git_xmerge_style;
Junio C Hamano23a64c92010-01-15 22:37:32 -0800131 if (marker_size > 0)
132 xmp.marker_size = marker_size;
Jonathan Niederf01de622010-03-20 19:38:58 -0500133 xmp.ancestor = orig_name;
Jonathan Niedera4b5e912010-03-20 19:35:18 -0500134 xmp.file1 = name1;
135 xmp.file2 = name2;
Elijah Newren35f69672022-02-02 02:37:30 +0000136 status = xdl_merge(orig, src1, src2, &xmp, result);
137 ret = (status > 0) ? LL_MERGE_CONFLICT : status;
138 return ret;
Junio C Hamano525ab632007-12-24 00:36:00 -0800139}
140
Elijah Newren35f69672022-02-02 02:37:30 +0000141static enum ll_merge_result ll_union_merge(const struct ll_merge_driver *drv_unused,
Junio C Hamano525ab632007-12-24 00:36:00 -0800142 mmbuffer_t *result,
Jeff King382b6012021-06-10 12:14:12 -0400143 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -0500144 mmfile_t *orig, const char *orig_name,
Junio C Hamano525ab632007-12-24 00:36:00 -0800145 mmfile_t *src1, const char *name1,
146 mmfile_t *src2, const char *name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500147 const struct ll_merge_options *opts,
148 int marker_size)
Junio C Hamano525ab632007-12-24 00:36:00 -0800149{
Bert Wesargcd1d61c2010-03-01 22:46:25 +0100150 /* Use union favor */
Jonathan Nieder712516b2010-08-26 00:49:53 -0500151 struct ll_merge_options o;
152 assert(opts);
153 o = *opts;
154 o.variant = XDL_MERGE_FAVOR_UNION;
Jeff King382b6012021-06-10 12:14:12 -0400155 return ll_xdl_merge(drv_unused, result, path,
Jeff King7f53f782021-06-10 08:58:43 -0400156 orig, orig_name, src1, name1, src2, name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500157 &o, marker_size);
Junio C Hamano525ab632007-12-24 00:36:00 -0800158}
159
160#define LL_BINARY_MERGE 0
161#define LL_TEXT_MERGE 1
162#define LL_UNION_MERGE 2
163static struct ll_merge_driver ll_merge_drv[] = {
164 { "binary", "built-in binary merge", ll_binary_merge },
165 { "text", "built-in 3-way text merge", ll_xdl_merge },
166 { "union", "built-in union merge", ll_union_merge },
167};
168
Jeff King5096d492015-09-24 17:06:08 -0400169static void create_temp(mmfile_t *src, char *path, size_t len)
Junio C Hamano525ab632007-12-24 00:36:00 -0800170{
171 int fd;
172
Jeff King5096d492015-09-24 17:06:08 -0400173 xsnprintf(path, len, ".merge_file_XXXXXX");
Junio C Hamano525ab632007-12-24 00:36:00 -0800174 fd = xmkstemp(path);
Jeff King06f46f22017-09-13 13:16:03 -0400175 if (write_in_full(fd, src->ptr, src->size) < 0)
Thomas Rast0721c312009-06-27 17:58:47 +0200176 die_errno("unable to write temp-file");
Junio C Hamano525ab632007-12-24 00:36:00 -0800177 close(fd);
178}
179
180/*
181 * User defined low-level merge driver support.
182 */
Elijah Newren35f69672022-02-02 02:37:30 +0000183static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
Junio C Hamano525ab632007-12-24 00:36:00 -0800184 mmbuffer_t *result,
185 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -0500186 mmfile_t *orig, const char *orig_name,
Junio C Hamano525ab632007-12-24 00:36:00 -0800187 mmfile_t *src1, const char *name1,
188 mmfile_t *src2, const char *name2,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500189 const struct ll_merge_options *opts,
190 int marker_size)
Junio C Hamano525ab632007-12-24 00:36:00 -0800191{
Junio C Hamano23a64c92010-01-15 22:37:32 -0800192 char temp[4][50];
René Scharfeced621b2008-11-23 00:13:00 +0100193 struct strbuf cmd = STRBUF_INIT;
Junio C Hamanoef45bb12015-06-04 15:10:29 -0700194 struct strbuf_expand_dict_entry dict[6];
195 struct strbuf path_sq = STRBUF_INIT;
Jeff Kingac0ba182009-12-30 05:53:57 -0500196 const char *args[] = { NULL, NULL };
Junio C Hamano525ab632007-12-24 00:36:00 -0800197 int status, fd, i;
198 struct stat st;
Elijah Newren35f69672022-02-02 02:37:30 +0000199 enum ll_merge_result ret;
Jonathan Nieder712516b2010-08-26 00:49:53 -0500200 assert(opts);
Junio C Hamano525ab632007-12-24 00:36:00 -0800201
Junio C Hamanoef45bb12015-06-04 15:10:29 -0700202 sq_quote_buf(&path_sq, path);
Gary V. Vaughan66dbfd52010-05-14 09:31:33 +0000203 dict[0].placeholder = "O"; dict[0].value = temp[0];
204 dict[1].placeholder = "A"; dict[1].value = temp[1];
205 dict[2].placeholder = "B"; dict[2].value = temp[2];
206 dict[3].placeholder = "L"; dict[3].value = temp[3];
Junio C Hamanoef45bb12015-06-04 15:10:29 -0700207 dict[4].placeholder = "P"; dict[4].value = path_sq.buf;
208 dict[5].placeholder = NULL; dict[5].value = NULL;
Gary V. Vaughan66dbfd52010-05-14 09:31:33 +0000209
Junio C Hamanoafe8a902022-05-02 09:50:37 -0700210 if (!fn->cmdline)
Junio C Hamano525ab632007-12-24 00:36:00 -0800211 die("custom merge driver %s lacks command line.", fn->name);
212
213 result->ptr = NULL;
214 result->size = 0;
Jeff King5096d492015-09-24 17:06:08 -0400215 create_temp(orig, temp[0], sizeof(temp[0]));
216 create_temp(src1, temp[1], sizeof(temp[1]));
217 create_temp(src2, temp[2], sizeof(temp[2]));
218 xsnprintf(temp[3], sizeof(temp[3]), "%d", marker_size);
Junio C Hamano525ab632007-12-24 00:36:00 -0800219
René Scharfeced621b2008-11-23 00:13:00 +0100220 strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
Junio C Hamano525ab632007-12-24 00:36:00 -0800221
Jeff Kingac0ba182009-12-30 05:53:57 -0500222 args[0] = cmd.buf;
223 status = run_command_v_opt(args, RUN_USING_SHELL);
Junio C Hamano525ab632007-12-24 00:36:00 -0800224 fd = open(temp[1], O_RDONLY);
225 if (fd < 0)
226 goto bad;
227 if (fstat(fd, &st))
228 goto close_bad;
229 result->size = st.st_size;
Jeff King3733e692016-02-22 17:44:28 -0500230 result->ptr = xmallocz(result->size);
Junio C Hamano525ab632007-12-24 00:36:00 -0800231 if (read_in_full(fd, result->ptr, result->size) != result->size) {
Ævar Arnfjörð Bjarmasone140f7a2017-06-15 23:15:48 +0000232 FREE_AND_NULL(result->ptr);
Junio C Hamano525ab632007-12-24 00:36:00 -0800233 result->size = 0;
234 }
235 close_bad:
236 close(fd);
237 bad:
238 for (i = 0; i < 3; i++)
Alex Riesen691f1a22009-04-29 23:22:56 +0200239 unlink_or_warn(temp[i]);
René Scharfeced621b2008-11-23 00:13:00 +0100240 strbuf_release(&cmd);
Junio C Hamanoef45bb12015-06-04 15:10:29 -0700241 strbuf_release(&path_sq);
Elijah Newren35f69672022-02-02 02:37:30 +0000242 ret = (status > 0) ? LL_MERGE_CONFLICT : status;
243 return ret;
Junio C Hamano525ab632007-12-24 00:36:00 -0800244}
245
246/*
247 * merge.default and merge.driver configuration items
248 */
249static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
250static const char *default_ll_merge;
251
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100252static int read_merge_config(const char *var, const char *value, void *cb)
Junio C Hamano525ab632007-12-24 00:36:00 -0800253{
254 struct ll_merge_driver *fn;
Jeff Kingd731f0a2013-01-23 01:24:23 -0500255 const char *key, *name;
Jeff Kingf5914f42020-04-10 15:44:28 -0400256 size_t namelen;
Junio C Hamano525ab632007-12-24 00:36:00 -0800257
Tanay Abhra6ea358f2014-08-13 18:13:04 +0530258 if (!strcmp(var, "merge.default"))
259 return git_config_string(&default_ll_merge, var, value);
Junio C Hamano525ab632007-12-24 00:36:00 -0800260
261 /*
262 * We are not interested in anything but "merge.<name>.variable";
263 * especially, we do not want to look at variables such as
264 * "merge.summary", "merge.tool", and "merge.verbosity".
265 */
Jeff Kingd731f0a2013-01-23 01:24:23 -0500266 if (parse_config_key(var, "merge", &name, &namelen, &key) < 0 || !name)
Junio C Hamano525ab632007-12-24 00:36:00 -0800267 return 0;
268
269 /*
270 * Find existing one as we might be processing merge.<name>.var2
271 * after seeing merge.<name>.var1.
272 */
Junio C Hamano525ab632007-12-24 00:36:00 -0800273 for (fn = ll_user_merge; fn; fn = fn->next)
274 if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
275 break;
276 if (!fn) {
René Scharfeca56dad2021-03-13 17:17:22 +0100277 CALLOC_ARRAY(fn, 1);
Junio C Hamano525ab632007-12-24 00:36:00 -0800278 fn->name = xmemdupz(name, namelen);
279 fn->fn = ll_ext_merge;
280 *ll_user_merge_tail = fn;
281 ll_user_merge_tail = &(fn->next);
282 }
283
Tanay Abhra6ea358f2014-08-13 18:13:04 +0530284 if (!strcmp("name", key))
285 return git_config_string(&fn->description, var, value);
Junio C Hamano525ab632007-12-24 00:36:00 -0800286
Jeff Kingd731f0a2013-01-23 01:24:23 -0500287 if (!strcmp("driver", key)) {
Junio C Hamano525ab632007-12-24 00:36:00 -0800288 if (!value)
289 return error("%s: lacks value", var);
290 /*
291 * merge.<name>.driver specifies the command line:
292 *
293 * command-line
294 *
295 * The command-line will be interpolated with the following
296 * tokens and is given to the shell:
297 *
298 * %O - temporary file name for the merge base.
299 * %A - temporary file name for our version.
300 * %B - temporary file name for the other branches' version.
Junio C Hamano23a64c92010-01-15 22:37:32 -0800301 * %L - conflict marker length
Junio C Hamanoef45bb12015-06-04 15:10:29 -0700302 * %P - the original path (safely quoted for the shell)
Junio C Hamano525ab632007-12-24 00:36:00 -0800303 *
304 * The external merge driver should write the results in the
305 * file named by %A, and signal that it has done with zero exit
306 * status.
307 */
Jim Meyering90dce512009-06-14 21:47:54 +0200308 fn->cmdline = xstrdup(value);
Junio C Hamano525ab632007-12-24 00:36:00 -0800309 return 0;
310 }
311
Tanay Abhra6ea358f2014-08-13 18:13:04 +0530312 if (!strcmp("recursive", key))
313 return git_config_string(&fn->recursive, var, value);
Junio C Hamano525ab632007-12-24 00:36:00 -0800314
315 return 0;
316}
317
318static void initialize_ll_merge(void)
319{
320 if (ll_user_merge_tail)
321 return;
322 ll_user_merge_tail = &ll_user_merge;
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100323 git_config(read_merge_config, NULL);
Junio C Hamano525ab632007-12-24 00:36:00 -0800324}
325
326static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr)
327{
328 struct ll_merge_driver *fn;
329 const char *name;
330 int i;
331
332 initialize_ll_merge();
333
334 if (ATTR_TRUE(merge_attr))
335 return &ll_merge_drv[LL_TEXT_MERGE];
336 else if (ATTR_FALSE(merge_attr))
337 return &ll_merge_drv[LL_BINARY_MERGE];
338 else if (ATTR_UNSET(merge_attr)) {
339 if (!default_ll_merge)
340 return &ll_merge_drv[LL_TEXT_MERGE];
341 else
342 name = default_ll_merge;
343 }
344 else
345 name = merge_attr;
346
347 for (fn = ll_user_merge; fn; fn = fn->next)
348 if (!strcmp(fn->name, name))
349 return fn;
350
351 for (i = 0; i < ARRAY_SIZE(ll_merge_drv); i++)
352 if (!strcmp(ll_merge_drv[i].name, name))
353 return &ll_merge_drv[i];
354
355 /* default to the 3-way */
356 return &ll_merge_drv[LL_TEXT_MERGE];
357}
358
Nguyễn Thái Ngọc Duy32eaa462018-09-21 17:57:27 +0200359static void normalize_file(mmfile_t *mm, const char *path, struct index_state *istate)
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200360{
361 struct strbuf strbuf = STRBUF_INIT;
Nguyễn Thái Ngọc Duy32eaa462018-09-21 17:57:27 +0200362 if (renormalize_buffer(istate, path, mm->ptr, mm->size, &strbuf)) {
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200363 free(mm->ptr);
364 mm->size = strbuf.len;
365 mm->ptr = strbuf_detach(&strbuf, NULL);
366 }
367}
368
Elijah Newren35f69672022-02-02 02:37:30 +0000369enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
Junio C Hamano525ab632007-12-24 00:36:00 -0800370 const char *path,
Jonathan Niederf01de622010-03-20 19:38:58 -0500371 mmfile_t *ancestor, const char *ancestor_label,
Junio C Hamano525ab632007-12-24 00:36:00 -0800372 mmfile_t *ours, const char *our_label,
373 mmfile_t *theirs, const char *their_label,
Nguyễn Thái Ngọc Duy32eaa462018-09-21 17:57:27 +0200374 struct index_state *istate,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500375 const struct ll_merge_options *opts)
Junio C Hamano525ab632007-12-24 00:36:00 -0800376{
brian m. carlson2c65d902019-09-02 22:39:44 +0000377 struct attr_check *check = load_merge_attributes();
Jonathan Nieder4fb40c22011-01-15 19:08:42 -0600378 static const struct ll_merge_options default_opts;
Junio C Hamano23a64c92010-01-15 22:37:32 -0800379 const char *ll_driver_name = NULL;
380 int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
Junio C Hamano525ab632007-12-24 00:36:00 -0800381 const struct ll_merge_driver *driver;
382
Jonathan Nieder4fb40c22011-01-15 19:08:42 -0600383 if (!opts)
384 opts = &default_opts;
Jonathan Nieder712516b2010-08-26 00:49:53 -0500385
386 if (opts->renormalize) {
Nguyễn Thái Ngọc Duy32eaa462018-09-21 17:57:27 +0200387 normalize_file(ancestor, path, istate);
388 normalize_file(ours, path, istate);
389 normalize_file(theirs, path, istate);
Eyvind Bernhardsenf217f0e2010-07-02 21:20:47 +0200390 }
Junio C Hamano2aef63d2017-01-27 18:01:57 -0800391
Junio C Hamano11877b92018-10-19 13:34:02 +0900392 git_check_attr(istate, path, check);
Torsten Bögershausend64324c2018-09-12 21:32:02 +0200393 ll_driver_name = check->items[0].value;
394 if (check->items[1].value) {
395 marker_size = atoi(check->items[1].value);
396 if (marker_size <= 0)
397 marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
Junio C Hamano23a64c92010-01-15 22:37:32 -0800398 }
Junio C Hamano525ab632007-12-24 00:36:00 -0800399 driver = find_ll_merge_driver(ll_driver_name);
Junio C Hamanod694a172016-04-14 15:35:09 -0700400
401 if (opts->virtual_ancestor) {
402 if (driver->recursive)
403 driver = find_ll_merge_driver(driver->recursive);
Elijah Newrenb2a79422018-11-07 20:40:24 -0800404 }
405 if (opts->extra_marker_size) {
406 marker_size += opts->extra_marker_size;
Junio C Hamanod694a172016-04-14 15:35:09 -0700407 }
Jonathan Niederf01de622010-03-20 19:38:58 -0500408 return driver->fn(driver, result_buf, path, ancestor, ancestor_label,
Junio C Hamano23a64c92010-01-15 22:37:32 -0800409 ours, our_label, theirs, their_label,
Jonathan Nieder712516b2010-08-26 00:49:53 -0500410 opts, marker_size);
Junio C Hamano525ab632007-12-24 00:36:00 -0800411}
Junio C Hamano85885672010-01-16 23:28:46 -0800412
Nguyễn Thái Ngọc Duy32eaa462018-09-21 17:57:27 +0200413int ll_merge_marker_size(struct index_state *istate, const char *path)
Junio C Hamano85885672010-01-16 23:28:46 -0800414{
Junio C Hamano2aef63d2017-01-27 18:01:57 -0800415 static struct attr_check *check;
Junio C Hamano85885672010-01-16 23:28:46 -0800416 int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
417
Junio C Hamano2aef63d2017-01-27 18:01:57 -0800418 if (!check)
419 check = attr_check_initl("conflict-marker-size", NULL);
Junio C Hamano11877b92018-10-19 13:34:02 +0900420 git_check_attr(istate, path, check);
Torsten Bögershausend64324c2018-09-12 21:32:02 +0200421 if (check->items[0].value) {
Junio C Hamano2aef63d2017-01-27 18:01:57 -0800422 marker_size = atoi(check->items[0].value);
Junio C Hamano85885672010-01-16 23:28:46 -0800423 if (marker_size <= 0)
424 marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
425 }
426 return marker_size;
Junio C Hamano525ab632007-12-24 00:36:00 -0800427}