Patchwork [4,of,7] remotedebug: add the ability to request remote debug output

login
register
mail settings
Submitter Paul Morelle
Date June 20, 2018, 4:36 p.m.
Message ID <1130b3e74a6e618dfca6.1529512585@belenos.localdomain>
Download mbox | patch
Permalink /patch/32347/
State Accepted
Headers show

Comments

Paul Morelle - June 20, 2018, 4:36 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1529488678 -7200
#      Wed Jun 20 11:57:58 2018 +0200
# Node ID 1130b3e74a6e618dfca6b19988881c004a304091
# Parent  81edf3431b95d57257c690f7fe125c6676a78e18
# EXP-Topic remote-debug
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1130b3e74a6e
remotedebug: add the ability to request remote debug output

For now, this only works for ssh. As enabling debug output for all clients
might be a bit scary, we will introduce restrictions in the next changesets.
Support for other debug flags (--profile, --traceback) will be introduced
later.

Making it work for HTTP is possible but quite different. There is no process
living during the whole exchange, and many wire protocol commands are lacking
the appropriate side channel to transmit the debug output. For now we focus on
ironing out the feature in the case of ssh.

Patch

diff -r 81edf3431b95 -r 1130b3e74a6e mercurial/configitems.py
--- a/mercurial/configitems.py	Wed Jun 20 12:18:26 2018 +0200
+++ b/mercurial/configitems.py	Wed Jun 20 11:57:58 2018 +0200
@@ -339,6 +339,9 @@ 
 coreconfigitem('devel', 'legacy.exchange',
     default=list,
 )
+coreconfigitem('devel', 'remote.debug',
+    default=False,
+)
 coreconfigitem('devel', 'servercafile',
     default='',
 )
diff -r 81edf3431b95 -r 1130b3e74a6e mercurial/dispatch.py
--- a/mercurial/dispatch.py	Wed Jun 20 12:18:26 2018 +0200
+++ b/mercurial/dispatch.py	Wed Jun 20 11:57:58 2018 +0200
@@ -292,8 +292,12 @@ 
                 req.args[3] != '--stdio'):
                 unsafe()
             other_args = req.args[4:]
-            if other_args:
-                unsafe()
+            while other_args:
+                if other_args[0] == '--debug':
+                    # TODO: introduce user restriction
+                    other_args.pop(0)
+                else:
+                    unsafe()
 
         try:
             debugger = 'pdb'
diff -r 81edf3431b95 -r 1130b3e74a6e mercurial/sshpeer.py
--- a/mercurial/sshpeer.py	Wed Jun 20 12:18:26 2018 +0200
+++ b/mercurial/sshpeer.py	Wed Jun 20 11:57:58 2018 +0200
@@ -148,12 +148,11 @@ 
     Returns a tuple of (process, stdin, stdout, stderr) for the
     spawned process.
     """
-    cmd = '%s %s %s' % (
-        sshcmd,
-        args,
-        procutil.shellquote('%s -R %s serve --stdio' % (
-            _serverquote(remotecmd), _serverquote(path))))
-
+    serverspawn = '%s -R %s serve --stdio'
+    serverspawn %= (_serverquote(remotecmd), _serverquote(path))
+    if ui.configbool('devel', 'remote.debug'):
+        serverspawn += ' --debug'
+    cmd = '%s %s %s' % (sshcmd, args, procutil.shellquote(serverspawn))
     ui.debug('running %s\n' % cmd)
     cmd = procutil.quotecommand(cmd)
 
diff -r 81edf3431b95 -r 1130b3e74a6e tests/test-remote-debugging.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-remote-debugging.t	Wed Jun 20 11:57:58 2018 +0200
@@ -0,0 +1,68 @@ 
+Test remote debugging capabilities
+==================================
+
+Setup
+
+  $ cat >> $HGRCPATH << EOF
+  > [ui]
+  > ssh="$PYTHON" "$RUNTESTDIR/dummyssh"
+  > EOF
+
+  $ hg init remote
+  $ cd remote
+  $ echo this > foo
+  $ echo this > fooO
+  $ hg ci -A -m "init" foo fooO
+  $ hg clone ssh://user@dummy/remote/ local --debug
+  running "*" "*/tests/dummyssh" 'user@dummy' 'hg -R remote/ serve --stdio' (glob)
+  sending hello command
+  sending between command
+  remote: 413
+  remote: capabilities: batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset getbundle known lookup protocaps pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash
+  remote: 1
+  sending protocaps command
+  query 1; heads
+  sending batch command
+  requesting all changes
+  sending getbundle command
+  bundle2-input-bundle: with-transaction
+  bundle2-input-part: "changegroup" (params: 1 mandatory 1 advisory) supported
+  adding changesets
+  add changeset 1160648e36ce
+  adding manifests
+  adding file changes
+  adding foo revisions
+  adding fooO revisions
+  added 1 changesets with 2 changes to 2 files
+  bundle2-input-part: total payload size 664
+  bundle2-input-part: "listkeys" (params: 1 mandatory) supported
+  bundle2-input-part: "phase-heads" supported
+  bundle2-input-part: total payload size 24
+  bundle2-input-part: "cache:rev-branch-cache" (advisory) supported
+  bundle2-input-part: total payload size 39
+  bundle2-input-bundle: 3 parts total
+  checking for updated bookmarks
+  updating the branch cache
+  new changesets 1160648e36ce
+  updating to branch default
+  resolving manifests
+   branchmerge: False, force: False, partial: False
+   ancestor: 000000000000, local: 000000000000+, remote: 1160648e36ce
+   foo: remote created -> g
+  getting foo
+   fooO: remote created -> g
+  getting fooO
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd local
+
+Test basic remote debug output
+------------------------------
+
+  $ hg pull --config "devel.remote.debug=yes"
+  pulling from ssh://user@dummy/remote/
+  searching for changes
+  no changes found
+  remote: listing keys for "bookmarks"
+  remote: bundle2-output-bundle: "HG20", 2 parts total
+  remote: bundle2-output-part: "listkeys" (params: 1 mandatory) empty payload
+  remote: bundle2-output-part: "phase-heads" 24 bytes payload