Skip to content

Commit

Permalink
xdiff: generate "anti-diffs" aka what is common to two files
Browse files Browse the repository at this point in the history
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 <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jun 29, 2006
1 parent abc0267 commit a9ed376
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions xdiff/xdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern "C" {
#define XDL_PATCH_IGNOREBSPACE (1 << 8)

#define XDL_EMIT_FUNCNAMES (1 << 0)
#define XDL_EMIT_COMMON (1 << 1)

#define XDL_MMB_READONLY (1 << 0)

Expand Down
18 changes: 18 additions & 0 deletions xdiff/xemit.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,31 @@ static void xdl_find_func(xdfile_t *xf, long i, char *buf, long sz, long *ll) {
}


int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg) {
xdfile_t *xdf = &xe->xdf1;
const char *rchg = xdf->rchg;
long ix;

for (ix = 0; ix < xdf->nrec; ix++) {
if (rchg[ix])
continue;
if (xdl_emit_record(xdf, ix, "", ecb))
return -1;
}
return 0;
}

int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg) {
long s1, s2, e1, e2, lctx;
xdchange_t *xch, *xche;
char funcbuf[40];
long funclen = 0;

if (xecfg->flags & XDL_EMIT_COMMON)
return xdl_emit_common(xe, xscr, ecb, xecfg);

for (xch = xche = xscr; xch; xch = xche->next) {
xche = xdl_get_hunk(xch, xecfg);

Expand Down

0 comments on commit a9ed376

Please sign in to comment.