Skip to content

Commit 9914cf4

Browse files
committed
xdl_merge(): allow passing down marker_size in xmparam_t
This allows the callers of xdl_merge() to pass marker_size (defaults to 7) in xmparam_t argument, to use conflict markers of non-default length. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 00f8f97 commit 9914cf4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

xdiff/xdiff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
110110

111111
typedef struct s_xmparam {
112112
xpparam_t xpp;
113+
int marker_size;
113114
} xmparam_t;
114115

116+
#define DEFAULT_CONFLICT_MARKER_SIZE 7
117+
115118
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
116119
mmfile_t *mf2, const char *name2,
117120
xmparam_t const *xmp, int level, mmbuffer_t *result);

xdiff/xmerge.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
145145
static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
146146
xdfenv_t *xe2, const char *name2,
147147
int size, int i, int style,
148-
xdmerge_t *m, char *dest)
148+
xdmerge_t *m, char *dest, int marker_size)
149149
{
150-
const int marker_size = 7;
151150
int marker1_size = (name1 ? strlen(name1) + 1 : 0);
152151
int marker2_size = (name2 ? strlen(name2) + 1 : 0);
153152
int j;
154153

154+
if (marker_size <= 0)
155+
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
156+
155157
/* Before conflicting part */
156158
size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
157159
dest ? dest + size : NULL);
@@ -214,14 +216,16 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
214216

215217
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
216218
xdfenv_t *xe2, const char *name2,
217-
xdmerge_t *m, char *dest, int style)
219+
xdmerge_t *m, char *dest, int style,
220+
int marker_size)
218221
{
219222
int size, i;
220223

221224
for (size = i = 0; m; m = m->next) {
222225
if (m->mode == 0)
223226
size = fill_conflict_hunk(xe1, name1, xe2, name2,
224-
size, i, style, m, dest);
227+
size, i, style, m, dest,
228+
marker_size);
225229
else if (m->mode == 1)
226230
size += xdl_recs_copy(xe1, i, m->i1 + m->chg1 - i, 0,
227231
dest ? dest + size : NULL);
@@ -386,8 +390,9 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
386390
*/
387391
static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
388392
xdfenv_t *xe2, xdchange_t *xscr2, const char *name2,
389-
int flags, xpparam_t const *xpp, mmbuffer_t *result) {
393+
int flags, xmparam_t const *xmp, mmbuffer_t *result) {
390394
xdmerge_t *changes, *c;
395+
xpparam_t const *xpp = &xmp->xpp;
391396
int i0, i1, i2, chg0, chg1, chg2;
392397
int level = flags & XDL_MERGE_LEVEL_MASK;
393398
int style = flags & XDL_MERGE_STYLE_MASK;
@@ -522,16 +527,18 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
522527
}
523528
/* output */
524529
if (result) {
530+
int marker_size = xmp->marker_size;
525531
int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
526-
changes, NULL, style);
532+
changes, NULL, style,
533+
marker_size);
527534
result->ptr = xdl_malloc(size);
528535
if (!result->ptr) {
529536
xdl_cleanup_merge(changes);
530537
return -1;
531538
}
532539
result->size = size;
533540
xdl_fill_merge_buffer(xe1, name1, xe2, name2, changes,
534-
result->ptr, style);
541+
result->ptr, style, marker_size);
535542
}
536543
return xdl_cleanup_merge(changes);
537544
}
@@ -575,7 +582,7 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
575582
} else {
576583
status = xdl_do_merge(&xe1, xscr1, name1,
577584
&xe2, xscr2, name2,
578-
flags, xpp, result);
585+
flags, xmp, result);
579586
}
580587
xdl_free_script(xscr1);
581588
xdl_free_script(xscr2);

0 commit comments

Comments
 (0)