obshistory: factor out _markerspreciseverb()
authorAnton Shestakov <av6@dwimlabs.net>
Sat, 11 Jan 2020 19:24:21 +0700
changeset 5065 877d80a205d1
parent 5064 c9138c441761
child 5066 8dc865544aa1
obshistory: factor out _markerspreciseverb()
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Fri Jan 17 20:40:24 2020 +0700
+++ b/hgext3rd/evolve/obshistory.py	Sat Jan 11 19:24:21 2020 +0700
@@ -847,6 +847,24 @@
     DIFFCHANGED: b"amended"
 }
 
+def _markerspreciseverb(markers):
+    """ Return a more precise verb based on effect flags in markers
+
+    Return None if verb cannot be more precise than just "rewritten", i.e. when
+    markers collectively have more than one effect in the flags.
+    """
+    metadata = [dict(marker[3]) for marker in markers]
+    ef1 = [data.get(b'ef1') for data in metadata]
+
+    if all(ef1):
+        combined = 0
+        for ef in ef1:
+            combined |= int(ef)
+
+        # Combined will be in VERBMAPPING only if one bit is set
+        if combined in VERBMAPPING:
+            return VERBMAPPING[combined]
+
 def _successorsetverb(successorset, markers):
     """ Return the verb summarizing the successorset
     """
@@ -854,19 +872,7 @@
     if not successorset:
         verb = b'pruned'
     elif len(successorset) == 1:
-        # Check for effect flag
-
-        metadata = [dict(marker[3]) for marker in markers]
-        ef1 = [data.get(b'ef1') for data in metadata]
-
-        if all(ef1):
-            combined = 0
-            for ef in ef1:
-                combined |= int(ef)
-
-            # Combined will be in VERBMAPPING only of one bit is set
-            if combined in VERBMAPPING:
-                verb = VERBMAPPING[combined]
+        verb = _markerspreciseverb(markers)
 
         if verb is None:
             verb = b'rewritten'