Skip to content

Commit a4b5e91

Browse files
jrngitster
authored andcommitted
xdl_merge(): move file1 and file2 labels to xmparam structure
The labels for the three participants in a potential conflict are all optional arguments for the xdiff merge routine; if they are NULL, then xdl_merge() can cope by omitting the labels from its output. Move them to the xmparam structure to allow new callers to save some keystrokes where they are not needed. This also has the virtue of making the xdiff merge interface more similar to merge_trees, which might make it easier to learn. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8a16143 commit a4b5e91

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

builtin/merge-file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
7777
argv[i]);
7878
}
7979

80-
ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
81-
&xmp, &result);
80+
xmp.file1 = names[0];
81+
xmp.file2 = names[2];
82+
ret = xdl_merge(mmfs + 1, mmfs + 0, mmfs + 2, &xmp, &result);
8283

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

ll-merge.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
8383
xmp.style = git_xmerge_style;
8484
if (marker_size > 0)
8585
xmp.marker_size = marker_size;
86-
return xdl_merge(orig, src1, name1, src2, name2, &xmp, result);
86+
xmp.file1 = name1;
87+
xmp.file2 = name2;
88+
return xdl_merge(orig, src1, src2, &xmp, result);
8789
}
8890

8991
static int ll_union_merge(const struct ll_merge_driver *drv_unused,

xdiff/xdiff.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ typedef struct s_xmparam {
118118
int favor;
119119
int style;
120120
const char *ancestor; /* label for orig */
121+
const char *file1; /* label for mf1 */
122+
const char *file2; /* label for mf2 */
121123
} xmparam_t;
122124

123125
#define DEFAULT_CONFLICT_MARKER_SIZE 7
124126

125-
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
126-
mmfile_t *mf2, const char *name2,
127+
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
127128
xmparam_t const *xmp, mmbuffer_t *result);
128129

129130
#ifdef __cplusplus

xdiff/xmerge.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,15 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
407407
*
408408
* returns < 0 on error, == 0 for no conflicts, else number of conflicts
409409
*/
410-
static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
411-
xdfenv_t *xe2, xdchange_t *xscr2, const char *name2,
412-
xmparam_t const *xmp, mmbuffer_t *result) {
410+
static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,
411+
xdfenv_t *xe2, xdchange_t *xscr2,
412+
xmparam_t const *xmp, mmbuffer_t *result)
413+
{
413414
xdmerge_t *changes, *c;
414415
xpparam_t const *xpp = &xmp->xpp;
415416
const char *const ancestor_name = xmp->ancestor;
417+
const char *const name1 = xmp->file1;
418+
const char *const name2 = xmp->file2;
416419
int i0, i1, i2, chg0, chg1, chg2;
417420
int level = xmp->level;
418421
int style = xmp->style;
@@ -566,9 +569,9 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
566569
return xdl_cleanup_merge(changes);
567570
}
568571

569-
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
570-
mmfile_t *mf2, const char *name2,
571-
xmparam_t const *xmp, mmbuffer_t *result) {
572+
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
573+
xmparam_t const *xmp, mmbuffer_t *result)
574+
{
572575
xdchange_t *xscr1, *xscr2;
573576
xdfenv_t xe1, xe2;
574577
int status;
@@ -603,8 +606,8 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
603606
memcpy(result->ptr, mf1->ptr, mf1->size);
604607
result->size = mf1->size;
605608
} else {
606-
status = xdl_do_merge(&xe1, xscr1, name1,
607-
&xe2, xscr2, name2,
609+
status = xdl_do_merge(&xe1, xscr1,
610+
&xe2, xscr2,
608611
xmp, result);
609612
}
610613
xdl_free_script(xscr1);

0 commit comments

Comments
 (0)