D2406: debugcommands: allow sending of simple commands with debugwireproto

2018-03-01 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2aeacc6b479d: debugcommands: allow sending of simple 
commands with debugwireproto (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2406?vs=6252=6285

REVISION DETAIL
  https://phab.mercurial-scm.org/D2406

AFFECTED FILES
  mercurial/debugcommands.py
  tests/test-ssh-proto.t

CHANGE DETAILS

diff --git a/tests/test-ssh-proto.t b/tests/test-ssh-proto.t
--- a/tests/test-ssh-proto.t
+++ b/tests/test-ssh-proto.t
@@ -1,3 +1,23 @@
+  $ cat > hgrc-sshv2 << EOF
+  > %include $HGRCPATH
+  > [experimental]
+  > sshpeer.advertise-v2 = true
+  > sshserver.support-v2 = true
+  > EOF
+
+Helper function to run protocol tests against multiple protocol versions.
+This is easier than using #testcases because managing differences between
+protocols with inline conditional output is hard to read.
+
+  $ debugwireproto() {
+  >   commands=`cat -`
+  >   echo 'testing ssh1'
+  >   echo "${commands}" | hg --verbose debugwireproto --localssh
+  >   echo ""
+  >   echo 'testing ssh2'
+  >   echo "${commands}" | HGRCPATH=$TESTTMP/hgrc-sshv2 hg --verbose 
debugwireproto --localssh
+  > }
+
   $ cat >> $HGRCPATH << EOF
   > [ui]
   > ssh = $PYTHON "$TESTDIR/dummyssh"
@@ -1252,3 +1272,561 @@
   e> read(-1) -> 49:
   e> malformed handshake protocol: missing pairs 81\n
   e> -\n
+
+  $ cd ..
+
+Test listkeys for listing namespaces
+
+  $ hg init empty
+  $ cd empty
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace namespaces
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 62:
+  o> upgraded * exp-ssh-v2-0001\n (glob)
+  o> readline() -> 4:
+  o> 383\n
+  o> read(383) -> 383: capabilities: lookup changegroupsubset branchmap 
pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN
+  o> read(1) -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+
+  $ cd ..
+
+Test listkeys for bookmarks
+
+  $ hg init bookmarkrepo
+  $ cd bookmarkrepo
+  $ echo 0 > foo
+  $ hg add foo
+  $ hg -q commit -m initial
+  $ echo 1 > foo
+  $ hg commit -m second
+
+With no bookmarks set
+
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace bookmarks
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(12) -> None:
+  i> namespace 9\n
+  i> write(9) -> None: bookmarks
+  i> flush() -> None
+  o> bufferedreadline() -> 2:
+  o> 0\n
+  response: 
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  

D2406: debugcommands: allow sending of simple commands with debugwireproto

2018-02-26 Thread indygreg (Gregory Szorc)
indygreg updated this revision to Diff 6141.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2406?vs=6026=6141

REVISION DETAIL
  https://phab.mercurial-scm.org/D2406

AFFECTED FILES
  mercurial/debugcommands.py
  tests/test-ssh-proto.t

CHANGE DETAILS

diff --git a/tests/test-ssh-proto.t b/tests/test-ssh-proto.t
--- a/tests/test-ssh-proto.t
+++ b/tests/test-ssh-proto.t
@@ -1,3 +1,23 @@
+  $ cat > hgrc-sshv2 << EOF
+  > %include $HGRCPATH
+  > [experimental]
+  > sshpeer.advertise-v2 = true
+  > sshserver.support-v2 = true
+  > EOF
+
+Helper function to run protocol tests against multiple protocol versions.
+This is easier than using #testcases because managing differences between
+protocols with inline conditional output is hard to read.
+
+  $ debugwireproto() {
+  >   commands=`cat -`
+  >   echo 'testing ssh1'
+  >   echo "${commands}" | hg --verbose debugwireproto --localssh
+  >   echo ""
+  >   echo 'testing ssh2'
+  >   echo "${commands}" | HGRCPATH=$TESTTMP/hgrc-sshv2 hg --verbose 
debugwireproto --localssh
+  > }
+
   $ cat >> $HGRCPATH << EOF
   > [ui]
   > ssh = $PYTHON "$TESTDIR/dummyssh"
@@ -1252,3 +1272,561 @@
   e> read(-1) -> 49:
   e> malformed handshake protocol: missing pairs 81\n
   e> -\n
+
+  $ cd ..
+
+Test listkeys for listing namespaces
+
+  $ hg init empty
+  $ cd empty
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace namespaces
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 62:
+  o> upgraded * exp-ssh-v2-0001\n (glob)
+  o> readline() -> 4:
+  o> 383\n
+  o> read(383) -> 383: capabilities: lookup changegroupsubset branchmap 
pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN
+  o> read(1) -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+
+  $ cd ..
+
+Test listkeys for bookmarks
+
+  $ hg init bookmarkrepo
+  $ cd bookmarkrepo
+  $ echo 0 > foo
+  $ hg add foo
+  $ hg -q commit -m initial
+  $ echo 1 > foo
+  $ hg commit -m second
+
+With no bookmarks set
+
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace bookmarks
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(12) -> None:
+  i> namespace 9\n
+  i> write(9) -> None: bookmarks
+  i> flush() -> None
+  o> bufferedreadline() -> 2:
+  o> 0\n
+  response: 
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 62:
+  o> 

D2406: debugcommands: allow sending of simple commands with debugwireproto

2018-02-23 Thread indygreg (Gregory Szorc)
indygreg updated this revision to Diff 6026.
indygreg edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2406?vs=6023=6026

REVISION DETAIL
  https://phab.mercurial-scm.org/D2406

AFFECTED FILES
  mercurial/debugcommands.py
  tests/test-ssh-proto.t

CHANGE DETAILS

diff --git a/tests/test-ssh-proto.t b/tests/test-ssh-proto.t
--- a/tests/test-ssh-proto.t
+++ b/tests/test-ssh-proto.t
@@ -1,3 +1,23 @@
+  $ cat > hgrc-sshv2 << EOF
+  > %include $HGRCPATH
+  > [experimental]
+  > sshpeer.advertise-v2 = true
+  > sshserver.support-v2 = true
+  > EOF
+
+Helper function to run protocol tests against multiple protocol versions.
+This is easier than using #testcases because managing differences between
+protocols with inline conditional output is hard to read.
+
+  $ debugwireproto() {
+  >   commands=`cat -`
+  >   echo 'testing ssh1'
+  >   echo "${commands}" | hg --verbose debugwireproto --localssh
+  >   echo ""
+  >   echo 'testing ssh2'
+  >   echo "${commands}" | HGRCPATH=$TESTTMP/hgrc-sshv2 hg --verbose 
debugwireproto --localssh
+  > }
+
   $ cat >> $HGRCPATH << EOF
   > [ui]
   > ssh = $PYTHON "$TESTDIR/dummyssh"
@@ -1215,3 +1235,561 @@
   e> read(-1) -> 49:
   e> malformed handshake protocol: missing pairs 81\n
   e> -\n
+
+  $ cd ..
+
+Test listkeys for listing namespaces
+
+  $ hg init empty
+  $ cd empty
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace namespaces
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 62:
+  o> upgraded * exp-ssh-v2-0001\n (glob)
+  o> readline() -> 4:
+  o> 383\n
+  o> read(383) -> 383: capabilities: lookup changegroupsubset branchmap 
pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN
+  o> read(1) -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(13) -> None:
+  i> namespace 10\n
+  i> write(10) -> None: namespaces
+  i> flush() -> None
+  o> bufferedreadline() -> 3:
+  o> 30\n
+  o> bufferedread(30) -> 30:
+  o> bookmarks \n
+  o> namespaces\n
+  o> phases
+  response: bookmarks  \nnamespaces\nphases
+
+  $ cd ..
+
+Test listkeys for bookmarks
+
+  $ hg init bookmarkrepo
+  $ cd bookmarkrepo
+  $ echo 0 > foo
+  $ hg add foo
+  $ hg -q commit -m initial
+  $ echo 1 > foo
+  $ hg commit -m second
+
+With no bookmarks set
+
+  $ debugwireproto << EOF
+  > command listkeys
+  > namespace bookmarks
+  > EOF
+  testing ssh1
+  creating ssh peer from handshake results
+  i> write(104) -> None:
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() -> None
+  o> readline() -> 4:
+  o> 384\n
+  o> readline() -> 384:
+  o> capabilities: lookup changegroupsubset branchmap pushkey known 
getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 
$USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN\n
+  o> readline() -> 2:
+  o> 1\n
+  o> readline() -> 1:
+  o> \n
+  sending listkeys command
+  i> write(9) -> None:
+  i> listkeys\n
+  i> write(12) -> None:
+  i> namespace 9\n
+  i> write(9) -> None: bookmarks
+  i> flush() -> None
+  o> bufferedreadline() -> 2:
+  o> 0\n
+  response: 
+  
+  testing ssh2
+  creating ssh peer from handshake results
+  i> write(171) -> None:
+  i> upgrade * proto=exp-ssh-v2-0001\n (glob)
+  i> hello\n
+  i> between\n
+  i> pairs 81\n
+  i> 
-
+  i> flush() 

D2406: debugcommands: allow sending of simple commands with debugwireproto

2018-02-23 Thread indygreg (Gregory Szorc)
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 
+---
+
+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 `` ``. 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel