Skip to content

Commit 47291da

Browse files
committed
xdiff: add new XDL_MERGE_FAVOR_BASE mode
Similar to XDL_MERGE_FAVOR_{OURS,THEIRS} add a new mode for favoring the base version in the event of a conflict, and add a --base flag to merge-file to allow testing this out. This will be used in a subsequent commit to reduce the prevalence of nested conflict markers in the virtual merge base when using diff3 conflict style, by having the virtual merge base (created by merging the merge bases) favor the version from their merge base (i.e. from the merge base of the merge bases). Signed-off-by: Elijah Newren <[email protected]>
1 parent fbe8d30 commit 47291da

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

builtin/merge-file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ int cmd_merge_file(int argc,
7373
OPT_SET_INT(0, "diff3", &xmp.style, N_("use a diff3 based merge"), XDL_MERGE_DIFF3),
7474
OPT_SET_INT(0, "zdiff3", &xmp.style, N_("use a zealous diff3 based merge"),
7575
XDL_MERGE_ZEALOUS_DIFF3),
76+
OPT_SET_INT(0, "base", &xmp.favor, N_("for conflicts, use base version"),
77+
XDL_MERGE_FAVOR_BASE),
7678
OPT_SET_INT(0, "ours", &xmp.favor, N_("for conflicts, use our version"),
7779
XDL_MERGE_FAVOR_OURS),
7880
OPT_SET_INT(0, "theirs", &xmp.favor, N_("for conflicts, use their version"),

xdiff/xdiff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern "C" {
6363
#define XDL_MERGE_FAVOR_OURS 1
6464
#define XDL_MERGE_FAVOR_THEIRS 2
6565
#define XDL_MERGE_FAVOR_UNION 3
66+
#define XDL_MERGE_FAVOR_BASE 4
6667

6768
/* merge output styles */
6869
#define XDL_MERGE_DIFF3 1

xdiff/xmerge.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ typedef struct s_xdmerge {
2626
struct s_xdmerge *next;
2727
/*
2828
* 0 = conflict,
29-
* 1 = no conflict, take first,
29+
* 1 = no conflict, take first.
3030
* 2 = no conflict, take second.
31-
* 3 = no conflict, take both.
31+
* 3 = no conflict, take both first & second.
32+
* 4 = no conflict, take base.
3233
*/
3334
int mode;
3435
/*
@@ -313,6 +314,13 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
313314
if (m->mode & 2)
314315
size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0,
315316
dest ? dest + size : NULL);
317+
} else if (m->mode == XDL_MERGE_FAVOR_BASE) {
318+
/* Before conflicting part */
319+
size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
320+
dest ? dest + size : NULL);
321+
/* Image from merge base */
322+
size += xdl_orig_copy(xe1, m->i0, m->chg0, 0, 0,
323+
dest ? dest + size : NULL);
316324
} else
317325
continue;
318326
i = m->i1 + m->chg1;

0 commit comments

Comments
 (0)