@matheusbsbs / matheus-bagliano / commits / 23a64c9e77
Fork 0

conflict-marker-size: new attribute

This can be specified to set the length of the conflict marker (usually 7) to a non-default value per path. Only the callers of ll_merge() that are aware of the per-path attributes are modified. Signed-off-by: Junio C Hamano <gitster@pobox.com>

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