Patchwork repoview: introduce "served-obsolete" filter for serving obsolete changesets

login
register
mail settings
Submitter Anton Shestakov
Date March 5, 2019, 5:58 a.m.
Message ID <b6636687c713bf3c4b4c.1551765523@neuro>
Download mbox | patch
Permalink /patch/39059/
State New
Headers show

Comments

Anton Shestakov - March 5, 2019, 5:58 a.m.
# HG changeset patch
# User Anton Shestakov <av6@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.
Pulkit Goyal - March 15, 2019, 1:59 p.m.
On Tue, Mar 5, 2019 at 9:00 AM Anton Shestakov <av6@dwimlabs.net> wrote:

> # HG changeset patch
> # User Anton Shestakov <av6@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.
>

Is this also equivalent to (unfiltered-secret) commits?
Anton Shestakov - March 16, 2019, 3:40 p.m.
On Fri, 15 Mar 2019 16:59:22 +0300
Pulkit Goyal <7895pulkit@gmail.com> wrote:

> On Tue, Mar 5, 2019 at 9:00 AM Anton Shestakov <av6@dwimlabs.net> wrote:
> 
> > # HG changeset patch
> > # User Anton Shestakov <av6@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.
> >  
> 
> Is this also equivalent to (unfiltered-secret) commits?

Is "unfiltered-secret" an actual thing that exists? I couldn't find
anything with that name in hg. If it's a pseudo-revset, then yes,
"served-obsolete" is all changesets (unfiltered repo) minus secret
(that includes archived and internal).

"served-obsolete" is not "served" minus "obsolete", however: it's
served plus obsolete. I don't know if "served+obsolete" is a better
name, but test-obsolete.t passes with either of them.

Patch

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