##// END OF EJS Templates
hg-ssh: fix dispatch call to use dispatch.request()...
Idan Kamara -
r14462:f6a43367 default
parent child Browse files
Show More
@@ -1,52 +1,52
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # Copyright 2005-2007 by Intevation GmbH <intevation@intevation.de>
3 # Copyright 2005-2007 by Intevation GmbH <intevation@intevation.de>
4 #
4 #
5 # Author(s):
5 # Author(s):
6 # Thomas Arendsen Hein <thomas@intevation.de>
6 # Thomas Arendsen Hein <thomas@intevation.de>
7 #
7 #
8 # This software may be used and distributed according to the terms of the
8 # This software may be used and distributed according to the terms of the
9 # GNU General Public License version 2 or any later version.
9 # GNU General Public License version 2 or any later version.
10
10
11 """
11 """
12 hg-ssh - a wrapper for ssh access to a limited set of mercurial repos
12 hg-ssh - a wrapper for ssh access to a limited set of mercurial repos
13
13
14 To be used in ~/.ssh/authorized_keys with the "command" option, see sshd(8):
14 To be used in ~/.ssh/authorized_keys with the "command" option, see sshd(8):
15 command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ...
15 command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ...
16 (probably together with these other useful options:
16 (probably together with these other useful options:
17 no-port-forwarding,no-X11-forwarding,no-agent-forwarding)
17 no-port-forwarding,no-X11-forwarding,no-agent-forwarding)
18
18
19 This allows pull/push over ssh from/to the repositories given as arguments.
19 This allows pull/push over ssh from/to the repositories given as arguments.
20
20
21 If all your repositories are subdirectories of a common directory, you can
21 If all your repositories are subdirectories of a common directory, you can
22 allow shorter paths with:
22 allow shorter paths with:
23 command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2"
23 command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2"
24
24
25 You can use pattern matching of your normal shell, e.g.:
25 You can use pattern matching of your normal shell, e.g.:
26 command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}"
26 command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}"
27 """
27 """
28
28
29 # enable importing on demand to reduce startup time
29 # enable importing on demand to reduce startup time
30 from mercurial import demandimport; demandimport.enable()
30 from mercurial import demandimport; demandimport.enable()
31
31
32 from mercurial import dispatch
32 from mercurial import dispatch
33
33
34 import sys, os
34 import sys, os
35
35
36 cwd = os.getcwd()
36 cwd = os.getcwd()
37 allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
37 allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
38 for path in sys.argv[1:]]
38 for path in sys.argv[1:]]
39 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
39 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
40
40
41 if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'):
41 if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'):
42 path = orig_cmd[6:-14]
42 path = orig_cmd[6:-14]
43 repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
43 repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
44 if repo in allowed_paths:
44 if repo in allowed_paths:
45 dispatch.dispatch(['-R', repo, 'serve', '--stdio'])
45 dispatch.dispatch(dispatch.request(['-R', repo, 'serve', '--stdio']))
46 else:
46 else:
47 sys.stderr.write("Illegal repository %r\n" % repo)
47 sys.stderr.write("Illegal repository %r\n" % repo)
48 sys.exit(-1)
48 sys.exit(-1)
49 else:
49 else:
50 sys.stderr.write("Illegal command %r\n" % orig_cmd)
50 sys.stderr.write("Illegal command %r\n" % orig_cmd)
51 sys.exit(-1)
51 sys.exit(-1)
52
52
General Comments 0
You need to be logged in to leave comments. Login now