effectflag: better diff detection
Improve the diff detection algorithm to have less false positive like in the
case of a rebase that move the hunk in the file but the hunk stays the same.
--- a/hgext3rd/evolve/obshistory.py Tue May 30 11:38:30 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py Tue May 30 11:39:45 2017 +0200
@@ -440,13 +440,23 @@
return effects
-def _getdiffline(iterdiff):
- """return a cleaned up line"""
+def _prepare_hunk(hunk):
+ """Drop all information but the username and patch"""
+ cleanunk = []
+ for line in hunk.splitlines():
+ if line.startswith(b'# User') or not line.startswith(b'#'):
+ if line.startswith(b'@@'):
+ line = b'@@\n'
+ cleanunk.append(line)
+ return cleanunk
+
+def _getdifflines(iterdiff):
+ """return a cleaned up lines"""
try:
- line = iterdiff.next()
+ lines = iterdiff.next()
except StopIteration:
return None
- return line
+ return _prepare_hunk(lines)
def _cmpdiff(leftctx, rightctx):
"""return True if both ctx introduce the "same diff"
@@ -457,8 +467,9 @@
rightdiff = rightctx.diff(git=1)
left, right = (0, 0)
while None not in (left, right):
- left = _getdiffline(leftdiff)
- right = _getdiffline(rightdiff)
+ left = _getdifflines(leftdiff)
+ right = _getdifflines(rightdiff)
+
if left != right:
return False
return True
--- a/tests/test-evolve-effectflags.t Tue May 30 11:38:30 2017 +0200
+++ b/tests/test-evolve-effectflags.t Tue May 30 11:39:45 2017 +0200
@@ -197,5 +197,5 @@
o e509e2eb3df5 (22) H1
|
x b57fed8d8322 (20) H1
- rewritten(parent, content) by test (*) as e509e2eb3df5 (glob)
+ rewritten(parent) by test (*) as e509e2eb3df5 (glob)