D2406: debugcommands: allow sending of simple commands with debugwireproto
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Feb 23 19:01:53 UTC 2018
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Previously, we only had support for low-level "raw" operations.
A goal of `hg debugwireproto` is to allow easily performing
higher-level primitives, such as sending a wire protocol command
and reading its response.
We implement a "command" action that does just this.
Currently, we only support simple commands (those without payloads).
We have basic support for sending command arguments. We don't yet
support sending dictionary arguments. This will be implemented later.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D2406
AFFECTED FILES
mercurial/debugcommands.py
CHANGE DETAILS
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2584,6 +2584,21 @@
Behaves like ``raw`` except flushes output afterwards.
+ command <X>
+ -----------
+
+ Send a request to run a named command, whose name follows the ``command``
+ string.
+
+ Arguments to the command are defined as lines in this block. The format of
+ each line is ``<key> <value>``. e.g.::
+
+ command listkeys
+ namespace bookmarks
+
+ Values are interpreted as Python b'' literals. This allows encoding
+ special byte sequences via backslash escaping.
+
close
-----
@@ -2683,6 +2698,24 @@
stdin.flush()
elif action == 'flush':
stdin.flush()
+ elif action.startswith('command'):
+ if not peer:
+ raise error.Abort(_('cannot send commands unless peer instance '
+ 'is available'))
+
+ command = action.split(' ', 1)[1]
+
+ args = {}
+ for line in lines:
+ fields = line.lstrip().split()
+ if len(fields) == 2:
+ key, value = fields
+ args[key] = ast.literal_eval(b'b"%s"' % value)
+ else:
+ raise error.Abort(_('value-less arguments not supported'))
+
+ peer._call(command, **args)
+
elif action == 'close':
peer.close()
elif action == 'readavailable':
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list