changeset 15622:86fc364ca5f8

sshrepo: don't quote obviously safe strings (issue2983) This restores compatibility with hg-over-ssh servers that don't parse commandlines as sh does but works ok in the most common cases.
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 08 Dec 2011 16:39:00 +0100
parents 013688350c7d
children fc8c7a5ccc4a
files mercurial/sshrepo.py tests/test-init.t tests/test-ssh.t tests/test-subrepo-relative-path.t
diffstat 4 files changed, 36 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/sshrepo.py	Wed Nov 16 15:29:57 2011 -0600
+++ b/mercurial/sshrepo.py	Thu Dec 08 16:39:00 2011 +0100
@@ -5,6 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import re
 from i18n import _
 import util, error, wireproto
 
@@ -20,6 +21,8 @@
 
 def _serverquote(s):
     '''quote a string for the remote shell ... which we assume is sh'''
+    if re.match(r'[a-zA-Z0-9._\-/]*$', s):
+        return s
     return "'%s'" % s.replace("'", "'\\''")
 
 class sshrepository(wireproto.wirerepository):
--- a/tests/test-init.t	Wed Nov 16 15:29:57 2011 -0600
+++ b/tests/test-init.t	Thu Dec 08 16:39:00 2011 +0100
@@ -105,13 +105,13 @@
 output of dummyssh
 
   $ cat dummylog
-  Got arguments 1:user@dummy 2:'hg' init 'remote2'
-  Got arguments 1:user@dummy 2:'hg' -R 'remote2' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote2' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' init 'remote1'
-  Got arguments 1:user@dummy 2:'hg' -R 'remote1' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' init 'remote1'
-  Got arguments 1:user@dummy 2:'hg' init 'remote1'
+  Got arguments 1:user@dummy 2:hg init remote2
+  Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
+  Got arguments 1:user@dummy 2:hg init remote1
+  Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio
+  Got arguments 1:user@dummy 2:hg init remote1
+  Got arguments 1:user@dummy 2:hg init remote1
 
 comparing repositories
 
--- a/tests/test-ssh.t	Wed Nov 16 15:29:57 2011 -0600
+++ b/tests/test-ssh.t	Thu Dec 08 16:39:00 2011 +0100
@@ -275,27 +275,27 @@
   3fb238f49e8c
 
   $ cat dummylog
-  Got arguments 1:user@dummy 2:'hg' -R 'nonexistent' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R '/$TESTTMP/nonexistent' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'local' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R '$TESTTMP/local' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
+  Got arguments 1:user@dummy 2:hg -R nonexistent serve --stdio
+  Got arguments 1:user@dummy 2:hg -R /$TESTTMP/nonexistent serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R local serve --stdio
+  Got arguments 1:user@dummy 2:hg -R $TESTTMP/local serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
   changegroup-in-remote hook: HG_NODE=a28a9d1a809cab7d4e2fde4bee738a9ede948b60 HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1 
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
   changegroup-in-remote hook: HG_NODE=1383141674ec756a6056f6a9097618482fe0f4a6 HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1 
-  Got arguments 1:user@dummy 2:'hg' -R 'remote' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' init 'a repo'
-  Got arguments 1:user@dummy 2:'hg' -R 'a repo' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'a repo' serve --stdio
+  Got arguments 1:user@dummy 2:hg -R remote serve --stdio
+  Got arguments 1:user@dummy 2:hg init 'a repo'
+  Got arguments 1:user@dummy 2:hg -R 'a repo' serve --stdio
+  Got arguments 1:user@dummy 2:hg -R 'a repo' serve --stdio
--- a/tests/test-subrepo-relative-path.t	Wed Nov 16 15:29:57 2011 -0600
+++ b/tests/test-subrepo-relative-path.t	Thu Dec 08 16:39:00 2011 +0100
@@ -98,8 +98,8 @@
   no changes found
 
   $ cat dummylog
-  Got arguments 1:user@dummy 2:'hg' -R 'cloned' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R 'sub' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R '$TESTTMP/cloned' serve --stdio
-  Got arguments 1:user@dummy 2:'hg' -R '$TESTTMP/sub' serve --stdio
+  Got arguments 1:user@dummy 2:hg -R cloned serve --stdio
+  Got arguments 1:user@dummy 2:hg -R sub serve --stdio
+  Got arguments 1:user@dummy 2:hg -R $TESTTMP/cloned serve --stdio
+  Got arguments 1:user@dummy 2:hg -R $TESTTMP/sub serve --stdio
   $ rm $BINDIR/ssh