effetflag: detect other meta (extra) changes
authorBoris Feld <boris.feld@octobus.net>
Tue, 30 May 2017 11:06:24 +0200
changeset 2522 a1cc2a0b9f6f
parent 2521 29fc90b0e59c
child 2523 3629446411b3
effetflag: detect other meta (extra) changes Check other changeset meta other than branch and *_source and if there is a change, set the METACHANGED effect flag. Add a test for this scenario with a topic change.
hgext3rd/evolve/obshistory.py
tests/test-evolve-effectflags.t
--- a/hgext3rd/evolve/obshistory.py	Tue May 30 17:32:39 2017 +0200
+++ b/hgext3rd/evolve/obshistory.py	Tue May 30 11:06:24 2017 +0200
@@ -7,6 +7,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import re
+
 from mercurial import (
     cmdutil,
     commands,
@@ -403,13 +405,32 @@
 
 # logic around storing and using effect flags
 DESCCHANGED = 1 << 0 # action changed the description
-METACHANGED = 1 << 1 # action change the meta (user, date, branch, etc...) OLD
+METACHANGED = 1 << 1 # action change the meta
 PARENTCHANGED = 1 << 2 # action change the parent
 DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset
 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):
     """compute the effect flag by comparing the source and destination"""
     effects = 0
@@ -431,6 +452,16 @@
         if changectx.branch() != source.branch():
             effects |= BRANCHCHANGED
 
+        # 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
+
         # Check if at least one of the parent has changes
         if changectx.parents() != source.parents():
             effects |= PARENTCHANGED
--- a/tests/test-evolve-effectflags.t	Tue May 30 17:32:39 2017 +0200
+++ b/tests/test-evolve-effectflags.t	Tue May 30 11:06:24 2017 +0200
@@ -199,3 +199,20 @@
   x  b57fed8d8322 (20) H1
        rewritten(parent) by test (*) as e509e2eb3df5 (glob)
   
+amend closing the branch should be detected as meta change
+----------------------------------------------------------
+
+  $ hg branch closedbranch
+  marked working directory as branch closedbranch
+  $ mkcommit G0
+  $ mkcommit I0
+  $ hg commit --amend --close-branch
+
+check result
+
+  $ hg obslog .
+  @  12c6238b5e37 (26) I0
+  |
+  x  2f599e54c1c6 (24) I0
+       rewritten(meta) by test (*) as 12c6238b5e37 (glob)
+