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 <gitster@pobox.com>
Junio C Hamano committed
Jan 16, 2010 at 21:30 UTC
9914cf468941067b4f3deb9c69c11af3f5b45ccc
2 files changed
+18
-8
xdiff/xdiff.h
+3
@@ -110,8 +110,11 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
110
111
typedef struct s_xmparam {
112
xpparam_t xpp;
113
+ int marker_size;
114
} xmparam_t;
115
116
+#define DEFAULT_CONFLICT_MARKER_SIZE 7
117
+
118
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
119
mmfile_t *mf2, const char *name2,
120
xmparam_t const *xmp, int level, mmbuffer_t *result);
xdiff/xmerge.c
+15
-8
@@ -145,13 +145,15 @@ static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest)
145
static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
146
xdfenv_t *xe2, const char *name2,
147
int size, int i, int style,
148
- xdmerge_t *m, char *dest)
148
+ xdmerge_t *m, char *dest, int marker_size)
149
{
150
- const int marker_size = 7;
150
int marker1_size = (name1 ? strlen(name1) + 1 : 0);
151
int marker2_size = (name2 ? strlen(name2) + 1 : 0);
152
int j;
153
154
+ if (marker_size <= 0)
155
+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
156
+
157
/* Before conflicting part */
158
size += xdl_recs_copy(xe1, i, m->i1 - i, 0,
159
dest ? dest + size : NULL);
@@ -214,14 +216,16 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
216
217
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
218
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)
221
{
222
int size, i;
223
224
for (size = i = 0; m; m = m->next) {
225
if (m->mode == 0)
226
size = fill_conflict_hunk(xe1, name1, xe2, name2,
224
- size, i, style, m, dest);
227
+ size, i, style, m, dest,
228
+ marker_size);
229
else if (m->mode == 1)
230
size += xdl_recs_copy(xe1, i, m->i1 + m->chg1 - i, 0,
231
dest ? dest + size : NULL);
@@ -386,8 +390,9 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
390
*/
391
static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
392
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) {
394
xdmerge_t *changes, *c;
395
+ xpparam_t const *xpp = &xmp->xpp;
396
int i0, i1, i2, chg0, chg1, chg2;
397
int level = flags & XDL_MERGE_LEVEL_MASK;
398
int style = flags & XDL_MERGE_STYLE_MASK;
@@ -522,8 +527,10 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
527
}
528
/* output */
529
if (result) {
530
+ int marker_size = xmp->marker_size;
531
int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
526
- changes, NULL, style);
532
+ changes, NULL, style,
533
+ marker_size);
534
result->ptr = xdl_malloc(size);
535
if (!result->ptr) {
536
xdl_cleanup_merge(changes);
@@ -531,7 +538,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
538
}
539
result->size = size;
540
xdl_fill_merge_buffer(xe1, name1, xe2, name2, changes,
534
- result->ptr, style);
541
+ result->ptr, style, marker_size);
542
}
543
return xdl_cleanup_merge(changes);
544
}
@@ -575,7 +582,7 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
582
} else {
583
status = xdl_do_merge(&xe1, xscr1, name1,
584
&xe2, xscr2, name2,
578
- flags, xpp, result);
585
+ flags, xmp, result);
586
}
587
xdl_free_script(xscr1);
588
xdl_free_script(xscr2);