D2603: mdiff: add a config option to use xdiff algorithm

2018-03-03 Thread quark (Jun Wu)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG9b51ac874d90: mdiff: add a config option to use xdiff 
algorithm (authored by quark, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2603?vs=6460&id=6517

REVISION DETAIL
  https://phab.mercurial-scm.org/D2603

AFFECTED FILES
  mercurial/configitems.py
  mercurial/mdiff.py
  mercurial/patch.py

CHANGE DETAILS

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2256,6 +2256,7 @@
 'context': get('unified', getter=ui.config),
 }
 buildopts['worddiff'] = ui.configbool('experimental', 'worddiff')
+buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
 
 if git:
 buildopts['git'] = get('git')
diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -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
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -577,6 +577,9 @@
 coreconfigitem('experimental', 'sshpeer.advertise-v2',
 default=False,
 )
+coreconfigitem('experimental', 'xdiff',
+default=False,
+)
 coreconfigitem('extensions', '.*',
 default=None,
 generic=True,



To: quark, #hg-reviewers, indygreg, durin42
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2603: mdiff: add a config option to use xdiff algorithm

2018-03-03 Thread quark (Jun Wu)
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The `experimental.xdiff` will affect the default diffopts and make mdiff use
  the xdiff algorithm for better diff quality.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2603

AFFECTED FILES
  mercurial/configitems.py
  mercurial/mdiff.py
  mercurial/patch.py

CHANGE DETAILS

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2256,6 +2256,7 @@
 'context': get('unified', getter=ui.config),
 }
 buildopts['worddiff'] = ui.configbool('experimental', 'worddiff')
+buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
 
 if git:
 buildopts['git'] = get('git')
diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -71,6 +71,7 @@
 'upgrade': False,
 'showsimilarity': False,
 'worddiff': False,
+'xdiff': False,
 }
 
 def __init__(self, **opts):
@@ -196,6 +197,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
@@ -209,7 +217,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
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -577,6 +577,9 @@
 coreconfigitem('experimental', 'sshpeer.advertise-v2',
 default=False,
 )
+coreconfigitem('experimental', 'xdiff',
+default=False,
+)
 coreconfigitem('extensions', '.*',
 default=None,
 generic=True,



To: quark, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel