The experimental.xdiff will affect the default diffopts and make mdiff use
the xdiff algorithm for better diff quality.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
The experimental.xdiff will affect the default diffopts and make mdiff use
the xdiff algorithm for better diff quality.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/configitems.py (3 lines) | |||
M | mercurial/mdiff.py (10 lines) | |||
M | mercurial/patch.py (1 line) |
default=False, | default=False, | ||||
) | ) | ||||
coreconfigitem('experimental', 'update.atomic-file', | coreconfigitem('experimental', 'update.atomic-file', | ||||
default=False, | default=False, | ||||
) | ) | ||||
coreconfigitem('experimental', 'sshpeer.advertise-v2', | coreconfigitem('experimental', 'sshpeer.advertise-v2', | ||||
default=False, | default=False, | ||||
) | ) | ||||
coreconfigitem('experimental', 'xdiff', | |||||
default=False, | |||||
) | |||||
coreconfigitem('extensions', '.*', | coreconfigitem('extensions', '.*', | ||||
default=None, | default=None, | ||||
generic=True, | generic=True, | ||||
) | ) | ||||
coreconfigitem('extdata', '.*', | coreconfigitem('extdata', '.*', | ||||
default=None, | default=None, | ||||
generic=True, | generic=True, | ||||
) | ) |
'index': 0, | 'index': 0, | ||||
'ignorews': False, | 'ignorews': False, | ||||
'ignorewsamount': False, | 'ignorewsamount': False, | ||||
'ignorewseol': False, | 'ignorewseol': False, | ||||
'ignoreblanklines': False, | 'ignoreblanklines': False, | ||||
'upgrade': False, | 'upgrade': False, | ||||
'showsimilarity': False, | 'showsimilarity': False, | ||||
'worddiff': False, | 'worddiff': False, | ||||
'xdiff': False, | |||||
} | } | ||||
def __init__(self, **opts): | def __init__(self, **opts): | ||||
opts = pycompat.byteskwargs(opts) | opts = pycompat.byteskwargs(opts) | ||||
for k in self.defaults.keys(): | for k in self.defaults.keys(): | ||||
v = opts.get(k) | v = opts.get(k) | ||||
if v is None: | if v is None: | ||||
v = self.defaults[k] | v = self.defaults[k] | ||||
else: | else: | ||||
uba = a2 | uba = a2 | ||||
if hunkinrange((b1, (b2 - b1)), rangeb): | if hunkinrange((b1, (b2 - b1)), rangeb): | ||||
filteredblocks.append(block) | filteredblocks.append(block) | ||||
if lba is None or uba is None or uba < lba: | if lba is None or uba is None or uba < lba: | ||||
raise error.Abort(_('line range exceeds file size')) | raise error.Abort(_('line range exceeds file size')) | ||||
return filteredblocks, (lba, uba) | 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): | def allblocks(text1, text2, opts=None, lines1=None, lines2=None): | ||||
"""Return (block, type) tuples, where block is an mdiff.blocks | """Return (block, type) tuples, where block is an mdiff.blocks | ||||
line entry. type is '=' for blocks matching exactly one another | line entry. type is '=' for blocks matching exactly one another | ||||
(bdiff blocks), '!' for non-matching blocks and '~' for blocks | (bdiff blocks), '!' for non-matching blocks and '~' for blocks | ||||
matching only after having filtered blank lines. | matching only after having filtered blank lines. | ||||
line1 and line2 are text1 and text2 split with splitnewlines() if | line1 and line2 are text1 and text2 split with splitnewlines() if | ||||
they are already available. | they are already available. | ||||
""" | """ | ||||
if opts is None: | if opts is None: | ||||
opts = defaultopts | opts = defaultopts | ||||
if opts.ignorews or opts.ignorewsamount or opts.ignorewseol: | if opts.ignorews or opts.ignorewsamount or opts.ignorewseol: | ||||
text1 = wsclean(opts, text1, False) | text1 = wsclean(opts, text1, False) | ||||
text2 = wsclean(opts, text2, False) | text2 = wsclean(opts, text2, False) | ||||
diff = bdiff.blocks(text1, text2) | diff = chooseblocksfunc(opts)(text1, text2) | ||||
for i, s1 in enumerate(diff): | for i, s1 in enumerate(diff): | ||||
# The first match is special. | # The first match is special. | ||||
# we've either found a match starting at line 0 or a match later | # we've either found a match starting at line 0 or a match later | ||||
# in the file. If it starts later, old and new below will both be | # in the file. If it starts later, old and new below will both be | ||||
# empty and we'll continue to the next match. | # empty and we'll continue to the next match. | ||||
if i > 0: | if i > 0: | ||||
s = diff[i - 1] | s = diff[i - 1] | ||||
else: | else: |
# core options, expected to be understood by every diff parser | # core options, expected to be understood by every diff parser | ||||
buildopts = { | buildopts = { | ||||
'nodates': get('nodates'), | 'nodates': get('nodates'), | ||||
'showfunc': get('show_function', 'showfunc'), | 'showfunc': get('show_function', 'showfunc'), | ||||
'context': get('unified', getter=ui.config), | 'context': get('unified', getter=ui.config), | ||||
} | } | ||||
buildopts['worddiff'] = ui.configbool('experimental', 'worddiff') | buildopts['worddiff'] = ui.configbool('experimental', 'worddiff') | ||||
buildopts['xdiff'] = ui.configbool('experimental', 'xdiff') | |||||
if git: | if git: | ||||
buildopts['git'] = get('git') | buildopts['git'] = get('git') | ||||
# since this is in the experimental section, we need to call | # since this is in the experimental section, we need to call | ||||
# ui.configbool directory | # ui.configbool directory | ||||
buildopts['showsimilarity'] = ui.configbool('experimental', | buildopts['showsimilarity'] = ui.configbool('experimental', | ||||
'extendedheader.similarity') | 'extendedheader.similarity') |