changeset 42138:caebe5e7f4bd

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 12 Apr 2019 15:41:32 +0200
parents d086ba387ae8
children 08481e11462e
files contrib/perf.py mercurial/branchmap.py mercurial/repoview.py mercurial/utils/repoviewutil.py tests/check-perf-code.py
diffstat 5 files changed, 36 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Fri Feb 01 15:51:02 2019 +0100
+++ b/contrib/perf.py	Fri Apr 12 15:41:32 2019 +0200
@@ -94,6 +94,10 @@
 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 @@
     # 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
--- a/mercurial/branchmap.py	Fri Feb 01 15:51:02 2019 +0100
+++ b/mercurial/branchmap.py	Fri Apr 12 15:41:32 2019 +0200
@@ -23,28 +23,17 @@
     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.hidden': 'served',
-               'served': 'immutable',
-               'immutable': 'base'}
-
-
 class BranchMapCache(object):
     """mapping of filtered views of repo with their branchcache"""
     def __init__(self):
--- a/mercurial/repoview.py	Fri Feb 01 15:51:02 2019 +0100
+++ b/mercurial/repoview.py	Fri Apr 12 15:41:32 2019 +0200
@@ -25,9 +25,9 @@
     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)
@@ -144,7 +144,7 @@
 # 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,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/utils/repoviewutil.py	Fri Apr 12 15:41:32 2019 +0200
@@ -0,0 +1,22 @@
+# repoviewutil.py - constaints data relevant to repoview.py and other module
+#
+# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
+#                Logilab SA        <contact@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.hidden': 'served',
+               'served': 'immutable',
+               'immutable': 'base'}
--- a/tests/check-perf-code.py	Fri Feb 01 15:51:02 2019 +0100
+++ b/tests/check-perf-code.py	Fri Apr 12 15:41:32 2019 +0200
@@ -10,7 +10,7 @@
 # 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"),