[PATCH 3 of 5 "] repoview: move subsettable in a dedicated module

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Apr 12 10:45:05 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1555076492 -7200
#      Fri Apr 12 15:41:32 2019 +0200
# Node ID 664b1ddfcfaa6a3bcd5350b1a7633d9903fdab1a
# Parent  74e8982a8943c78c332699aa2a109ba10be0fdc2
# EXP-Topic repoview
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 664b1ddfcfaa
repoview: move subsettable in a dedicated module

The dictionary got moved in `branchmap` to avoid import cycle. However, we are
about to needs it in repoview too. So we introduce a now module to define that
that mapping.

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -94,6 +94,10 @@ try:
 except ImportError:
     pass
 try:
+    from mercurial.utils import repoviewutil # since 5.0
+except ImportError:
+    repoviewutil = None
+try:
     from mercurial import scmutil # since 1.9 (or 8b252e826c68)
 except ImportError:
     pass
@@ -471,7 +475,8 @@ def getbranchmapsubsettable():
     # subsettable is defined in:
     # - branchmap since 2.9 (or 175c6fd8cacc)
     # - repoview since 2.5 (or 59a9f18d4587)
-    for mod in (branchmap, repoview):
+    # - repoviewutil since 5.0
+    for mod in (branchmap, repoview, repoviewutil):
         subsettable = getattr(mod, 'subsettable', None)
         if subsettable:
             return subsettable
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -23,27 +23,17 @@ from . import (
     util,
 )
 from .utils import (
+    repoviewutil,
     stringutil,
 )
 
+subsettable = repoviewutil. subsettable
+
 calcsize = struct.calcsize
 pack_into = struct.pack_into
 unpack_from = struct.unpack_from
 
 
-### Nearest subset relation
-# Nearest subset of filter X is a filter Y so that:
-# * Y is included in X,
-# * X - Y is as small as possible.
-# This create and ordering used for branchmap purpose.
-# the ordering may be partial
-subsettable = {None: 'visible',
-               'visible-hidden': 'visible',
-               'visible': 'served',
-               'served': 'immutable',
-               'immutable': 'base'}
-
-
 class BranchMapCache(object):
     """mapping of filtered views of repo with their branchcache"""
     def __init__(self):
diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -25,9 +25,9 @@ def hideablerevs(repo):
     This is a standalone function to allow extensions to wrap it.
 
     Because we use the set of immutable changesets as a fallback subset in
-    branchmap (see mercurial.branchmap.subsettable), you cannot set "public"
-    changesets as "hideable". Doing so would break multiple code assertions and
-    lead to crashes."""
+    branchmap (see mercurial.utils.repoviewutils.subsettable), you cannot set
+    "public" changesets as "hideable". Doing so would break multiple code
+    assertions and lead to crashes."""
     obsoletes = obsolete.getrevs(repo, 'obsolete')
     internals = repo._phasecache.getrevset(repo, phases.localhiddenphases)
     internals = frozenset(internals)
@@ -136,7 +136,7 @@ def computeimpactable(repo, visibilityex
 # function to compute filtered set
 #
 # When adding a new filter you MUST update the table at:
-#     mercurial.branchmap.subsettable
+#     mercurial.utils.repoviewutil.subsettable
 # Otherwise your filter will have to recompute all its branches cache
 # from scratch (very slow).
 filtertable = {'visible': computehidden,
diff --git a/mercurial/utils/repoviewutil.py b/mercurial/utils/repoviewutil.py
new file mode 100644
--- /dev/null
+++ b/mercurial/utils/repoviewutil.py
@@ -0,0 +1,21 @@
+# repoviewutil.py - constaints data relevant to repoview.py and other module
+#
+# Copyright 2012 Pierre-Yves David <pierre-yves.david at ens-lyon.org>
+#                Logilab SA        <contact at logilab.fr>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+### Nearest subset relation
+# Nearest subset of filter X is a filter Y so that:
+# * Y is included in X,
+# * X - Y is as small as possible.
+# This create and ordering used for branchmap purpose.
+# the ordering may be partial
+subsettable = {None: 'visible',
+               'visible-hidden': 'visible',
+               'visible': 'served',
+               'served': 'immutable',
+               'immutable': 'base'}
diff --git a/tests/check-perf-code.py b/tests/check-perf-code.py
--- a/tests/check-perf-code.py
+++ b/tests/check-perf-code.py
@@ -10,7 +10,7 @@ import sys
 # write static check patterns here
 perfpypats = [
   [
-    (r'(branchmap|repoview)\.subsettable',
+    (r'(branchmap|repoview|repoviewutil)\.subsettable',
      "use getbranchmapsubsettable() for early Mercurial"),
     (r'\.(vfs|svfs|opener|sopener)',
      "use getvfs()/getsvfs() for early Mercurial"),


More information about the Mercurial-devel mailing list