Patchwork D541: effectflag: detect when diff changed

login
register
mail settings
Submitter phabricator
Date Sept. 27, 2017, 8:08 a.m.
Message ID <e2bb8a81c40ed31982196267fb980e87@localhost.localdomain>
Download mbox | patch
Permalink /patch/24177/
State Not Applicable
Headers show

Comments

phabricator - Sept. 27, 2017, 8:08 a.m.
lothiraldan updated this revision to Diff 2112.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D541?vs=1345&id=2112

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

AFFECTED FILES
  mercurial/obsutil.py
  tests/test-obsmarkers-effectflag.t

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-obsmarkers-effectflag.t b/tests/test-obsmarkers-effectflag.t
--- a/tests/test-obsmarkers-effectflag.t
+++ b/tests/test-obsmarkers-effectflag.t
@@ -93,7 +93,7 @@ 
 check result
 
   $ hg debugobsolete --rev .
-  ebfe0333e0d96f68a917afd97c0a0af87f1c3b5f 75781fdbdbf58a987516b00c980bccda1e9ae588 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'amend', 'user': 'test'}
+  ebfe0333e0d96f68a917afd97c0a0af87f1c3b5f 75781fdbdbf58a987516b00c980bccda1e9ae588 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'amend', 'user': 'test'}
 
 amend with multiple effect (desc and meta)
 -------------------------------------------
diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -312,6 +312,7 @@ 
 
 DESCCHANGED = 1 << 0 # action changed the description
 METACHANGED = 1 << 1 # action change the meta
+DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset
 PARENTCHANGED = 1 << 2 # action change the parent
 USERCHANGED = 1 << 4 # the user changed
 DATECHANGED = 1 << 5 # the date changed
@@ -335,6 +336,46 @@ 
 
     return True
 
+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:
+        lines = next(iterdiff)
+    except StopIteration:
+        return None
+    return _prepare_hunk(lines)
+
+def _cmpdiff(leftctx, rightctx):
+    """return True if both ctx introduce the "same diff"
+
+    This is a first and basic implementation, with many shortcoming.
+    """
+
+    # Leftctx or right ctx might be filtered, so we need to use the contexts
+    # with an unfiltered repository to safely compute the diff
+    leftunfi = leftctx._repo.unfiltered()[leftctx.rev()]
+    leftdiff = leftunfi.diff(git=1)
+    rightunfi = rightctx._repo.unfiltered()[rightctx.rev()]
+    rightdiff = rightunfi.diff(git=1)
+
+    left, right = (0, 0)
+    while None not in (left, right):
+        left = _getdifflines(leftdiff)
+        right = _getdifflines(rightdiff)
+
+        if left != right:
+            return False
+    return True
+
 def geteffectflag(relation):
     """ From an obs-marker relation, compute what changed between the
     predecessor and the successor.
@@ -374,6 +415,10 @@ 
         if ctxmeta != srcmeta:
             effects |= METACHANGED
 
+        # Check if the diff has changed
+        if not _cmpdiff(source, changectx):
+            effects |= DIFFCHANGED
+
     return effects
 
 def getobsoleted(repo, tr):