contrib/hg-ssh
changeset 15897 cc021114fc98
parent 14462 f6a433671c06
child 16606 19379226dc67
--- a/contrib/hg-ssh	Sun Jan 15 13:50:12 2012 -0700
+++ b/contrib/hg-ssh	Thu Dec 08 16:28:18 2011 +0100
@@ -31,15 +31,20 @@
 
 from mercurial import dispatch
 
-import sys, os
+import sys, os, shlex
 
 cwd = os.getcwd()
 allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
                  for path in sys.argv[1:]]
 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
+try:
+    cmdargv = shlex.split(orig_cmd)
+except ValueError, e:
+    sys.stderr.write("Illegal command %r: %s\n" % (orig_cmd, e))
+    sys.exit(-1)
 
-if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'):
-    path = orig_cmd[6:-14]
+if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
+    path = cmdargv[2]
     repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
     if repo in allowed_paths:
         dispatch.dispatch(dispatch.request(['-R', repo, 'serve', '--stdio']))