Mercurial > public > mercurial-scm > hg-stable
diff mercurial/mdiff.py @ 36705:c6a61298ac32
mdiff: add a config option to use xdiff algorithm
The `experimental.xdiff` will affect the default diffopts and make mdiff use
the xdiff algorithm for better diff quality.
Differential Revision: https://phab.mercurial-scm.org/D2603
author | Jun Wu <quark@fb.com> |
---|---|
date | Sat, 03 Mar 2018 12:39:14 -0800 |
parents | 68026dd7c4f9 |
children | b6de372b4309 |
line wrap: on
line diff
--- a/mercurial/mdiff.py Sat Mar 03 12:39:14 2018 -0800 +++ b/mercurial/mdiff.py Sat Mar 03 12:39:14 2018 -0800 @@ -63,6 +63,7 @@ 'upgrade': False, 'showsimilarity': False, 'worddiff': False, + 'xdiff': False, } def __init__(self, **opts): @@ -188,6 +189,13 @@ raise error.Abort(_('line range exceeds file size')) return filteredblocks, (lba, uba) +def chooseblocksfunc(opts=None): + if (opts is None or not opts.xdiff + or not util.safehasattr(bdiff, 'xdiffblocks')): + return bdiff.blocks + else: + return bdiff.xdiffblocks + def allblocks(text1, text2, opts=None, lines1=None, lines2=None): """Return (block, type) tuples, where block is an mdiff.blocks line entry. type is '=' for blocks matching exactly one another @@ -201,7 +209,7 @@ if opts.ignorews or opts.ignorewsamount or opts.ignorewseol: text1 = wsclean(opts, text1, False) text2 = wsclean(opts, text2, False) - diff = bdiff.blocks(text1, text2) + diff = chooseblocksfunc(opts)(text1, text2) for i, s1 in enumerate(diff): # The first match is special. # we've either found a match starting at line 0 or a match later