@matheusbsbs / matheus-bagliano / commits / f01de62e45
Fork 0

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>

Jonathan Nieder committed Mar 20, 2010 at 19:38 UTC f01de62e4591a6acc061eb994d44f7eeef7a0cfd
6 files changed +17 -15
builtin/checkout.c
+1 -1
@@ -149,7 +149,7 @@ static int checkout_merged(int pos, struct checkout *state)
149 read_mmblob(&ours, active_cache[pos+1]->sha1);
150 read_mmblob(&theirs, active_cache[pos+2]->sha1);
151
152 - status = ll_merge(&result_buf, path, &ancestor,
152 + status = ll_merge(&result_buf, path, &ancestor, NULL,
153 &ours, "ours", &theirs, "theirs", 0);
154 free(ancestor.ptr);
155 free(ours.ptr);
ll-merge.c
+11 -9
@@ -15,7 +15,7 @@ struct ll_merge_driver;
15 typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
16 mmbuffer_t *result,
17 const char *path,
18 - mmfile_t *orig,
18 + mmfile_t *orig, const char *orig_name,
19 mmfile_t *src1, const char *name1,
20 mmfile_t *src2, const char *name2,
21 int flag,
@@ -36,7 +36,7 @@ struct ll_merge_driver {
36 static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
37 mmbuffer_t *result,
38 const char *path_unused,
39 - mmfile_t *orig,
39 + mmfile_t *orig, const char *orig_name,
40 mmfile_t *src1, const char *name1,
41 mmfile_t *src2, const char *name2,
42 int flag, int marker_size)
@@ -57,7 +57,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
57 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
58 mmbuffer_t *result,
59 const char *path,
60 - mmfile_t *orig,
60 + mmfile_t *orig, const char *orig_name,
61 mmfile_t *src1, const char *name1,
62 mmfile_t *src2, const char *name2,
63 int flag, int marker_size)
@@ -71,7 +71,8 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
71 path, name1, name2);
72 return ll_binary_merge(drv_unused, result,
73 path,
74 - orig, src1, name1,
74 + orig, orig_name,
75 + src1, name1,
76 src2, name2,
77 flag, marker_size);
78 }
@@ -83,6 +84,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
84 xmp.style = git_xmerge_style;
85 if (marker_size > 0)
86 xmp.marker_size = marker_size;
87 + xmp.ancestor = orig_name;
88 xmp.file1 = name1;
89 xmp.file2 = name2;
90 return xdl_merge(orig, src1, src2, &xmp, result);
@@ -91,7 +93,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
93 static int ll_union_merge(const struct ll_merge_driver *drv_unused,
94 mmbuffer_t *result,
95 const char *path_unused,
94 - mmfile_t *orig,
96 + mmfile_t *orig, const char *orig_name,
97 mmfile_t *src1, const char *name1,
98 mmfile_t *src2, const char *name2,
99 int flag, int marker_size)
@@ -99,7 +101,7 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
101 /* Use union favor */
102 flag = (flag & 1) | (XDL_MERGE_FAVOR_UNION << 1);
103 return ll_xdl_merge(drv_unused, result, path_unused,
102 - orig, src1, NULL, src2, NULL,
104 + orig, NULL, src1, NULL, src2, NULL,
105 flag, marker_size);
106 return 0;
107 }
@@ -130,7 +132,7 @@ static void create_temp(mmfile_t *src, char *path)
132 static int ll_ext_merge(const struct ll_merge_driver *fn,
133 mmbuffer_t *result,
134 const char *path,
133 - mmfile_t *orig,
135 + mmfile_t *orig, const char *orig_name,
136 mmfile_t *src1, const char *name1,
137 mmfile_t *src2, const char *name2,
138 int flag, int marker_size)
@@ -321,7 +323,7 @@ static int git_path_check_merge(const char *path, struct git_attr_check check[2]
323
324 int ll_merge(mmbuffer_t *result_buf,
325 const char *path,
324 - mmfile_t *ancestor,
326 + mmfile_t *ancestor, const char *ancestor_label,
327 mmfile_t *ours, const char *our_label,
328 mmfile_t *theirs, const char *their_label,
329 int flag)
@@ -343,7 +345,7 @@ int ll_merge(mmbuffer_t *result_buf,
345 driver = find_ll_merge_driver(ll_driver_name);
346 if (virtual_ancestor && driver->recursive)
347 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,
349 ours, our_label, theirs, their_label,
350 flag, marker_size);
351 }
ll-merge.h
+1 -1
@@ -7,7 +7,7 @@
7
8 int ll_merge(mmbuffer_t *result_buf,
9 const char *path,
10 - mmfile_t *ancestor,
10 + mmfile_t *ancestor, const char *ancestor_label,
11 mmfile_t *ours, const char *our_label,
12 mmfile_t *theirs, const char *their_label,
13 int flag);
merge-file.c
+1 -1
@@ -30,7 +30,7 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
30 int merge_status;
31 mmbuffer_t res;
32
33 - merge_status = ll_merge(&res, path, base,
33 + merge_status = ll_merge(&res, path, base, NULL,
34 our, ".our", their, ".their", 0);
35 if (merge_status < 0)
36 return NULL;
merge-recursive.c
+1 -1
@@ -640,7 +640,7 @@ static int merge_3way(struct merge_options *o,
640 read_mmblob(&src1, a->sha1);
641 read_mmblob(&src2, b->sha1);
642
643 - merge_status = ll_merge(result_buf, a->path, &orig,
643 + merge_status = ll_merge(result_buf, a->path, &orig, NULL,
644 &src1, name1, &src2, name2,
645 (!!o->call_depth) | (favor << 1));
646
rerere.c
+2 -2
@@ -319,7 +319,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
319 if (!mmfile[i].ptr && !mmfile[i].size)
320 mmfile[i].ptr = xstrdup("");
321 }
322 - ll_merge(&result, path, &mmfile[0],
322 + ll_merge(&result, path, &mmfile[0], NULL,
323 &mmfile[1], "ours",
324 &mmfile[2], "theirs", 0);
325 for (i = 0; i < 3; i++)
@@ -376,7 +376,7 @@ static int merge(const char *name, const char *path)
376 ret = 1;
377 goto out;
378 }
379 - ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
379 + ret = ll_merge(&result, path, &base, NULL, &cur, "", &other, "", 0);
380 if (!ret) {
381 FILE *f = fopen(path, "w");
382 if (!f)