[PATCH 4 of 9] flagutil: move insertflagprocessor to the new module (API)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Aug 7 21:47:20 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1565220337 -7200
#      Thu Aug 08 01:25:37 2019 +0200
# Node ID c446e19887223d1e7299ea6123b408564f3832d9
# Parent  c084756962a2c842af5dc0e23cc67234e4fb1d59
# EXP-Topic flag-processors
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c446e1988722
flagutil: move insertflagprocessor to the new module (API)

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -150,19 +150,7 @@ 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, flagutil.flagprocessors)
-
-def _insertflagprocessor(flag, processor, flagprocessors):
-    if not flag & flagutil.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:
-        msg = _("cannot register multiple processors on flag '%#x'.") % (flag)
-        raise error.Abort(msg)
-    flagprocessors[flag] = processor
+    flagutil.insertflagprocessor(flag, processor, flagutil.flagprocessors)
 
 def getoffset(q):
     return int(q >> 16)
@@ -438,7 +426,7 @@ class revlog(object):
 
         # revlog v0 doesn't have flag processors
         for flag, processor in opts.get(b'flagprocessors', {}).iteritems():
-            _insertflagprocessor(flag, processor, self._flagprocessors)
+            flagutil.insertflagprocessor(flag, processor, self._flagprocessors)
 
         if self._chunkcachesize <= 0:
             raise error.RevlogError(_('revlog chunk cache size %r is not '
diff --git a/mercurial/revlogutils/flagutil.py b/mercurial/revlogutils/flagutil.py
--- a/mercurial/revlogutils/flagutil.py
+++ b/mercurial/revlogutils/flagutil.py
@@ -8,6 +8,8 @@
 
 from __future__ import absolute_import
 
+from ..i18n import _
+
 from .constants import (
     REVIDX_DEFAULT_FLAGS,
     REVIDX_ELLIPSIS,
@@ -18,6 +20,7 @@ from .constants import (
 )
 
 from .. import (
+    error,
     util
 )
 
@@ -37,3 +40,14 @@ flagprocessors = {
     REVIDX_ISCENSORED: None,
 }
 
+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:
+        msg = _("cannot register multiple processors on flag '%#x'.") % (flag)
+        raise error.Abort(msg)
+    flagprocessors[flag] = processor
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -206,8 +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, flagutil.flagprocessors)
-    File "*/mercurial/revlog.py", line *, in _insertflagprocessor (glob)
+      flagutil.insertflagprocessor(flag, processor, flagutil.flagprocessors)
+    File "*/mercurial/revlogutils/flagutil.py", line *, in insertflagprocessor (glob)
       raise error.Abort(msg)
   mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !)
   Abort: cannot register multiple processors on flag '0x8'. (no-py3 !)


More information about the Mercurial-devel mailing list