Patchwork [4,of,4,V2] flagutil: use it in simplestorerepo

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 11, 2019, 11:10 a.m.
Message ID <4179d7904302083165af.1565521850@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41241/
State New
Headers show

Comments

Pierre-Yves David - Aug. 11, 2019, 11:10 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 4179d7904302083165af51c90096615d18ad77a9
# Parent  6f91ac3cb36e88b6308b8893c471c246f79deaf2
# EXP-Topic flag-processors
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4179d7904302
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.
Pierre-Yves David - Aug. 30, 2019, 8:42 a.m.
Gentle ping on this series. I need it to make further progress on other 
topics.

On 8/11/19 1:10 PM, Pierre-Yves David wrote:
> # 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 4179d7904302083165af51c90096615d18ad77a9
> # Parent  6f91ac3cb36e88b6308b8893c471c246f79deaf2
> # EXP-Topic flag-processors
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4179d7904302
> 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.
> 
> 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)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

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)