Skip to content

Commit a9ed376

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
xdiff: generate "anti-diffs" aka what is common to two files
This fairly trivial patch adds a new XDL_EMIT_xxx flag to tell libxdiff that we don't want to generate the _diff_ between two files, we want to see the lines that are _common_ to two files. So when you set XDL_EMIT_COMMON, xdl_diff() will do everything exactly like it used to do, but the output records it generates just contain the lines that aren't part of the diff. This is for doing things like generating the common base case for a file that was added in both branches. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abc0267 commit a9ed376

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

xdiff/xdiff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
#define XDL_PATCH_IGNOREBSPACE (1 << 8)
4040

4141
#define XDL_EMIT_FUNCNAMES (1 << 0)
42+
#define XDL_EMIT_COMMON (1 << 1)
4243

4344
#define XDL_MMB_READONLY (1 << 0)
4445

xdiff/xemit.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,31 @@ static void xdl_find_func(xdfile_t *xf, long i, char *buf, long sz, long *ll) {
100100
}
101101

102102

103+
int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
104+
xdemitconf_t const *xecfg) {
105+
xdfile_t *xdf = &xe->xdf1;
106+
const char *rchg = xdf->rchg;
107+
long ix;
108+
109+
for (ix = 0; ix < xdf->nrec; ix++) {
110+
if (rchg[ix])
111+
continue;
112+
if (xdl_emit_record(xdf, ix, "", ecb))
113+
return -1;
114+
}
115+
return 0;
116+
}
117+
103118
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
104119
xdemitconf_t const *xecfg) {
105120
long s1, s2, e1, e2, lctx;
106121
xdchange_t *xch, *xche;
107122
char funcbuf[40];
108123
long funclen = 0;
109124

125+
if (xecfg->flags & XDL_EMIT_COMMON)
126+
return xdl_emit_common(xe, xscr, ecb, xecfg);
127+
110128
for (xch = xche = xscr; xch; xch = xche->next) {
111129
xche = xdl_get_hunk(xch, xecfg);
112130

0 commit comments

Comments
 (0)