comparison mercurial/sshrepo.py @ 2549:e1831f06eef1

Added ability to clone from a local repository to a (new) remote one. Rearranged the clone command a good bit to make sure it validates that the source does exist and that the destination doesn't before doing anything. Before I moved the source repo check it would create the destination repository before it verified the source existed. Moved the responsibility for creating the destination repo root directory entirly into the localrepo class so that local to local cloning doesn't break. This also simplifies the code a bit since it's no longer being done in both clone and init. Changed the names of the 'repo' and 'other' variables to 'dest_repo' and 'src_repo' to maintain my sanity. Passes 82/83 tests. The only failure is the version number test, which I suspect is supposed to fail since it comes from a generated file.
author Sean Meiners <sean.meiners@linspire.com>
date Fri, 30 Jun 2006 19:24:02 -0700
parents eabcda3ed0dd
children ffb895f16925
comparison
equal deleted inserted replaced
2546:8cb894370514 2549:e1831f06eef1
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')