Patchwork [1,of,3,V2] repoview: move subsettable in a dedicated module

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2019, 6:26 p.m.
Message ID <56e2557a9401a3b3c609.1555439178@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/39663/
State Accepted
Headers show

Comments

Pierre-Yves David - April 16, 2019, 6:26 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1555076492 -7200
#      Fri Apr 12 15:41:32 2019 +0200
# Node ID 56e2557a9401a3b3c60956b86860c84fb2e1330a
# Parent  2003f0bffcb197699b6665939e21a681f9c73570
# EXP-Topic repoview
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 56e2557a9401
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.
Pulkit Goyal - April 16, 2019, 10:14 p.m.
On Tue, Apr 16, 2019 at 11:56 PM Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1555076492 -7200
> #      Fri Apr 12 15:41:32 2019 +0200
> # Node ID 56e2557a9401a3b3c60956b86860c84fb2e1330a
> # Parent  2003f0bffcb197699b6665939e21a681f9c73570
> # EXP-Topic repoview
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 56e2557a9401
> 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.
>

Queued 1 and 3. Many thanks!
Pierre-Yves David - April 16, 2019, 10:52 p.m.
On 4/17/19 12:14 AM, Pulkit Goyal wrote:
> 
> On Tue, Apr 16, 2019 at 11:56 PM Pierre-Yves David 
> <pierre-yves.david@ens-lyon.org <mailto:pierre-yves.david@ens-lyon.org>> 
> wrote:
> 
>     # HG changeset patch
>     # User Pierre-Yves David <pierre-yves.david@octobus.net
>     <mailto:pierre-yves.david@octobus.net>>
>     # Date 1555076492 -7200
>     #      Fri Apr 12 15:41:32 2019 +0200
>     # Node ID 56e2557a9401a3b3c60956b86860c84fb2e1330a
>     # Parent  2003f0bffcb197699b6665939e21a681f9c73570
>     # EXP-Topic repoview
>     # Available At https://bitbucket.org/octobus/mercurial-devel/
>     #              hg pull
>     https://bitbucket.org/octobus/mercurial-devel/ -r 56e2557a9401
>     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.
> 
> 
> Queued 1 and 3. Many thanks!

Discussing on IRC with pulkit, he did not had time to fully grasp the 
concept around path 2. I am going to sent it as (untouched) as V3 for 
clarify. Still according to this IRC conversion, other reviewers are 
encouraged to look at it.

Having the experimental in 5.0 would help to start wider testing make a 
difference on our side.

Cheers,

Patch

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,28 +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.hidden': '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)
@@ -144,7 +144,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,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'}
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"),