wireproto: in batch queries, support queries with immediate responses
authorValentin Gatien-Baron <valentin.gatienbaron@gmail.com>
Mon, 24 Dec 2018 14:04:16 -0500
changeset 41055 55e8da487b8a
parent 41054 ef54bd33b476
child 41056 41cd64a81dd9
wireproto: in batch queries, support queries with immediate responses listkeys and pushkey return without querying the remote when the remote doesn't support such queries. Before this change, the batching code didn't handle this convention, resulting in this kind of error: $ hg pull ssh://user@dummy/repo1 -r tip -B a pulling from ssh://user@dummy/repo1 remote: ** Unknown exception encountered with possibly-broken third-party extension disable-lookup remote: ** which supports versions unknown of Mercurial. remote: ** Please disable disable-lookup and try your action again. remote: ** If that fixes the bug please report it to the extension author. remote: ** Python 2.7.15+ (default, Oct 2 2018, 22:12:08) [GCC 8.2.0] remote: ** Mercurial Distributed SCM (version 4.8.1+586-ef54bd33b476+20181224) remote: ** Extensions loaded: disable-lookup remote: Traceback (most recent call last): remote: File "/tmp/hgtests.i66Npc/install/bin/hg", line 43, in <module> remote: dispatch.run() remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 99, in run remote: status = dispatch(req) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 225, in dispatch remote: ret = _runcatch(req) or 0 remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 376, in _runcatch remote: return _callcatch(ui, _runcatchfunc) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 384, in _callcatch remote: return scmutil.callcatch(ui, func) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/scmutil.py", line 166, in callcatch remote: return func() remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 367, in _runcatchfunc remote: return _dispatch(req) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1021, in _dispatch remote: cmdpats, cmdoptions) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 756, in runcommand remote: ret = _runcommand(ui, options, cmd, d) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1030, in _runcommand remote: return cmdfunc() remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/dispatch.py", line 1018, in <lambda> remote: d = lambda: util.checksignature(func)(ui, *args, **strcmdopt) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/util.py", line 1670, in check remote: return func(*args, **kwargs) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/commands.py", line 5257, in serve remote: s.serve_forever() remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 797, in serve_forever remote: self.serveuntil(threading.Event()) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 804, in serveuntil remote: _runsshserver(self._ui, self._repo, self._fin, self._fout, ev) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotoserver.py", line 656, in _runsshserver remote: rsp = wireprotov1server.dispatch(repo, proto, request) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotov1server.py", line 74, in dispatch remote: return func(repo, proto, *args) remote: File "/tmp/hgtests.i66Npc/install/lib/python/mercurial/wireprotov1server.py", line 195, in batch remote: data[k] = vals[k] remote: KeyError: 'namespace' abort: unexpected response: empty string [255] Differential Revision: https://phab.mercurial-scm.org/D5482
mercurial/wireprotov1peer.py
tests/test-missing-capability.t
--- a/mercurial/wireprotov1peer.py	Tue Dec 04 11:05:06 2018 +0100
+++ b/mercurial/wireprotov1peer.py	Mon Dec 24 14:04:16 2018 -0500
@@ -240,13 +240,16 @@
 
             # Encoded arguments and future holding remote result.
             try:
-                encodedargs, fremote = next(batchable)
+                encargsorres, fremote = next(batchable)
             except Exception:
                 pycompat.future_set_exception_info(f, sys.exc_info()[1:])
                 return
 
-            requests.append((command, encodedargs))
-            states.append((command, f, batchable, fremote))
+            if not fremote:
+                f.set_result(encargsorres)
+            else:
+                requests.append((command, encargsorres))
+                states.append((command, f, batchable, fremote))
 
         if not requests:
             return
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-missing-capability.t	Mon Dec 24 14:04:16 2018 -0500
@@ -0,0 +1,46 @@
+Checking how hg behaves when one side of a pull/push doesn't support
+some capability (because it's running an older hg version, usually).
+
+  $ hg init repo1
+  $ cd repo1
+  $ echo a > a; hg add -q a; hg commit -q -m a
+  $ hg bookmark a
+  $ hg clone -q . ../repo2
+  $ cd ../repo2
+
+  $ touch $TESTTMP/disable-lookup.py
+  $ disable_cap() {
+  >   rm -f $TESTTMP/disable-lookup.pyc # pyc caching is buggy
+  >   cat <<EOF > $TESTTMP/disable-lookup.py
+  > from mercurial import extensions, wireprotov1server
+  > def wcapabilities(orig, *args, **kwargs):
+  >   cap = orig(*args, **kwargs)
+  >   cap.remove('$1')
+  >   return cap
+  > extensions.wrapfunction(wireprotov1server, '_capabilities', wcapabilities)
+  > EOF
+  > }
+  $ cat >> ../repo1/.hg/hgrc <<EOF
+  > [extensions]
+  > disable-lookup = $TESTTMP/disable-lookup.py
+  > EOF
+  $ cat >> .hg/hgrc <<EOF
+  > [ui]
+  > ssh = "$PYTHON" "$TESTDIR/dummyssh"
+  > EOF
+
+  $ hg pull ssh://user@dummy/repo1 -r tip -B a
+  pulling from ssh://user@dummy/repo1
+  no changes found
+
+  $ disable_cap lookup
+  $ hg pull ssh://user@dummy/repo1 -r tip -B a
+  pulling from ssh://user@dummy/repo1
+  abort: other repository doesn't support revision lookup, so a rev cannot be specified.
+  [255]
+
+  $ disable_cap pushkey
+  $ hg pull ssh://user@dummy/repo1 -r tip -B a
+  pulling from ssh://user@dummy/repo1
+  abort: remote bookmark a not found!
+  [255]