effectflag: detect when meta changed
authorBoris Feld <boris.feld@octobus.net>
Thu, 06 Jul 2017 14:58:44 +0200
changeset 34421 95759620d492
parent 34420 fa26f5891e68
child 34422 187bc224554a
effectflag: detect when meta changed Store in effect flag when the meta changed between the predecessor and its successors. We blacklisted some known meta that would always changed when another flag change. For example rebase would always add a meta rebase-source while the effect flag parents will already detect this situation. It can happens with various hg commands. Differential Revision: https://phab.mercurial-scm.org/D540
mercurial/obsutil.py
tests/test-obsmarkers-effectflag.t
--- a/mercurial/obsutil.py	Thu Jul 06 14:56:16 2017 +0200
+++ b/mercurial/obsutil.py	Thu Jul 06 14:58:44 2017 +0200
@@ -7,6 +7,8 @@
 
 from __future__ import absolute_import
 
+import re
+
 from . import (
     phases,
     util
@@ -309,11 +311,27 @@
 EFFECTFLAGFIELD = "ef1"
 
 DESCCHANGED = 1 << 0 # action changed the description
+METACHANGED = 1 << 1 # action change the meta
 PARENTCHANGED = 1 << 2 # action change the parent
 USERCHANGED = 1 << 4 # the user changed
 DATECHANGED = 1 << 5 # the date changed
 BRANCHCHANGED = 1 << 6 # the branch changed
 
+METABLACKLIST = [
+    re.compile('^branch$'),
+    re.compile('^.*-source$'),
+    re.compile('^.*_source$'),
+    re.compile('^source$'),
+]
+
+def metanotblacklisted(metaitem):
+    """ Check that the key of a meta item (extrakey, extravalue) does not
+    match at least one of the blacklist pattern
+    """
+    metakey = metaitem[0]
+
+    return not any(pattern.match(metakey) for pattern in METABLACKLIST)
+
 def geteffectflag(relation):
     """ From an obs-marker relation, compute what changed between the
     predecessor and the successor.
@@ -343,6 +361,16 @@
         if changectx.parents() != source.parents():
             effects |= PARENTCHANGED
 
+        # Check if other meta has changed
+        changeextra = changectx.extra().items()
+        ctxmeta = filter(metanotblacklisted, changeextra)
+
+        sourceextra = source.extra().items()
+        srcmeta = filter(metanotblacklisted, sourceextra)
+
+        if ctxmeta != srcmeta:
+            effects |= METACHANGED
+
     return effects
 
 def getobsoleted(repo, tr):
--- a/tests/test-obsmarkers-effectflag.t	Thu Jul 06 14:56:16 2017 +0200
+++ b/tests/test-obsmarkers-effectflag.t	Thu Jul 06 14:58:44 2017 +0200
@@ -164,4 +164,4 @@
 check result
 
   $ hg debugobsolete -r .
-  2f599e54c1c6974299065cdf54e1ad640bfb7b5d 12c6238b5e371eea00fd2013b12edce3f070928b 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'operation': 'amend', 'user': 'test'}
+  2f599e54c1c6974299065cdf54e1ad640bfb7b5d 12c6238b5e371eea00fd2013b12edce3f070928b 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '2', 'operation': 'amend', 'user': 'test'}