Rev 353: Allow importing to a remote repository. in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Mon Jan 1 17:01:03 GMT 2007


------------------------------------------------------------
revno: 353
revision-id: jelmer at samba.org-20070101170010-0v0mdegv2ilp0fxj
parent: jelmer at samba.org-20070101162635-5cdtbm36kfqlhtcg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Mon 2007-01-01 18:00:10 +0100
message:
  Allow importing to a remote repository.
modified:
  TODO                           todo-20060729211917-2kpobww0zyvvo0j2-1
  convert.py                     svn2bzr.py-20051018015439-cb4563bff29e632d
=== modified file 'TODO'
--- a/TODO	2007-01-01 16:26:35 +0000
+++ b/TODO	2007-01-01 17:00:10 +0000
@@ -1,5 +1,4 @@
 - handle parent directories of branches being moved correctly
-- allow remote locations in svn-import
 - fix "bzr status" in checkouts
 - faster "bzr status" in checkouts
 - avoid extra connect in logwalker?

=== modified file 'convert.py'
--- a/convert.py	2007-01-01 16:26:35 +0000
+++ b/convert.py	2007-01-01 17:00:10 +0000
@@ -28,11 +28,13 @@
 
 from bzrlib.bzrdir import BzrDir
 from bzrlib.branch import Branch
-from bzrlib.errors import BzrError, NotBranchError
+from bzrlib.errors import BzrError, NotBranchError, NoSuchFile
 import bzrlib.osutils as osutils
 from bzrlib.progress import DummyProgress
 from bzrlib.repository import Repository
 from bzrlib.trace import info, mutter
+from bzrlib.transport import get_transport
+import bzrlib.urlutils as urlutils
 from bzrlib.ui import ui_factory
 
 from format import SvnRemoteAccess, SvnFormat
@@ -41,6 +43,16 @@
 
 import svn.core
 
+def transport_makedirs(transport, location_url):
+    needed = [(transport, transport.relpath(location_url))]
+    while needed:
+        try:
+            transport, relpath = needed[-1]
+            transport.mkdir(relpath)
+            needed.pop()
+        except NoSuchFile:
+            needed.append((transport, urlutils.dirname(relpath)))
+
 def load_dumpfile(dumpfile, outputdir):
     import svn
     from svn.core import SubversionException
@@ -55,7 +67,7 @@
     return repos
 
 
-def convert_repository(url, output_dir, scheme, create_shared_repo=True, 
+def convert_repository(url, output_url, scheme, create_shared_repo=True, 
                        working_trees=False, all=False):
     assert not all or create_shared_repo
 
@@ -70,17 +82,18 @@
     try:
         source_repos = SvnRepository.open(url)
         source_repos.set_branching_scheme(scheme)
+        to_transport = get_transport(output_url)
 
         if create_shared_repo:
             try:
-                target_repos = Repository.open(output_dir)
+                target_repos = Repository.open(output_url)
                 assert target_repos.is_shared()
             except NotBranchError:
                 if scheme.is_branch(""):
-                    BzrDir.create_branch_and_repo(output_dir)
+                    BzrDir.create_branch_and_repo(output_url)
                 else:
-                    BzrDir.create_repository(output_dir, shared=True)
-                target_repos = Repository.open(output_dir)
+                    BzrDir.create_repository(output_url, shared=True)
+                target_repos = Repository.open(output_url)
             target_repos.set_make_working_trees(working_trees)
             if all:
                 source_repos.copy_content_into(target_repos)
@@ -103,16 +116,16 @@
                 pb.update("%s:%d" % (branch, revnum), i, len(existing_branches))
                 revid = source_repos.generate_revision_id(revnum, branch)
 
-                target_dir = os.path.join(output_dir, branch)
+                target_url = urlutils.join(to_transport.base, branch)
                 try:
-                    target_branch = Branch.open(target_dir)
+                    target_branch = Branch.open(target_url)
                     if not revid in target_branch.revision_history():
                         source_branch = Branch.open("%s/%s" % (url, branch))
                         target_branch.pull(source_branch)
                 except NotBranchError:
                     source_branch = Branch.open("%s/%s" % (url, branch))
-                    os.makedirs(target_dir)
-                    source_branch.bzrdir.sprout(target_dir, 
+                    transport_makedirs(to_transport, target_url)
+                    source_branch.bzrdir.sprout(target_url, 
                                                 source_branch.last_revision())
                 i+=1
         finally:




More information about the bazaar-commits mailing list