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 <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Jun 28, 2006 at 21:57 UTC
a9ed376b158faf82d3685b51d546ccaeda716da3
2 files changed
+19
xdiff/xdiff.h
+1
@@ -39,6 +39,7 @@ extern "C" {
39
#define XDL_PATCH_IGNOREBSPACE (1 << 8)
40
41
#define XDL_EMIT_FUNCNAMES (1 << 0)
42
+#define XDL_EMIT_COMMON (1 << 1)
43
44
#define XDL_MMB_READONLY (1 << 0)
45
xdiff/xemit.c
+18
@@ -100,6 +100,21 @@ static void xdl_find_func(xdfile_t *xf, long i, char *buf, long sz, long *ll) {
100
}
101
102
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
+
118
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
119
xdemitconf_t const *xecfg) {
120
long s1, s2, e1, e2, lctx;
@@ -107,6 +122,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
122
char funcbuf[40];
123
long funclen = 0;
124
125
+ if (xecfg->flags & XDL_EMIT_COMMON)
126
+ return xdl_emit_common(xe, xscr, ecb, xecfg);
127
+
128
for (xch = xche = xscr; xch; xch = xche->next) {
129
xche = xdl_get_hunk(xch, xecfg);
130