10 from i18n import gettext as _ |
10 from i18n import gettext as _ |
11 from demandload import * |
11 from demandload import * |
12 demandload(globals(), "hg os re stat util") |
12 demandload(globals(), "hg os re stat util") |
13 |
13 |
14 class sshrepository(remoterepository): |
14 class sshrepository(remoterepository): |
15 def __init__(self, ui, path): |
15 def __init__(self, ui, path, create=0): |
16 self.url = path |
16 self.url = path |
17 self.ui = ui |
17 self.ui = ui |
18 |
18 |
19 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) |
19 m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) |
20 if not m: |
20 if not m: |
28 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host |
28 args = self.user and ("%s@%s" % (self.user, self.host)) or self.host |
29 args = self.port and ("%s -p %s") % (args, self.port) or args |
29 args = self.port and ("%s -p %s") % (args, self.port) or args |
30 |
30 |
31 sshcmd = self.ui.config("ui", "ssh", "ssh") |
31 sshcmd = self.ui.config("ui", "ssh", "ssh") |
32 remotecmd = self.ui.config("ui", "remotecmd", "hg") |
32 remotecmd = self.ui.config("ui", "remotecmd", "hg") |
|
33 |
|
34 if create: |
|
35 try: |
|
36 self.validate_repo(ui, sshcmd, args, remotecmd) |
|
37 return # the repo is good, nothing more to do |
|
38 except hg.RepoError: |
|
39 pass |
|
40 |
|
41 cmd = '%s %s "%s init %s"' |
|
42 cmd = cmd % (sshcmd, args, remotecmd, self.path) |
|
43 |
|
44 ui.note('running %s\n' % cmd) |
|
45 res = os.system(cmd) |
|
46 if res != 0: |
|
47 raise hg.RepoError(_("could not create remote repo")) |
|
48 |
|
49 self.validate_repo(ui, sshcmd, args, remotecmd) |
|
50 |
|
51 def validate_repo(self, ui, sshcmd, args, remotecmd): |
33 cmd = '%s %s "%s -R %s serve --stdio"' |
52 cmd = '%s %s "%s -R %s serve --stdio"' |
34 cmd = cmd % (sshcmd, args, remotecmd, self.path) |
53 cmd = cmd % (sshcmd, args, remotecmd, self.path) |
35 |
54 |
36 ui.note('running %s\n' % cmd) |
55 ui.note('running %s\n' % cmd) |
37 self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') |
56 self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') |