diff 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
line wrap: on
line diff
--- a/mercurial/sshrepo.py	Fri Jun 30 23:02:08 2006 +0200
+++ b/mercurial/sshrepo.py	Fri Jun 30 19:24:02 2006 -0700
@@ -12,7 +12,7 @@
 demandload(globals(), "hg os re stat util")
 
 class sshrepository(remoterepository):
-    def __init__(self, ui, path):
+    def __init__(self, ui, path, create=0):
         self.url = path
         self.ui = ui
 
@@ -30,6 +30,25 @@
 
         sshcmd = self.ui.config("ui", "ssh", "ssh")
         remotecmd = self.ui.config("ui", "remotecmd", "hg")
+
+        if create:
+            try:
+                self.validate_repo(ui, sshcmd, args, remotecmd)
+                return # the repo is good, nothing more to do
+            except hg.RepoError:
+                pass
+
+            cmd = '%s %s "%s init %s"'
+            cmd = cmd % (sshcmd, args, remotecmd, self.path)
+
+            ui.note('running %s\n' % cmd)
+            res = os.system(cmd)
+            if res != 0:
+                raise hg.RepoError(_("could not create remote repo"))
+
+        self.validate_repo(ui, sshcmd, args, remotecmd)
+
+    def validate_repo(self, ui, sshcmd, args, remotecmd):
         cmd = '%s %s "%s -R %s serve --stdio"'
         cmd = cmd % (sshcmd, args, remotecmd, self.path)