Skip to content

Commit f01de62

Browse files
jrngitster
authored andcommitted
ll_merge(): add ancestor label parameter for diff3-style output
Commands using the ll_merge() function will present conflict hunks imitating ‘diff3 -m’ output if the merge.conflictstyle configuration option is set appropriately. Unlike ‘diff3 -m’, the output does not include a label for the merge base on the ||||||| line of the output, and some tools misparse the conflict hunks without that. Add a new ancestor_label parameter to ll_merge() to give callers the power to rectify this situation. If ancestor_label is NULL, the output format is unchanged. All callers pass NULL for now. Requested-by: Stefan Monnier <monnier@iro.umontreal.ca> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4bb0936 commit f01de62

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int checkout_merged(int pos, struct checkout *state)
149149
read_mmblob(&ours, active_cache[pos+1]->sha1);
150150
read_mmblob(&theirs, active_cache[pos+2]->sha1);
151151

152-
status = ll_merge(&result_buf, path, &ancestor,
152+
status = ll_merge(&result_buf, path, &ancestor, NULL,
153153
&ours, "ours", &theirs, "theirs", 0);
154154
free(ancestor.ptr);
155155
free(ours.ptr);

ll-merge.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct ll_merge_driver;
1515
typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
1616
mmbuffer_t *result,
1717
const char *path,
18-
mmfile_t *orig,
18+
mmfile_t *orig, const char *orig_name,
1919
mmfile_t *src1, const char *name1,
2020
mmfile_t *src2, const char *name2,
2121
int flag,
@@ -36,7 +36,7 @@ struct ll_merge_driver {
3636
static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
3737
mmbuffer_t *result,
3838
const char *path_unused,
39-
mmfile_t *orig,
39+
mmfile_t *orig, const char *orig_name,
4040
mmfile_t *src1, const char *name1,
4141
mmfile_t *src2, const char *name2,
4242
int flag, int marker_size)
@@ -57,7 +57,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
5757
static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
5858
mmbuffer_t *result,
5959
const char *path,
60-
mmfile_t *orig,
60+
mmfile_t *orig, const char *orig_name,
6161
mmfile_t *src1, const char *name1,
6262
mmfile_t *src2, const char *name2,
6363
int flag, int marker_size)
@@ -71,7 +71,8 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
7171
path, name1, name2);
7272
return ll_binary_merge(drv_unused, result,
7373
path,
74-
orig, src1, name1,
74+
orig, orig_name,
75+
src1, name1,
7576
src2, name2,
7677
flag, marker_size);
7778
}
@@ -83,6 +84,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
8384
xmp.style = git_xmerge_style;
8485
if (marker_size > 0)
8586
xmp.marker_size = marker_size;
87+
xmp.ancestor = orig_name;
8688
xmp.file1 = name1;
8789
xmp.file2 = name2;
8890
return xdl_merge(orig, src1, src2, &xmp, result);
@@ -91,15 +93,15 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
9193
static int ll_union_merge(const struct ll_merge_driver *drv_unused,
9294
mmbuffer_t *result,
9395
const char *path_unused,
94-
mmfile_t *orig,
96+
mmfile_t *orig, const char *orig_name,
9597
mmfile_t *src1, const char *name1,
9698
mmfile_t *src2, const char *name2,
9799
int flag, int marker_size)
98100
{
99101
/* Use union favor */
100102
flag = (flag & 1) | (XDL_MERGE_FAVOR_UNION << 1);
101103
return ll_xdl_merge(drv_unused, result, path_unused,
102-
orig, src1, NULL, src2, NULL,
104+
orig, NULL, src1, NULL, src2, NULL,
103105
flag, marker_size);
104106
return 0;
105107
}
@@ -130,7 +132,7 @@ static void create_temp(mmfile_t *src, char *path)
130132
static int ll_ext_merge(const struct ll_merge_driver *fn,
131133
mmbuffer_t *result,
132134
const char *path,
133-
mmfile_t *orig,
135+
mmfile_t *orig, const char *orig_name,
134136
mmfile_t *src1, const char *name1,
135137
mmfile_t *src2, const char *name2,
136138
int flag, int marker_size)
@@ -321,7 +323,7 @@ static int git_path_check_merge(const char *path, struct git_attr_check check[2]
321323

322324
int ll_merge(mmbuffer_t *result_buf,
323325
const char *path,
324-
mmfile_t *ancestor,
326+
mmfile_t *ancestor, const char *ancestor_label,
325327
mmfile_t *ours, const char *our_label,
326328
mmfile_t *theirs, const char *their_label,
327329
int flag)
@@ -343,7 +345,7 @@ int ll_merge(mmbuffer_t *result_buf,
343345
driver = find_ll_merge_driver(ll_driver_name);
344346
if (virtual_ancestor && driver->recursive)
345347
driver = find_ll_merge_driver(driver->recursive);
346-
return driver->fn(driver, result_buf, path, ancestor,
348+
return driver->fn(driver, result_buf, path, ancestor, ancestor_label,
347349
ours, our_label, theirs, their_label,
348350
flag, marker_size);
349351
}

ll-merge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
int ll_merge(mmbuffer_t *result_buf,
99
const char *path,
10-
mmfile_t *ancestor,
10+
mmfile_t *ancestor, const char *ancestor_label,
1111
mmfile_t *ours, const char *our_label,
1212
mmfile_t *theirs, const char *their_label,
1313
int flag);

merge-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
3030
int merge_status;
3131
mmbuffer_t res;
3232

33-
merge_status = ll_merge(&res, path, base,
33+
merge_status = ll_merge(&res, path, base, NULL,
3434
our, ".our", their, ".their", 0);
3535
if (merge_status < 0)
3636
return NULL;

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static int merge_3way(struct merge_options *o,
640640
read_mmblob(&src1, a->sha1);
641641
read_mmblob(&src2, b->sha1);
642642

643-
merge_status = ll_merge(result_buf, a->path, &orig,
643+
merge_status = ll_merge(result_buf, a->path, &orig, NULL,
644644
&src1, name1, &src2, name2,
645645
(!!o->call_depth) | (favor << 1));
646646

rerere.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
319319
if (!mmfile[i].ptr && !mmfile[i].size)
320320
mmfile[i].ptr = xstrdup("");
321321
}
322-
ll_merge(&result, path, &mmfile[0],
322+
ll_merge(&result, path, &mmfile[0], NULL,
323323
&mmfile[1], "ours",
324324
&mmfile[2], "theirs", 0);
325325
for (i = 0; i < 3; i++)
@@ -376,7 +376,7 @@ static int merge(const char *name, const char *path)
376376
ret = 1;
377377
goto out;
378378
}
379-
ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
379+
ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", 0);
380380
if (!ret) {
381381
FILE *f = fopen(path, "w");
382382
if (!f)

0 commit comments

Comments
 (0)