Patchwork [08,of,14,"] hidden: add support for --remote-hidden to localpeer

login
register
mail settings
Submitter Pierre-Yves David
Date April 13, 2019, 11:40 p.m.
Message ID <3ee63024cb9551aa025a.1555198838@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/39604/
State Accepted
Headers show

Comments

Pierre-Yves David - April 13, 2019, 11:40 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1554459112 -7200
#      Fri Apr 05 12:11:52 2019 +0200
# Node ID 3ee63024cb9551aa025a3126b88ecaf973c3fbaf
# Parent  302c42682e7dbc2c32ef60c07ed2e7d8e59c0ca6
# EXP-Topic hgweb-obsolete
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3ee63024cb95
hidden: add support for --remote-hidden to localpeer

We start with implementing support for hidden changesets access to the simplest
peer. The local one.

No specific access control is implemented because the user already have full
access to the full repository content on disk.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -209,14 +209,18 @@  class localcommandexecutor(object):
 class localpeer(repository.peer):
     '''peer for a local repo; reflects only the most recent API'''
 
-    def __init__(self, repo, caps=None):
+    def __init__(self, repo, caps=None, accesshidden=False):
         super(localpeer, self).__init__()
 
         if caps is None:
             caps = moderncaps.copy()
-        self._repo = repo.filtered('served')
+        if accesshidden:
+            self._repo = repo.filtered('served.hidden')
+        else:
+            self._repo = repo.filtered('served')
         self.ui = repo.ui
         self._caps = repo._restrictcapabilities(caps)
+        self._accesshidden = accesshidden
 
     # Begin of _basepeer interface.
 
@@ -227,11 +231,7 @@  class localpeer(repository.peer):
         return self._repo
 
     def peer(self, remotehidden=False):
-        if remotehidden:
-            msg = _("ignoring `--remote-hidden` request\n"
-                    "(access to hidden changeset for local peers not "
-                    "supported yet)\n")
-            self.ui.warn(msg)
+        assert remotehidden == self._accesshidden
         return self
 
     def canpush(self):
@@ -1175,12 +1175,8 @@  class localrepository(object):
         return False
 
     def peer(self, remotehidden=False):
-        if remotehidden:
-            msg = _("ignoring `--remote-hidden` request\n"
-                    "(access to hidden changeset for local peers not "
-                    "supported yet)\n")
-            self.ui.warn(msg)
-        return localpeer(self) # not cached to avoid reference cycle
+        # not cached to avoid reference cycle
+        return localpeer(self, accesshidden=remotehidden)
 
     def unfiltered(self):
         """Return unfiltered version of the repository
diff --git a/tests/test-remote-hidden.t b/tests/test-remote-hidden.t
--- a/tests/test-remote-hidden.t
+++ b/tests/test-remote-hidden.t
@@ -111,6 +111,67 @@  changesets in secret and higher phases a
 
   $ killdaemons.py
 
+Test --remote-hidden for local peer
+-----------------------------------
+
+  $ hg clone --pull repo-with-hidden client
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 1 files
+  2 new obsolescence markers
+  new changesets 5f354f46e585:c33affeb3f6b (1 drafts)
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg -R client log -G --hidden -v
+  @  1:c33affeb3f6b c_Amend_New [draft]
+  |
+  o  0:5f354f46e585 c_Public [public]
+  
+
+pulling an hidden changeset should fail:
+
+  $ hg -R client pull -r be215fbb8c50
+  pulling from $TESTTMP/repo-with-hidden
+  abort: filtered revision 'be215fbb8c50' (not in 'served' subset)!
+  [255]
+
+pulling an hidden changeset with --remote-hidden should succeed:
+
+  $ hg -R client pull --remote-hidden --traceback -r be215fbb8c50
+  pulling from $TESTTMP/repo-with-hidden
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  (1 other changesets obsolete on arrival)
+  (run 'hg heads' to see heads)
+  $ hg -R client log -G --hidden -v
+  x  2:be215fbb8c50 c_Amend_Old [draft]
+  |
+  | @  1:c33affeb3f6b c_Amend_New [draft]
+  |/
+  o  0:5f354f46e585 c_Public [public]
+  
+
+Pulling a secret changeset is still forbidden:
+
+secret visible:
+
+  $ hg -R client pull --remote-hidden -r 8d28cbe335f3
+  pulling from $TESTTMP/repo-with-hidden
+  abort: filtered revision '8d28cbe335f3' (not in 'served.hidden' subset)!
+  [255]
+
+secret hidden:
+
+  $ hg -R client pull --remote-hidden -r 1c6afd79eb66
+  pulling from $TESTTMP/repo-with-hidden
+  abort: filtered revision '1c6afd79eb66' (not in 'served.hidden' subset)!
+  [255]
+
 Test accessing hidden changeset through hgweb
 ---------------------------------------------