##// END OF EJS Templates
hg-ssh: refactor to have main() method...
David Schleimer -
r16779:67bfe7f6 default
parent child Browse files
Show More
@@ -33,25 +33,31 b' from mercurial import dispatch'
33
33
34 import sys, os, shlex
34 import sys, os, shlex
35
35
36 cwd = os.getcwd()
36 def main():
37 allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
37 cwd = os.getcwd()
38 for path in sys.argv[1:]]
38 allowed_paths = [os.path.normpath(os.path.join(cwd,
39 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
39 os.path.expanduser(path)))
40 try:
40 for path in sys.argv[1:]]
41 cmdargv = shlex.split(orig_cmd)
41 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
42 except ValueError, e:
42 try:
43 sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
43 cmdargv = shlex.split(orig_cmd)
44 sys.exit(255)
44 except ValueError, e:
45 sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
46 sys.exit(255)
45
47
46 if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
48 if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
47 path = cmdargv[2]
49 path = cmdargv[2]
48 repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
50 repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
49 if repo in allowed_paths:
51 if repo in allowed_paths:
50 dispatch.dispatch(dispatch.request(['-R', repo, 'serve', '--stdio']))
52 dispatch.dispatch(dispatch.request(['-R', repo,
53 'serve',
54 '--stdio']))
55 else:
56 sys.stderr.write('Illegal repository "%s"\n' % repo)
57 sys.exit(255)
51 else:
58 else:
52 sys.stderr.write('Illegal repository "%s"\n' % repo)
59 sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
53 sys.exit(255)
60 sys.exit(255)
54 else:
55 sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
56 sys.exit(255)
57
61
62 if __name__ == '__main__':
63 main()
General Comments 0
You need to be logged in to leave comments. Login now