# HG changeset patch # User Manuel Jacob <m...@manueljacob.de> # Date 1554419835 -7200 # Fri Apr 05 01:17:15 2019 +0200 # Node ID fb4b7793a71ec639bd567f3b088719a0fc16f9c8 # Parent 4931cc804f7a17c5a7b8cbf6b6a724930d7c47b7 # EXP-Topic hgweb-obsolete # Available At https://bitbucket.org/octobus/mercurial-devel/ # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fb4b7793a71e hidden: add support for --remote-hidden to http peer
This is the client side code putting the previous changeset to use. This makes the --remote-hidden flag works for http peers. Test written by Pierre-Yves David. diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -109,7 +109,7 @@ class _multifile(object): self._index = 0 def makev1commandrequest(ui, requestbuilder, caps, capablefn, - repobaseurl, cmd, args): + repobaseurl, cmd, args, remotehidden=False): """Make an HTTP request to run a command for a version 1 client. ``caps`` is a set of known server capabilities. The value may be @@ -127,6 +127,8 @@ def makev1commandrequest(ui, requestbuil ui.debug("sending %s command\n" % cmd) q = [('cmd', cmd)] + if remotehidden: + q.append(('access-hidden', '1')) headersize = 0 # Important: don't use self.capable() here or else you end up # with infinite recursion when trying to look up capabilities @@ -377,13 +379,15 @@ def parsev1commandresponse(ui, baseurl, return respurl, proto, resp class httppeer(wireprotov1peer.wirepeer): - def __init__(self, ui, path, url, opener, requestbuilder, caps): + def __init__(self, ui, path, url, opener, requestbuilder, caps, + remotehidden=False): self.ui = ui self._path = path self._url = url self._caps = caps self._urlopener = opener self._requestbuilder = requestbuilder + self._remotehidden = remotehidden def __del__(self): for h in self._urlopener.handlers: @@ -399,11 +403,7 @@ class httppeer(wireprotov1peer.wirepeer) return None def peer(self, remotehidden=False): - if remotehidden: - msg = _("ignoring `--remote-hidden` request\n" - "(access to hidden changeset for http peers not " - "supported yet)\n") - self.ui.warn(msg) + assert remotehidden == self._remotehidden return self def canpush(self): @@ -434,7 +434,8 @@ class httppeer(wireprotov1peer.wirepeer) req, cu, qs = makev1commandrequest(self.ui, self._requestbuilder, self._caps, self.capable, - self._url, cmd, args) + self._url, cmd, args, + self._remotehidden) resp = sendrequest(self.ui, self._urlopener, req) @@ -756,7 +757,12 @@ class httpv2executor(object): @interfaceutil.implementer(repository.ipeerv2) class httpv2peer(object): def __init__(self, ui, repourl, apipath, opener, requestbuilder, - apidescriptor): + apidescriptor, remotehidden=False): + if remotehidden: + msg = _("ignoring `--remote-hidden` request\n" + "(access to hidden changeset for http peers (v2) not " + "supported yet)\n") + ui.warn(msg) self.ui = ui self.apidescriptor = apidescriptor @@ -782,7 +788,7 @@ class httpv2peer(object): def peer(self, remotehidden=False): if remotehidden: msg = _("ignoring `--remote-hidden` request\n" - "(access to hidden changeset for http peers not " + "(access to hidden changeset for http peers (v2) not " "supported yet)\n") self.ui.warn(msg) return self @@ -958,11 +964,6 @@ def makepeer(ui, path, opener=None, requ ``requestbuilder`` is the type used for constructing HTTP requests. It exists as an argument so extensions can override the default. """ - if remotehidden: - msg = _("ignoring `--remote-hidden` request\n" - "(access to hidden changeset for http peers not " - "supported yet)\n") - ui.warn(msg) u = util.url(path) if u.query or u.fragment: raise error.Abort(_('unsupported URL component: "%s"') % @@ -996,11 +997,12 @@ def makepeer(ui, path, opener=None, requ return API_PEERS[service]['init'](ui, respurl, apipath, opener, requestbuilder, - info['apis'][service]) + info['apis'][service], + remotehidden=remotehidden) # Failed to construct an API peer. Fall back to legacy. return httppeer(ui, path, respurl, opener, requestbuilder, - info['v1capabilities']) + info['v1capabilities'], remotehidden=remotehidden) def instance(ui, path, create, intents=None, createopts=None, remotehidden=False): 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 @@ -210,6 +210,100 @@ Hidden changeset are still hidden despit revision: 2 revision: 0 +Test --remote-hidden for http peer +---------------------------------- + + $ hg clone --pull http://localhost:$HGPORT client-http + 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-http 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-http pull -r be215fbb8c50 + pulling from http://localhost:$HGPORT/ + abort: filtered revision 'be215fbb8c50' (not in 'served' subset)! + [255] + +pulling an hidden changeset with --remote-hidden should succeed: + + $ hg -R client-http pull --remote-hidden -r be215fbb8c50 + pulling from http://localhost:$HGPORT/ + 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-http 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-http pull --remote-hidden -r 8d28cbe335f3 + pulling from http://localhost:$HGPORT/ + abort: filtered revision '8d28cbe335f3' (not in 'served.hidden' subset)! + [255] + +secret hidden: + + $ hg -R client-http pull --remote-hidden -r 1c6afd79eb66 + pulling from http://localhost:$HGPORT/ + abort: filtered revision '1c6afd79eb66' (not in 'served.hidden' subset)! + [255] + +Same check on a server that do not allow hidden access: +``````````````````````````````````````````````````````` + + $ hg clone --pull http://localhost:$HGPORT1 client-http2 + 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-http2 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-http2 pull -r be215fbb8c50 + pulling from http://localhost:$HGPORT1/ + abort: filtered revision 'be215fbb8c50' (not in 'served' subset)! + [255] + +pulling an hidden changeset with --remote-hidden should fail too: + + $ hg -R client-http2 pull --remote-hidden -r be215fbb8c50 + pulling from http://localhost:$HGPORT1/ + abort: filtered revision 'be215fbb8c50' (not in 'served' subset)! + [255] + ============= Final cleanup ============= _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel