Skip to content

Commit 857b933

Browse files
dschoJunio C Hamano
authored andcommitted
xdiff: add xdl_merge()
This new function implements the functionality of RCS merge, but in-memory. It returns < 0 on error, otherwise the number of conflicts. Finding the conflicting lines can be a very expensive task. You can control the eagerness of this algorithm: - a level value of 0 means that all overlapping changes are treated as conflicts, - a value of 1 means that if the overlapping changes are identical, it is not treated as a conflict. - If you set level to 2, overlapping changes will be analyzed, so that almost identical changes will not result in huge conflicts. Rather, only the conflicting lines will be shown inside conflict markers. With each increasing level, the algorithm gets slower, but more accurate. Note that the code for level 2 depends on the simple definition of mmfile_t specific to git, and therefore it will be harder to port that to LibXDiff. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 278fcd7 commit 857b933

File tree

5 files changed

+444
-3
lines changed

5 files changed

+444
-3
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,8 @@ $(DIFF_OBJS): diffcore.h
723723
$(LIB_FILE): $(LIB_OBJS)
724724
rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)
725725

726-
XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o
726+
XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
727+
xdiff/xmerge.o
727728
$(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
728729
xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
729730

xdiff/xdiff.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ extern "C" {
4949
#define XDL_BDOP_CPY 2
5050
#define XDL_BDOP_INSB 3
5151

52+
#define XDL_MERGE_MINIMAL 0
53+
#define XDL_MERGE_EAGER 1
54+
#define XDL_MERGE_ZEALOUS 2
5255

5356
typedef struct s_mmfile {
5457
char *ptr;
@@ -90,6 +93,10 @@ long xdl_mmfile_size(mmfile_t *mmf);
9093
int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
9194
xdemitconf_t const *xecfg, xdemitcb_t *ecb);
9295

96+
int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
97+
mmfile_t *mf2, const char *name2,
98+
xpparam_t const *xpp, int level, mmbuffer_t *result);
99+
93100
#ifdef __cplusplus
94101
}
95102
#endif /* #ifdef __cplusplus */

xdiff/xdiffi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
4545
long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl,
4646
xdalgoenv_t *xenv);
4747
static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, long chg2);
48-
static int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags);
4948

5049

5150

@@ -397,7 +396,7 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
397396
}
398397

399398

400-
static int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
399+
int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
401400
long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;
402401
char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
403402
xrecord_t **recs = xdf->recs;

xdiff/xdiffi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1,
5050
long *kvdf, long *kvdb, int need_min, xdalgoenv_t *xenv);
5151
int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
5252
xdfenv_t *xe);
53+
int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags);
5354
int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr);
5455
void xdl_free_script(xdchange_t *xscr);
5556
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,

0 commit comments

Comments
 (0)