[PATCH 09 of 10] effectflag: detect when meta changed

Boris Feld boris.feld at octobus.net
Fri Jul 7 08:38:38 EDT 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1499345924 -7200
#      Thu Jul 06 14:58:44 2017 +0200
# Node ID 6a40d87dfedcce4064eb4bcdb131ed4d427fd4de
# Parent  96a9902a0c2a2c93e7e2a672fb682c845cfcbb88
# EXP-Topic effectflag
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.

diff -r 96a9902a0c2a -r 6a40d87dfedc mercurial/obsutil.py
--- 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,
 )
@@ -538,11 +540,31 @@
 
 # logic around storing and using effect flags
 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('^__touch-noise__$'),
+    re.compile('^branch$'),
+    re.compile('^.*-source$'),
+    re.compile('^.*_source$'),
+    re.compile('^source$'),
+]
+
+def ismetablacklisted(metaitem):
+    """ Check that the key of a meta item (extrakey, extravalue) does not
+    match at least one of the blacklist pattern
+    """
+    metakey = metaitem[0]
+    for pattern in METABLACKLIST:
+        if pattern.match(metakey):
+            return False
+
+    return True
+
 def geteffectflag(relation):
     """ From an obs-marker relation, compute what changed between the
     predecessor and the successor.
@@ -572,4 +594,14 @@
         if changectx.parents() != source.parents():
             effects |= PARENTCHANGED
 
+        # Check if other meta has changed
+        changeextra = changectx.extra().items()
+        ctxmeta = filter(ismetablacklisted, changeextra)
+
+        sourceextra = source.extra().items()
+        srcmeta = filter(ismetablacklisted, sourceextra)
+
+        if ctxmeta != srcmeta:
+            effects |= METACHANGED
+
     return effects
diff -r 96a9902a0c2a -r 6a40d87dfedc tests/test-obsmarkers-effectflag.t
--- 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
@@ -168,4 +168,4 @@
 
   $ hg debugobsolete -r .
   2b5d9213db9e0e240052e89aad86f7c7a5fb3822 0 {2f599e54c1c6974299065cdf54e1ad640bfb7b5d} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'user': 'test'}
-  2f599e54c1c6974299065cdf54e1ad640bfb7b5d 12c6238b5e371eea00fd2013b12edce3f070928b 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'user': 'test'}
+  2f599e54c1c6974299065cdf54e1ad640bfb7b5d 12c6238b5e371eea00fd2013b12edce3f070928b 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '2', 'user': 'test'}


More information about the Mercurial-devel mailing list