D6817: flagprocessors: make `_processflagsfunc` a module level function

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sat Sep 7 09:29:24 UTC 2019


marmoute created this revision.
marmoute added reviewers: yuja, durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is the first step toward removing the flag processing mixin.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/revlogutils/flagutil.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/flagutil.py b/mercurial/revlogutils/flagutil.py
--- a/mercurial/revlogutils/flagutil.py
+++ b/mercurial/revlogutils/flagutil.py
@@ -118,7 +118,7 @@
         processed text and ``validatehash`` is a bool indicating whether the
         returned text should be checked for hash integrity.
         """
-        return self._processflagsfunc(text, flags, 'read')
+        return _processflagsfunc(self, text, flags, 'read')
 
     def _processflagswrite(self, text, flags, sidedata):
         """Inspect revision data flags and applies write transformations defined
@@ -136,8 +136,8 @@
         processed text and ``validatehash`` is a bool indicating whether the
         returned text should be checked for hash integrity.
         """
-        return self._processflagsfunc(text, flags, 'write',
-                                      sidedata=sidedata)[:2]
+        return _processflagsfunc(self, text, flags, 'write',
+                                 sidedata=sidedata)[:2]
 
     def _processflagsraw(self, text, flags):
         """Inspect revision data flags to check is the content hash should be
@@ -155,48 +155,52 @@
         processed text and ``validatehash`` is a bool indicating whether the
         returned text should be checked for hash integrity.
         """
-        return self._processflagsfunc(text, flags, 'raw')[1]
+        return _processflagsfunc(self, text, flags, 'raw')[1]
+
+def _processflagsfunc(revlog, text, flags, operation, sidedata=None):
+    """internal function to process flag on a revlog
 
-    def _processflagsfunc(self, text, flags, operation, sidedata=None):
-        # fast path: no flag processors will run
-        if flags == 0:
-            return text, True, {}
-        if not operation in ('read', 'write', 'raw'):
-            raise error.ProgrammingError(_("invalid '%s' operation") %
-                                         operation)
-        # Check all flags are known.
-        if flags & ~REVIDX_KNOWN_FLAGS:
-            raise self._flagserrorclass(_("incompatible revision flag '%#x'") %
-                                        (flags & ~REVIDX_KNOWN_FLAGS))
-        validatehash = True
-        # Depending on the operation (read or write), the order might be
-        # reversed due to non-commutative transforms.
-        orderedflags = REVIDX_FLAGS_ORDER
-        if operation == 'write':
-            orderedflags = reversed(orderedflags)
+    This function is private to this module, code should never needs to call it
+    directly."""
+    # fast path: no flag processors will run
+    if flags == 0:
+        return text, True, {}
+    if not operation in ('read', 'write', 'raw'):
+        raise error.ProgrammingError(_("invalid '%s' operation") %
+                                     operation)
+    # Check all flags are known.
+    if flags & ~REVIDX_KNOWN_FLAGS:
+        raise revlog._flagserrorclass(_("incompatible revision flag '%#x'") %
+                                      (flags & ~REVIDX_KNOWN_FLAGS))
+    validatehash = True
+    # Depending on the operation (read or write), the order might be
+    # reversed due to non-commutative transforms.
+    orderedflags = REVIDX_FLAGS_ORDER
+    if operation == 'write':
+        orderedflags = reversed(orderedflags)
 
-        sidedata = {}
-        for flag in orderedflags:
-            # If a flagprocessor has been registered for a known flag, apply the
-            # related operation transform and update result tuple.
-            if flag & flags:
-                vhash = True
+    sidedata = {}
+    for flag in orderedflags:
+        # If a flagprocessor has been registered for a known flag, apply the
+        # related operation transform and update result tuple.
+        if flag & flags:
+            vhash = True
 
-                if flag not in self._flagprocessors:
-                    message = _("missing processor for flag '%#x'") % (flag)
-                    raise self._flagserrorclass(message)
+            if flag not in revlog._flagprocessors:
+                message = _("missing processor for flag '%#x'") % (flag)
+                raise revlog._flagserrorclass(message)
 
-                processor = self._flagprocessors[flag]
-                if processor is not None:
-                    readtransform, writetransform, rawtransform = processor
+            processor = revlog._flagprocessors[flag]
+            if processor is not None:
+                readtransform, writetransform, rawtransform = processor
 
-                    if operation == 'raw':
-                        vhash = rawtransform(self, text)
-                    elif operation == 'read':
-                        text, vhash, s = readtransform(self, text)
-                        sidedata.update(s)
-                    else: # write operation
-                        text, vhash = writetransform(self, text, sidedata)
-                validatehash = validatehash and vhash
+                if operation == 'raw':
+                    vhash = rawtransform(revlog, text)
+                elif operation == 'read':
+                    text, vhash, s = readtransform(revlog, text)
+                    sidedata.update(s)
+                else: # write operation
+                    text, vhash = writetransform(revlog, text, sidedata)
+            validatehash = validatehash and vhash
 
-        return text, validatehash, sidedata
+    return text, validatehash, sidedata



To: marmoute, yuja, durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list