Patchwork [9,of,9] flagutil: use it in simplestorerepo

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 8, 2019, 1:47 a.m.
Message ID <8bf3a649c932784a12ea.1565228845@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41219/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 8, 2019, 1:47 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1565223018 -7200
#      Thu Aug 08 02:10:18 2019 +0200
# Node ID 8bf3a649c932784a12ea49aeda0f3991980e8777
# Parent  9ee2ada7f37ba42787408c03074206cf0bb828de
# EXP-Topic flag-processors
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 8bf3a649c932
flagutil: use it in simplestorerepo

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.

Patch

diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py
--- a/tests/simplestorerepo.py
+++ b/tests/simplestorerepo.py
@@ -89,7 +89,7 @@  class simplefilestoreproblem(object):
     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
@@ -100,6 +100,8 @@  class filestorage(object):
     Fulltext data is stored in files having names of the node.
     """
 
+    _flagserrorclass = simplestoreerror
+
     def __init__(self, svfs, path):
         self._svfs = svfs
         self._path = path
@@ -117,6 +119,8 @@  class filestorage(object):
         self._index = []
         self._refreshindex()
 
+        self._flagprocessors = dict(flagutil.flagprocessors)
+
     def _refreshindex(self):
         self._indexbynode.clear()
         self._indexbyrev.clear()
@@ -261,45 +265,6 @@  class filestorage(object):
 
         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)