repoview: introduce a `experimental.extra-filter-revs` config
The option define revisions to additionally filter out of all repository "view".
The end goal is to provide and easy to way to serve multiple subset of the same
repository using multiple "shares".
The simplest use case of this feature is to have one view serving the public
changesets and one view also serving the draft. This is currently achievable
using the new `server.view` option introduced recently by Joerg Sonnenberger.
However, more advanced use cases need more advanced definitions. For example
some needs a view dedicated to some release branches, or view that hides
security fixes to be released. Joerg Sonnenberger and I discussed this topic at
the recent mini-sprint and the both of us have seen real life use cases for
this. (This series got written during the same mini-sprint).
The feature is fully functional, and use similar cache-fallback mechanism to
ensure decent performance. However,there remaining room to ensure each share
caches and hooks collaborate with each others. This will come at a later time
once users start to actually test this feature on real usecase.
--- a/mercurial/configitems.py Wed Apr 17 23:10:29 2019 -0700
+++ b/mercurial/configitems.py Sat Apr 06 17:46:19 2019 +0200
@@ -532,6 +532,13 @@
coreconfigitem('experimental', 'evolution.track-operation',
default=True,
)
+# repo-level config to exclude a revset visibility
+#
+# The target use case is to use `share` to expose different subset of the same
+# repository, especially server side. See also `server.view`.
+coreconfigitem('experimental', 'extra-filter-revs',
+ default=None,
+)
coreconfigitem('experimental', 'maxdeltachainspan',
default=-1,
)
--- a/mercurial/localrepo.py Wed Apr 17 23:10:29 2019 -0700
+++ b/mercurial/localrepo.py Sat Apr 06 17:46:19 2019 +0200
@@ -1050,6 +1050,8 @@
# Signature to cached matcher instance.
self._sparsematchercache = {}
+ self._extrafilterid = repoview.extrafilter(ui)
+
def _getvfsward(self, origfunc):
"""build a ward for self.vfs"""
rref = weakref.ref(self)
@@ -1197,6 +1199,9 @@
In other word, there is always only one level of `repoview` "filtering".
"""
+ if self._extrafilterid is not None and '%' not in name:
+ name = name + '%' + self._extrafilterid
+
cls = repoview.newtype(self.unfiltered().__class__)
return cls(self, name, visibilityexceptions)
--- a/mercurial/repoview.py Wed Apr 17 23:10:29 2019 -0700
+++ b/mercurial/repoview.py Sat Apr 06 17:46:19 2019 +0200
@@ -17,6 +17,10 @@
phases,
pycompat,
tags as tagsmod,
+ util,
+)
+from .utils import (
+ repoviewutil,
)
def hideablerevs(repo):
@@ -154,6 +158,35 @@
'immutable': computemutable,
'base': computeimpactable}
+_basefiltername = list(filtertable)
+
+def extrafilter(ui):
+ """initialize extra filter and return its id
+
+ If extra filtering is configured, we make sure the associated filtered view
+ are declared and return the associated id.
+ """
+ frevs = ui.config('experimental', 'extra-filter-revs')
+ if frevs is None:
+ return None
+
+ fid = pycompat.sysbytes(util.DIGESTS['sha1'](frevs).hexdigest())[:12]
+
+ combine = lambda fname: fname + '%' + fid
+
+ subsettable = repoviewutil.subsettable
+
+ if combine('base') not in filtertable:
+ for name in _basefiltername:
+ def extrafilteredrevs(repo, *args, **kwargs):
+ baserevs = filtertable[name](repo, *args, **kwargs)
+ extrarevs = frozenset(repo.revs(frevs))
+ return baserevs | extrarevs
+ filtertable[combine(name)] = extrafilteredrevs
+ if name in subsettable:
+ subsettable[combine(name)] = combine(subsettable[name])
+ return fid
+
def filterrevs(repo, filtername, visibilityexceptions=None):
"""returns set of filtered revision for this filter name
--- a/mercurial/statichttprepo.py Wed Apr 17 23:10:29 2019 -0700
+++ b/mercurial/statichttprepo.py Sat Apr 06 17:46:19 2019 +0200
@@ -155,6 +155,7 @@
self.names = namespaces.namespaces()
self.filtername = None
+ self._extrafilterid = None
try:
requirements = set(self.vfs.read(b'requires').splitlines())
--- a/tests/test-server-view.t Wed Apr 17 23:10:29 2019 -0700
+++ b/tests/test-server-view.t Sat Apr 06 17:46:19 2019 +0200
@@ -34,5 +34,29 @@
date: Thu Jan 01 00:00:00 1970 +0000
summary: r0
+
+Check same result using `experimental.extra-filter-revs`
+
+ $ hg -R test --config experimental.extra-filter-revs='not public()' serve -p $HGPORT1 -d --pid-file=hg2.pid -E errors.log
+ $ cat hg2.pid >> $DAEMON_PIDS
+ $ hg -R test2 incoming http://foo:xyzzy@localhost:$HGPORT1/
+ comparing with http://foo:***@localhost:$HGPORT1/
+ changeset: 0:1ea73414a91b
+ tag: tip
+ user: debugbuilddag
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: r0
+
+ $ hg -R test --config experimental.extra-filter-revs='not public()' debugupdatecache
+ $ ls -1 test/.hg/cache/
+ branch2-base%89c45d2fa07e
+ branch2-served
+ rbc-names-v1
+ rbc-revs-v1
+ tags2
+ tags2-served%89c45d2fa07e
+
+cleanup
+
$ cat errors.log
$ killdaemons.py