Page MenuHomePhabricator

xdiff: add a python wrapper
AbandonedPublic

Authored by quark on Mar 2 2018, 7:25 PM.

Details

Reviewers
ryanmce
Group Reviewers
hg-reviewers
Summary

Implement a mercurial.cext.xdiff module that exposes the xdiff algorithm.

xdiff.blocks should be a drop-in replacement for bdiff.blocks.

In theory we can change the pure C version of bdiff.c directly. However
that means we lose bdiff entirely. It seems more flexible to have both at
the same time so they can be easily switched via Python code. Hence the
Python module approach.

Test Plan

make local. And test from hg debugshell:

In [1]: from mercurial.cext import bdiff, xdiff

In [2]: bdiff.blocks('b\nc\nd\n', 'a\nb\nc\ne\nf\n')
Out[2]: [(0, 2, 1, 3), (3, 3, 5, 5)]

In [3]: xdiff.blocks('b\nc\nd\n', 'a\nb\nc\ne\nf\n')
Out[3]: [(0, 2, 1, 3), (3, 3, 5, 5)]

In [4]: bdiff.blocks('a\nb', '')
Out[4]: [(2, 2, 0, 0)]

In [5]: xdiff.blocks('a\nb', '')
Out[5]: [(2, 2, 0, 0)]

In [6]: bdiff.blocks('a\nb', 'a\nb\n')
Out[6]: [(0, 1, 0, 1), (2, 2, 2, 2)]

In [7]: xdiff.blocks('a\nb', 'a\nb\n')
Out[7]: [(0, 1, 0, 1), (2, 2, 2, 2)]

In [8]: xdiff.blocks('', '')
Out[8]: [(0, 0, 0, 0)]

In [9]: bdiff.blocks('', '')
Out[9]: [(0, 0, 0, 0)]

In [10]: xdiff.blocks('', '\n')
Out[10]: [(0, 0, 1, 1)]

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

ryanmce created this revision.Mar 2 2018, 7:25 PM
quark added a subscriber: quark.Mar 2 2018, 8:53 PM

Traditionally things under mercurial.cext has a pure equivalent. So it's cleaner to either make the changes directly in mercurial.cext.bdiff, or mercurial/bdiff.c. Or add a xdiff pure shim.

durin42 added a subscriber: durin42.Mar 3 2018, 9:49 AM
durin42 added inline comments.
setup.py
223

wat?

quark commandeered this revision.

Not going to add another module.

quark abandoned this revision.