D6799: flagutil: use it in simplestorerepo

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Sat Sep 7 05:26:59 EDT 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 remove the other code duplication of the `_processflags` code.
  
  To be honest, this code looks very dead since it is not run by either developer
  nor buildbot. However, we update the code to make the task of reviving this less
  daunting.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/simplestorerepo.py

CHANGE DETAILS

diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py
--- a/tests/simplestorerepo.py
+++ b/tests/simplestorerepo.py
@@ -91,7 +91,7 @@
     node = attr.ib(default=None)
 
 @interfaceutil.implementer(repository.ifilestorage)
-class filestorage(object):
+class filestorage(flagutil.flagprocessorsmixin):
     """Implements storage for a tracked path.
 
     Data is stored in the VFS in a directory corresponding to the tracked
@@ -102,6 +102,8 @@
     Fulltext data is stored in files having names of the node.
     """
 
+    _flagserrorclass = simplestoreerror
+
     def __init__(self, svfs, path):
         self._svfs = svfs
         self._path = path
@@ -119,6 +121,8 @@
         self._index = []
         self._refreshindex()
 
+        self._flagprocessors = dict(flagutil.flagprocessors)
+
     def _refreshindex(self):
         self._indexbynode.clear()
         self._indexbyrev.clear()
@@ -263,45 +267,6 @@
 
         return True
 
-    def _processflags(self, text, flags, operation, raw=False):
-        if flags == 0:
-            return text, True
-
-        if flags & ~flagutil.REVIDX_KNOWN_FLAGS:
-            raise simplestoreerror(_("incompatible revision flag '%#x'") %
-                                   (flags & ~flagutil.REVIDX_KNOWN_FLAGS))
-
-        validatehash = True
-        # Depending on the operation (read or write), the order might be
-        # reversed due to non-commutative transforms.
-        orderedflags = revlog.REVIDX_FLAGS_ORDER
-        if operation == 'write':
-            orderedflags = reversed(orderedflags)
-
-        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 revlog._flagprocessors:
-                    message = _("missing processor for flag '%#x'") % (flag)
-                    raise simplestoreerror(message)
-
-                processor = revlog._flagprocessors[flag]
-                if processor is not None:
-                    readtransform, writetransform, rawtransform = processor
-
-                    if raw:
-                        vhash = rawtransform(self, text)
-                    elif operation == 'read':
-                        text, vhash = readtransform(self, text)
-                    else:  # write operation
-                        text, vhash = writetransform(self, text)
-                validatehash = validatehash and vhash
-
-        return text, validatehash
-
     def checkhash(self, text, node, p1=None, p2=None, rev=None):
         if p1 is None and p2 is None:
             p1, p2 = self.parents(node)



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


More information about the Mercurial-devel mailing list