[PATCH] repoview: introduce "served-obsolete" filter for serving obsolete changesets

Anton Shestakov av6 at dwimlabs.net
Tue Mar 5 00:58:43 EST 2019


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1551763152 -28800
#      Tue Mar 05 13:19:12 2019 +0800
# Node ID b6636687c713bf3c4b4c246b0e8759061d6e6742
# Parent  82d9728ace9535057d77df6c920385861ec00072
repoview: introduce "served-obsolete" filter for serving obsolete changesets

This filter allows viewing and pulling obsolete changesets (e.g. through
hgweb), but still doesn't allow secret commits to be seen. In other words, this
is "served" plus obsolete commits, hence the name.

Based on a patch by Boris Feld.

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -40,6 +40,7 @@ unpack_from = struct.unpack_from
 subsettable = {None: 'visible',
                'visible-hidden': 'visible',
                'visible': 'served',
+               'served-obsolete': 'served',
                'served': 'immutable',
                'immutable': 'base'}
 
diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -86,6 +86,14 @@ def computehidden(repo, visibilityexcept
         _revealancestors(pfunc, hidden, visible)
     return frozenset(hidden)
 
+def computesecret(repo, visibilityexceptions=None):
+    """compute the set of secret (plus archived, etc) revisions to filter
+
+    Changesets in the secret (and higher) phase should stay inaccessible."""
+    assert not repo.changelog.filteredrevs
+    secrets = repo._phasecache.getrevset(repo, phases.remotehiddenphases)
+    return frozenset(secrets)
+
 def computeunserved(repo, visibilityexceptions=None):
     """compute the set of revision that should be filtered when used a server
 
@@ -141,6 +149,7 @@ def computeimpactable(repo, visibilityex
 # from scratch (very slow).
 filtertable = {'visible': computehidden,
                'visible-hidden': computehidden,
+               'served-obsolete': computesecret,
                'served': computeunserved,
                'immutable':  computemutable,
                'base':  computeimpactable}
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1651,3 +1651,53 @@ Test issue 5783
   d1b09fe3ad2b2a03e23a72f0c582e29a49570145 1a1a11184d2588af24e767e5335d5d9d07e8c550 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'note': 'Testing::Obsstore', 'operation': 'amend', 'user': 'test'}
   1bfd8e3868f641e048b6667cd672c68932f26d00 79959ca316d5b27ac6be1dd0cfd0843a5b5412eb 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'note': 'Testing::Obsstore2', 'operation': 'amend', 'user': 'test'}
   $ cd ..
+
+#if serve
+
+Testing web.view = served-obsolete
+
+  $ hg init test-served-obsolete
+  $ cd test-served-obsolete
+  $ echo 'internal-phase' >> .hg/requires
+
+  $ echo 0 > a
+  $ hg ci -qAm 0
+  $ hg phase --public
+  $ echo 1 > a
+  $ hg ci -m 1
+  $ echo 2 > a
+  $ hg ci -m 2 --amend
+  $ echo 3 > a
+  $ hg ci -m 3 --secret
+  $ echo 4 > a
+  $ hg ci -m 4 --config phases.new-commit=archived
+  $ echo 5 > a
+  $ hg ci -m 5 --config phases.new-commit=internal
+
+  $ hg log -G -T '{rev}: {phase}\n' --hidden
+  @  5: internal
+  |
+  o  4: archived
+  |
+  o  3: secret
+  |
+  o  2: draft
+  |
+  | x  1: draft
+  |/
+  o  0: public
+  
+  $ hg serve -p $HGPORT -d --pid-file hg.pid --config web.view=served-obsolete
+  $ cat hg.pid >> $DAEMON_PIDS
+
+changesets in secret and higher phases are not visible through hgweb
+
+  $ get-with-headers.py localhost:$HGPORT 'log?style=raw' | grep revision:
+  revision:    2
+  revision:    1
+  revision:    0
+
+  $ killdaemons.py
+  $ cd ..
+
+#endif


More information about the Mercurial-devel mailing list