@matheusbsbs / matheus-bagliano / commits / 8a161433a0
Fork 0

xdl_merge(): add optional ancestor label to diff3-style output

The ‘git checkout --conflict=diff3’ command can be used to present conflicts hunks including text from the common ancestor: <<<<<<< ours ourside ||||||| original ======= theirside >>>>>>> theirs The added information is helpful for resolving merges by hand, and merge tools can usually grok it because it is very similar to the output from diff3 -m. A subtle change can help more tools to understand the output. ‘diff3’ includes the name of the merge base on the ||||||| line of the output, and some tools misparse the conflict hunks without it. Add a new xmp->ancestor parameter to xdl_merge() for use with conflict style XDL_MERGE_DIFF3 as a label on the ||||||| line for any conflict hunks. If xmp->ancestor is NULL, the output format is unchanged. Thus, this change only provides unexposed plumbing for the new feature; it does not affect the outward behavior of git. Requested-by: Stefan Monnier <monnier@iro.umontreal.ca> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Bert Wesarg <Bert.Wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 20, 2010 at 19:31 UTC 8a161433a0b414d15093e312eb9be99587074309
2 files changed +15 -2
xdiff/xdiff.h
+1
@@ -117,6 +117,7 @@ typedef struct s_xmparam {
117 int level;
118 int favor;
119 int style;
120 + const char *ancestor; /* label for orig */
121 } xmparam_t;
122
123 #define DEFAULT_CONFLICT_MARKER_SIZE 7
xdiff/xmerge.c
+14 -2
@@ -145,11 +145,13 @@ static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
145
146 static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
147 xdfenv_t *xe2, const char *name2,
148 + const char *name3,
149 int size, int i, int style,
150 xdmerge_t *m, char *dest, int marker_size)
151 {
152 int marker1_size = (name1 ? strlen(name1) + 1 : 0);
153 int marker2_size = (name2 ? strlen(name2) + 1 : 0);
154 + int marker3_size = (name3 ? strlen(name3) + 1 : 0);
155 int j;
156
157 if (marker_size <= 0)
@@ -179,10 +181,15 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
181 if (style == XDL_MERGE_DIFF3) {
182 /* Shared preimage */
183 if (!dest) {
182 - size += marker_size + 1;
184 + size += marker_size + 1 + marker3_size;
185 } else {
186 for (j = 0; j < marker_size; j++)
187 dest[size++] = '|';
188 + if (marker3_size) {
189 + dest[size] = ' ';
190 + memcpy(dest + size + 1, name3, marker3_size - 1);
191 + size += marker3_size;
192 + }
193 dest[size++] = '\n';
194 }
195 size += xdl_orig_copy(xe1, m->i0, m->chg0, 1,
@@ -217,6 +224,7 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
224
225 static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
226 xdfenv_t *xe2, const char *name2,
227 + const char *ancestor_name,
228 int favor,
229 xdmerge_t *m, char *dest, int style,
230 int marker_size)
@@ -229,6 +237,7 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
237
238 if (m->mode == 0)
239 size = fill_conflict_hunk(xe1, name1, xe2, name2,
240 + ancestor_name,
241 size, i, style, m, dest,
242 marker_size);
243 else if (m->mode & 3) {
@@ -403,6 +412,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
412 xmparam_t const *xmp, mmbuffer_t *result) {
413 xdmerge_t *changes, *c;
414 xpparam_t const *xpp = &xmp->xpp;
415 + const char *const ancestor_name = xmp->ancestor;
416 int i0, i1, i2, chg0, chg1, chg2;
417 int level = xmp->level;
418 int style = xmp->style;
@@ -540,6 +550,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
550 if (result) {
551 int marker_size = xmp->marker_size;
552 int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
553 + ancestor_name,
554 favor, changes, NULL, style,
555 marker_size);
556 result->ptr = xdl_malloc(size);
@@ -548,7 +559,8 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
559 return -1;
560 }
561 result->size = size;
551 - xdl_fill_merge_buffer(xe1, name1, xe2, name2, favor, changes,
562 + xdl_fill_merge_buffer(xe1, name1, xe2, name2,
563 + ancestor_name, favor, changes,
564 result->ptr, style, marker_size);
565 }
566 return xdl_cleanup_merge(changes);