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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

indygreg (Gregory Szorc)
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
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

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

indygreg (Gregory Szorc)
marmoute updated this revision to Diff 16483.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6817?vs=16422&id=16483

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6817/new/

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 operation not 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 operation not 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)
 
-        outsidedata = {}
-        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
+    outsidedata = {}
+    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)
-                        outsidedata.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)
+                    outsidedata.update(s)
+                else: # write operation
+                    text, vhash = writetransform(revlog, text, sidedata)
+            validatehash = validatehash and vhash
 
-        return text, validatehash, outsidedata
+    return text, validatehash, outsidedata



To: marmoute, yuja, durin42, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

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

indygreg (Gregory Szorc)
In reply to this post by indygreg (Gregory Szorc)
Closed by commit rHG50d9de61ce02: flagprocessors: make `_processflagsfunc` a module level function (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6817?vs=16483&id=16638

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6817/new/

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 operation not 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 operation not 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)
 
-        outsidedata = {}
-        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
+    outsidedata = {}
+    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)
-                        outsidedata.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)
+                    outsidedata.update(s)
+                else: # write operation
+                    text, vhash = writetransform(revlog, text, sidedata)
+            validatehash = validatehash and vhash
 
-        return text, validatehash, outsidedata
+    return text, validatehash, outsidedata



To: marmoute, yuja, durin42, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel