Patchwork [1,of,2,V4] revlog: allow flag processors to be applied via store options

login
register
mail settings
Submitter Matt Harbison
Date Oct. 13, 2018, 5:30 p.m.
Message ID <222cf88a686a2fb818c4.1539451808@Envy>
Download mbox | patch
Permalink /patch/35942/
State Accepted
Headers show

Comments

Matt Harbison - Oct. 13, 2018, 5:30 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1539136401 14400
#      Tue Oct 09 21:53:21 2018 -0400
# Node ID 222cf88a686a2fb818c4c440250be10625b4fdeb
# Parent  8f192f2c4a1e04ac69dec66c48efcb96bc738533
revlog: allow flag processors to be applied via store options

This allows flag processors to be registered to specific repos in an extension
by wrapping localrepo.resolverevlogstorevfsoptions().  I wanted to add the
processors via a function on localrepo, but some of the places where the
processors are globally registered don't have a repository available.  This
makes targeting specific repos in the wrapper awkward, but still manageable.
Yuya Nishihara - Oct. 14, 2018, 4:40 a.m.
On Sat, 13 Oct 2018 13:30:08 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1539136401 14400
> #      Tue Oct 09 21:53:21 2018 -0400
> # Node ID 222cf88a686a2fb818c4c440250be10625b4fdeb
> # Parent  8f192f2c4a1e04ac69dec66c48efcb96bc738533
> revlog: allow flag processors to be applied via store options

Queued, many thanks.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -708,6 +708,7 @@  def resolverevlogstorevfsoptions(ui, req
     """Resolve opener options specific to revlogs."""
 
     options = {}
+    options[b'flagprocessors'] = {}
 
     if b'revlogv1' in requirements:
         options[b'revlogv1'] = True
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -151,16 +151,19 @@  def addflagprocessor(flag, processor):
       debug commands. In this case the transform only indicates whether the
       contents can be used for hash integrity checks.
     """
+    _insertflagprocessor(flag, processor, _flagprocessors)
+
+def _insertflagprocessor(flag, processor, flagprocessors):
     if not flag & REVIDX_KNOWN_FLAGS:
         msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
         raise error.ProgrammingError(msg)
     if flag not in REVIDX_FLAGS_ORDER:
         msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % (flag)
         raise error.ProgrammingError(msg)
-    if flag in _flagprocessors:
+    if flag in flagprocessors:
         msg = _("cannot register multiple processors on flag '%#x'.") % (flag)
         raise error.Abort(msg)
-    _flagprocessors[flag] = processor
+    flagprocessors[flag] = processor
 
 def getoffset(q):
     return int(q >> 16)
@@ -408,6 +411,10 @@  class revlog(object):
             if opts.get('enableellipsis'):
                 self._flagprocessors[REVIDX_ELLIPSIS] = ellipsisprocessor
 
+            # revlog v0 doesn't have flag processors
+            for flag, processor in opts.get(b'flagprocessors', {}).iteritems():
+                _insertflagprocessor(flag, processor, self._flagprocessors)
+
         if self._chunkcachesize <= 0:
             raise error.RevlogError(_('revlog chunk cache size %r is not '
                                       'greater than 0') % self._chunkcachesize)
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -206,6 +206,8 @@  Ensure the data got to the server OK
     File "*/tests/flagprocessorext.py", line *, in extsetup (glob)
       validatehash,
     File "*/mercurial/revlog.py", line *, in addflagprocessor (glob)
+      _insertflagprocessor(flag, processor, _flagprocessors)
+    File "*/mercurial/revlog.py", line *, in _insertflagprocessor (glob)
       raise error.Abort(msg)
   Abort: cannot register multiple processors on flag '0x8'.
   *** failed to set up extension duplicate: cannot register multiple processors on flag '0x8'.