Patchwork [7,of,9] flagutil: use the new mixin use in remotefilelog

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 8, 2019, 1:47 a.m.
Message ID <2e87598264f883b252a3.1565228843@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41218/
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 1565219856 -7200
#      Thu Aug 08 01:17:36 2019 +0200
# Node ID 2e87598264f883b252a39664f2e2618e9de13e42
# Parent  466943d2fed3602e08ac9117afef1c727bcb98a5
# EXP-Topic flag-processors
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 2e87598264f8
flagutil: use the new mixin use in remotefilelog

This remove one of the code duplication. Hooray \o/.

Patch

diff --git a/hgext/remotefilelog/remotefilelog.py b/hgext/remotefilelog/remotefilelog.py
--- a/hgext/remotefilelog/remotefilelog.py
+++ b/hgext/remotefilelog/remotefilelog.py
@@ -25,6 +25,8 @@  from mercurial import (
 )
 from mercurial.utils import storageutil
 
+from mercurial.revlogutils import flagutil
+
 from . import (
     constants,
     fileserverclient,
@@ -45,7 +47,7 @@  class remotefilelognodemap(object):
             raise KeyError(node)
         return node
 
-class remotefilelog(object):
+class remotefilelog(flagutil.flagprocessorsmixin):
 
     _generaldelta = True
 
@@ -57,6 +59,8 @@  class remotefilelog(object):
 
         self.version = 1
 
+        self._flagprocessors = dict(flagutil.flagprocessors)
+
     def read(self, node):
         """returns the file contents at this node"""
         t = self.revision(node)
@@ -324,28 +328,6 @@  class remotefilelog(object):
         text, verifyhash = self._processflags(rawtext, flags, 'read')
         return text
 
-    def _processflags(self, text, flags, operation, raw=False):
-        # mostly copied from hg/mercurial/revlog.py
-        validatehash = True
-        orderedflags = revlog.REVIDX_FLAGS_ORDER
-        if operation == 'write':
-            orderedflags = reversed(orderedflags)
-        for flag in orderedflags:
-            if flag & flags:
-                vhash = True
-                if flag not in revlog._flagprocessors:
-                    message = _("missing processor for flag '%#x'") % (flag)
-                    raise revlog.RevlogError(message)
-                readfunc, writefunc, rawfunc = revlog._flagprocessors[flag]
-                if raw:
-                    vhash = rawfunc(self, text)
-                elif operation == 'read':
-                    text, vhash = readfunc(self, text)
-                elif operation == 'write':
-                    text, vhash = writefunc(self, text)
-                validatehash = validatehash and vhash
-        return text, validatehash
-
     def _read(self, id):
         """reads the raw file blob from disk, cache, or server"""
         fileservice = self.repo.fileservice