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>
Jonathan Nieder committed
Mar 20, 2010 at 19:35 UTC
a4b5e91c49238146f4cb85ff5f7f3bc97e0e51de
4 files changed
+20
-13
builtin/merge-file.c
+3
-2
@@ -77,8 +77,9 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
77
argv[i]);
78
}
79
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);
83
84
for (i = 0; i < 3; i++)
85
free(mmfs[i].ptr);
ll-merge.c
+3
-1
@@ -83,7 +83,9 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
83
xmp.style = git_xmerge_style;
84
if (marker_size > 0)
85
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);
89
}
90
91
static int ll_union_merge(const struct ll_merge_driver *drv_unused,
xdiff/xdiff.h
+3
-2
@@ -118,12 +118,13 @@ typedef struct s_xmparam {
118
int favor;
119
int style;
120
const char *ancestor; /* label for orig */
121
+ const char *file1; /* label for mf1 */
122
+ const char *file2; /* label for mf2 */
123
} xmparam_t;
124
125
#define DEFAULT_CONFLICT_MARKER_SIZE 7
126
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,
128
xmparam_t const *xmp, mmbuffer_t *result);
129
130
#ifdef __cplusplus
xdiff/xmerge.c
+11
-8
@@ -407,12 +407,15 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
407
*
408
* returns < 0 on error, == 0 for no conflicts, else number of conflicts
409
*/
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
+{
414
xdmerge_t *changes, *c;
415
xpparam_t const *xpp = &xmp->xpp;
416
const char *const ancestor_name = xmp->ancestor;
417
+ const char *const name1 = xmp->file1;
418
+ const char *const name2 = xmp->file2;
419
int i0, i1, i2, chg0, chg1, chg2;
420
int level = xmp->level;
421
int style = xmp->style;
@@ -566,9 +569,9 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
569
return xdl_cleanup_merge(changes);
570
}
571
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
+{
575
xdchange_t *xscr1, *xscr2;
576
xdfenv_t xe1, xe2;
577
int status;
@@ -603,8 +606,8 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
606
memcpy(result->ptr, mf1->ptr, mf1->size);
607
result->size = mf1->size;
608
} else {
606
- status = xdl_do_merge(&xe1, xscr1, name1,
607
- &xe2, xscr2, name2,
609
+ status = xdl_do_merge(&xe1, xscr1,
610
+ &xe2, xscr2,
611
xmp, result);
612
}
613
xdl_free_script(xscr1);