##// END OF EJS Templates
bdiff: add a xdiffblocks method...
Jun Wu -
r36693:430fdb71 default
parent child Browse files
Show More
@@ -17,6 +17,7 b''
17
17
18 #include "bdiff.h"
18 #include "bdiff.h"
19 #include "bitmanipulation.h"
19 #include "bitmanipulation.h"
20 #include "thirdparty/xdiff/xdiff.h"
20 #include "util.h"
21 #include "util.h"
21
22
22 static PyObject *blocks(PyObject *self, PyObject *args)
23 static PyObject *blocks(PyObject *self, PyObject *args)
@@ -256,6 +257,64 b' abort:'
256 return NULL;
257 return NULL;
257 }
258 }
258
259
260 static int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
261 {
262 PyObject *rl = (PyObject *)priv;
263 PyObject *m = Py_BuildValue("llll", a1, a2, b1, b2);
264 if (!m)
265 return -1;
266 if (PyList_Append(rl, m) != 0) {
267 Py_DECREF(m);
268 return -1;
269 }
270 return 0;
271 }
272
273 static PyObject *xdiffblocks(PyObject *self, PyObject *args)
274 {
275 Py_ssize_t la, lb;
276 mmfile_t a, b;
277 PyObject *rl;
278
279 xpparam_t xpp = {
280 XDF_INDENT_HEURISTIC, /* flags */
281 NULL, /* anchors */
282 0, /* anchors_nr */
283 };
284 xdemitconf_t xecfg = {
285 0, /* ctxlen */
286 0, /* interhunkctxlen */
287 XDL_EMIT_BDIFFHUNK, /* flags */
288 NULL, /* find_func */
289 NULL, /* find_func_priv */
290 hunk_consumer, /* hunk_consume_func */
291 };
292 xdemitcb_t ecb = {
293 NULL, /* priv */
294 NULL, /* outf */
295 };
296
297 if (!PyArg_ParseTuple(args, PY23("s#s#", "y#y#"), &a.ptr, &la, &b.ptr,
298 &lb))
299 return NULL;
300
301 a.size = la;
302 b.size = lb;
303
304 rl = PyList_New(0);
305 if (!rl)
306 return PyErr_NoMemory();
307
308 ecb.priv = rl;
309
310 if (xdl_diff(&a, &b, &xpp, &xecfg, &ecb) != 0) {
311 Py_DECREF(rl);
312 return PyErr_NoMemory();
313 }
314
315 return rl;
316 }
317
259 static char mdiff_doc[] = "Efficient binary diff.";
318 static char mdiff_doc[] = "Efficient binary diff.";
260
319
261 static PyMethodDef methods[] = {
320 static PyMethodDef methods[] = {
@@ -264,10 +323,12 b' static PyMethodDef methods[] = {'
264 {"fixws", fixws, METH_VARARGS, "normalize diff whitespaces\n"},
323 {"fixws", fixws, METH_VARARGS, "normalize diff whitespaces\n"},
265 {"splitnewlines", splitnewlines, METH_VARARGS,
324 {"splitnewlines", splitnewlines, METH_VARARGS,
266 "like str.splitlines, but only split on newlines\n"},
325 "like str.splitlines, but only split on newlines\n"},
326 {"xdiffblocks", xdiffblocks, METH_VARARGS,
327 "find a list of matching lines using xdiff algorithm\n"},
267 {NULL, NULL},
328 {NULL, NULL},
268 };
329 };
269
330
270 static const int version = 2;
331 static const int version = 3;
271
332
272 #ifdef IS_PY3K
333 #ifdef IS_PY3K
273 static struct PyModuleDef bdiff_module = {
334 static struct PyModuleDef bdiff_module = {
@@ -66,7 +66,7 b' def _importfrom(pkgname, modname):'
66 # keep in sync with "version" in C modules
66 # keep in sync with "version" in C modules
67 _cextversions = {
67 _cextversions = {
68 (r'cext', r'base85'): 1,
68 (r'cext', r'base85'): 1,
69 (r'cext', r'bdiff'): 2,
69 (r'cext', r'bdiff'): 3,
70 (r'cext', r'diffhelpers'): 1,
70 (r'cext', r'diffhelpers'): 1,
71 (r'cext', r'mpatch'): 1,
71 (r'cext', r'mpatch'): 1,
72 (r'cext', r'osutil'): 3,
72 (r'cext', r'osutil'): 3,
@@ -847,14 +847,33 b' for plat, macro, code in ['
847 if sys.platform == 'darwin':
847 if sys.platform == 'darwin':
848 osutil_ldflags += ['-framework', 'ApplicationServices']
848 osutil_ldflags += ['-framework', 'ApplicationServices']
849
849
850 xdiff_srcs = [
851 'mercurial/thirdparty/xdiff/xdiffi.c',
852 'mercurial/thirdparty/xdiff/xemit.c',
853 'mercurial/thirdparty/xdiff/xmerge.c',
854 'mercurial/thirdparty/xdiff/xprepare.c',
855 'mercurial/thirdparty/xdiff/xutils.c',
856 ]
857
858 xdiff_headers = [
859 'mercurial/thirdparty/xdiff/xdiff.h',
860 'mercurial/thirdparty/xdiff/xdiffi.h',
861 'mercurial/thirdparty/xdiff/xemit.h',
862 'mercurial/thirdparty/xdiff/xinclude.h',
863 'mercurial/thirdparty/xdiff/xmacros.h',
864 'mercurial/thirdparty/xdiff/xprepare.h',
865 'mercurial/thirdparty/xdiff/xtypes.h',
866 'mercurial/thirdparty/xdiff/xutils.h',
867 ]
868
850 extmodules = [
869 extmodules = [
851 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],
870 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],
852 include_dirs=common_include_dirs,
871 include_dirs=common_include_dirs,
853 depends=common_depends),
872 depends=common_depends),
854 Extension('mercurial.cext.bdiff', ['mercurial/bdiff.c',
873 Extension('mercurial.cext.bdiff', ['mercurial/bdiff.c',
855 'mercurial/cext/bdiff.c'],
874 'mercurial/cext/bdiff.c'] + xdiff_srcs,
856 include_dirs=common_include_dirs,
875 include_dirs=common_include_dirs,
857 depends=common_depends + ['mercurial/bdiff.h']),
876 depends=common_depends + ['mercurial/bdiff.h'] + xdiff_headers),
858 Extension('mercurial.cext.diffhelpers', ['mercurial/cext/diffhelpers.c'],
877 Extension('mercurial.cext.diffhelpers', ['mercurial/cext/diffhelpers.c'],
859 include_dirs=common_include_dirs,
878 include_dirs=common_include_dirs,
860 depends=common_depends),
879 depends=common_depends),
General Comments 0
You need to be logged in to leave comments. Login now