Skip to content

Commit 06dbc1e

Browse files
committed
Merge branch 'jc/conflict-marker-size'
* jc/conflict-marker-size: rerere: honor conflict-marker-size attribute rerere: prepare for customizable conflict marker length conflict-marker-size: new attribute rerere: use ll_merge() instead of using xdl_merge() merge-tree: use ll_merge() not xdl_merge() xdl_merge(): allow passing down marker_size in xmparam_t xdl_merge(): introduce xmparam_t for merge specific parameters git_attr(): fix function signature Conflicts: builtin-merge-file.c ll-merge.c xdiff/xdiff.h xdiff/xmerge.c
2 parents df91d0e + 8588567 commit 06dbc1e

16 files changed

+155
-78
lines changed

archive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ static void setup_archive_check(struct git_attr_check *check)
8787
static struct git_attr *attr_export_subst;
8888

8989
if (!attr_export_ignore) {
90-
attr_export_ignore = git_attr("export-ignore", 13);
91-
attr_export_subst = git_attr("export-subst", 12);
90+
attr_export_ignore = git_attr("export-ignore");
91+
attr_export_subst = git_attr("export-subst");
9292
}
9393
check[0].attr = attr_export_ignore;
9494
check[1].attr = attr_export_subst;

attr.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int invalid_attr_name(const char *name, int namelen)
6565
return 0;
6666
}
6767

68-
struct git_attr *git_attr(const char *name, int len)
68+
static struct git_attr *git_attr_internal(const char *name, int len)
6969
{
7070
unsigned hval = hash_name(name, len);
7171
unsigned pos = hval % HASHSIZE;
@@ -95,6 +95,11 @@ struct git_attr *git_attr(const char *name, int len)
9595
return a;
9696
}
9797

98+
struct git_attr *git_attr(const char *name)
99+
{
100+
return git_attr_internal(name, strlen(name));
101+
}
102+
98103
/*
99104
* .gitattributes file is one line per record, each of which is
100105
*
@@ -162,7 +167,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
162167
else {
163168
e->setto = xmemdupz(equals + 1, ep - equals - 1);
164169
}
165-
e->attr = git_attr(cp, len);
170+
e->attr = git_attr_internal(cp, len);
166171
}
167172
(*num_attr)++;
168173
return ep + strspn(ep, blank);
@@ -221,7 +226,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
221226
sizeof(struct attr_state) * num_attr +
222227
(is_macro ? 0 : namelen + 1));
223228
if (is_macro)
224-
res->u.attr = git_attr(name, namelen);
229+
res->u.attr = git_attr_internal(name, namelen);
225230
else {
226231
res->u.pattern = (char *)&(res->state[num_attr]);
227232
memcpy(res->u.pattern, name, namelen);

attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct git_attr;
88
* Given a string, return the gitattribute object that
99
* corresponds to it.
1010
*/
11-
struct git_attr *git_attr(const char *, int);
11+
struct git_attr *git_attr(const char *);
1212

1313
/* Internal use */
1414
extern const char git_attr__true[];

builtin-check-attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
106106
const char *name;
107107
struct git_attr *a;
108108
name = argv[i];
109-
a = git_attr(name, strlen(name));
109+
a = git_attr(name);
110110
if (!a)
111111
return error("%s: not a valid attribute name", name);
112112
check[i].attr = a;

builtin-merge-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
2525
const char *names[3] = { NULL, NULL, NULL };
2626
mmfile_t mmfs[3];
2727
mmbuffer_t result = {NULL, 0};
28-
xpparam_t xpp = {XDF_NEED_MINIMAL};
28+
xmparam_t xmp = {{XDF_NEED_MINIMAL}};
2929
int ret = 0, i = 0, to_stdout = 0;
3030
int level = XDL_MERGE_ZEALOUS_ALNUM;
3131
int style = 0, quiet = 0;
@@ -73,7 +73,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
7373
}
7474

7575
ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
76-
&xpp, XDL_MERGE_FLAGS(level, style, favor), &result);
76+
&xmp, XDL_MERGE_FLAGS(level, style, favor), &result);
7777

7878
for (i = 0; i < 3; i++)
7979
free(mmfs[i].ptr);

builtin-pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static void setup_delta_attr_check(struct git_attr_check *check)
673673
static struct git_attr *attr_delta;
674674

675675
if (!attr_delta)
676-
attr_delta = git_attr("delta", 5);
676+
attr_delta = git_attr("delta");
677677

678678
check[0].attr = attr_delta;
679679
}

convert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ static void setup_convert_check(struct git_attr_check *check)
378378
static struct git_attr *attr_filter;
379379

380380
if (!attr_crlf) {
381-
attr_crlf = git_attr("crlf", 4);
382-
attr_ident = git_attr("ident", 5);
383-
attr_filter = git_attr("filter", 6);
381+
attr_crlf = git_attr("crlf");
382+
attr_ident = git_attr("ident");
383+
attr_filter = git_attr("filter");
384384
user_convert_tail = &user_convert;
385385
git_config(read_convert_config, NULL);
386386
}

ll-merge.c

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2324
struct 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

354357
int 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
}

ll-merge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ int ll_merge(mmbuffer_t *result_buf,
1212
mmfile_t *theirs, const char *their_label,
1313
int flag);
1414

15+
int ll_merge_marker_size(const char *path);
16+
1517
#endif

merge-file.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22
#include "run-command.h"
33
#include "xdiff-interface.h"
4+
#include "ll-merge.h"
45
#include "blob.h"
56

67
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
@@ -24,16 +25,13 @@ static void free_mmfile(mmfile_t *f)
2425
free(f->ptr);
2526
}
2627

27-
static void *three_way_filemerge(mmfile_t *base, mmfile_t *our, mmfile_t *their, unsigned long *size)
28+
static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our, mmfile_t *their, unsigned long *size)
2829
{
29-
mmbuffer_t res;
30-
xpparam_t xpp;
3130
int merge_status;
31+
mmbuffer_t res;
3232

33-
memset(&xpp, 0, sizeof(xpp));
34-
merge_status = xdl_merge(base, our, ".our", their, ".their",
35-
&xpp, XDL_MERGE_ZEALOUS, &res);
36-
33+
merge_status = ll_merge(&res, path, base,
34+
our, ".our", their, ".their", 0);
3735
if (merge_status < 0)
3836
return NULL;
3937

@@ -75,7 +73,7 @@ static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2)
7573
return xdi_diff(f1, f2, &xpp, &xecfg, &ecb);
7674
}
7775

78-
void *merge_file(struct blob *base, struct blob *our, struct blob *their, unsigned long *size)
76+
void *merge_file(const char *path, struct blob *base, struct blob *our, struct blob *their, unsigned long *size)
7977
{
8078
void *res = NULL;
8179
mmfile_t f1, f2, common;
@@ -108,7 +106,7 @@ void *merge_file(struct blob *base, struct blob *our, struct blob *their, unsign
108106
if (generate_common_file(&common, &f1, &f2) < 0)
109107
goto out_free_f2_f1;
110108
}
111-
res = three_way_filemerge(&common, &f1, &f2, size);
109+
res = three_way_filemerge(path, &common, &f1, &f2, size);
112110
free_mmfile(&common);
113111
out_free_f2_f1:
114112
free_mmfile(&f2);

0 commit comments

Comments
 (0)