diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1582,6 +1582,21 @@ def debugwalk(ui, repo, *pats, **opts): line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') ui.write("%s\n" % line.rstrip()) +def debugwireargs(ui, repopath, *vals, **opts): + repo = hg.repository(hg.remoteui(ui, opts), repopath) + for opt in remoteopts: + del opts[opt[1]] + args = {} + for k, v in opts.iteritems(): + if v: + args[k] = v + # run twice to check that we don't mess up the stream for the next command + res1 = repo.debugwireargs(*vals, **args) + res2 = repo.debugwireargs(*vals, **args) + ui.write("%s\n" % res1) + if res1 != res2: + ui.warn("%s\n" % res2) + def diff(ui, repo, *pats, **opts): """diff repository (or selected files) @@ -4456,6 +4471,12 @@ table = { _('revision to check'), _('REV'))], _('[-r REV] [REV]')), "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')), + "debugwireargs": + (debugwireargs, + [('', 'three', '', 'three'), + ('', 'four', '', 'four'), + ] + remoteopts, + _('REPO [OPTIONS]... [ONE [TWO]]')), "^diff": (diff, [('r', 'rev', [], @@ -4789,6 +4810,6 @@ table = { } norepo = ("clone init version help debugcommands debugcomplete" - " debugdate debuginstall debugfsinfo debugpushkey") + " debugdate debuginstall debugfsinfo debugpushkey debugwireargs") optionalrepo = ("identify paths serve showconfig debugancestor debugdag" " debugdata debugindex debugindexdot") diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1905,6 +1905,10 @@ class localrepository(repo.repository): def listkeys(self, namespace): return pushkey.list(self, namespace) + def debugwireargs(self, one, two, three=None, four=None): + '''used to test argument passing over the wire''' + return "%s %s %s %s" % (one, two, three, four) + # used to avoid circular references so destructors work def aftertrans(files): renamefiles = [tuple(t) for t in files] diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -133,6 +133,15 @@ class wirerepository(repo.repository): self.ui.status(_('remote: '), l) return ret + def debugwireargs(self, one, two, three=None, four=None): + # don't pass optional arguments left at their default value + opts = {} + if three is not None: + opts['three'] = three + if four is not None: + opts['four'] = four + return self._call('debugwireargs', one=one, two=two, **opts) + # server side class streamres(object): @@ -199,6 +208,9 @@ def changegroupsubset(repo, proto, bases cg = repo.changegroupsubset(bases, heads, 'serve') return streamres(proto.groupchunks(cg)) +def debugwireargs(repo, proto, one, two): + return repo.debugwireargs(one, two) + def heads(repo, proto): h = repo.heads() return encodelist(h) + "\n" @@ -343,6 +355,7 @@ commands = { 'capabilities': (capabilities, ''), 'changegroup': (changegroup, 'roots'), 'changegroupsubset': (changegroupsubset, 'bases heads'), + 'debugwireargs': (debugwireargs, 'one two'), 'heads': (heads, ''), 'hello': (hello, ''), 'listkeys': (listkeys, 'namespace'), diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t --- a/tests/test-debugcomplete.t +++ b/tests/test-debugcomplete.t @@ -87,6 +87,7 @@ Show debug commands if there are no othe debugstate debugsub debugwalk + debugwireargs Do not show the alias of a debug command if there are other candidates (this should hide rawcommit) @@ -227,6 +228,7 @@ Show all commands + options debugstate: nodates debugsub: rev debugwalk: include, exclude + debugwireargs: three, four, ssh, remotecmd, insecure grep: print0, all, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude heads: rev, topo, active, closed, style, template help: diff --git a/tests/test-wireproto.t b/tests/test-wireproto.t new file mode 100644 --- /dev/null +++ b/tests/test-wireproto.t @@ -0,0 +1,42 @@ + +Test wire protocol argument passing + +Setup repo: + + $ hg init repo + +Local: + + $ hg debugwireargs repo eins zwei + eins zwei None None + +HTTP: + + $ hg serve -R repo -p $HGPORT -d --pid-file=hg1.pid -E error.log -A access.log + $ cat hg1.pid >> $DAEMON_PIDS + + $ hg debugwireargs http://localhost:$HGPORT/ eins zwei + eins zwei None None + $ cat access.log + * - - [*] "GET /?cmd=capabilities HTTP/1.1" 200 - (glob) + * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob) + * - - [*] "GET /?cmd=debugwireargs&one=eins&two=zwei HTTP/1.1" 200 - (glob) + +SSH (try to exercise the ssh functionality with a dummy script): + + $ cat < dummyssh + > import sys + > import os + > os.chdir(os.path.dirname(sys.argv[0])) + > if sys.argv[1] != "user@dummy": + > sys.exit(-1) + > if not os.path.exists("dummyssh"): + > sys.exit(-1) + > os.environ["SSH_CLIENT"] = "127.0.0.1 1 2" + > r = os.system(sys.argv[2]) + > sys.exit(bool(r)) + > EOF + + $ hg debugwireargs --ssh "python ./dummyssh" ssh://user@dummy/repo eins zwei + eins zwei None None +