Rev 341: Add --all option to svn-import. in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev
Jelmer Vernooij
jelmer at samba.org
Sun Dec 31 03:39:43 GMT 2006
------------------------------------------------------------
revno: 341
revision-id: jelmer at samba.org-20061231033910-r3ks4rqiwpmiwhqy
parent: jelmer at samba.org-20061231030347-8ye5ftr7c0w2inpq
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Sun 2006-12-31 04:39:10 +0100
message:
Add --all option to svn-import.
modified:
NEWS news-20061231030336-h9fhq245ie0de8bs-1
__init__.py __init__.py-20051008155114-eae558e6cf149e1d
convert.py svn2bzr.py-20051018015439-cb4563bff29e632d
fetch.py fetch.py-20060625004942-x2lfaib8ra707a8p-1
repository.py repository.py-20060306123302-1f8c5069b3fe0265
tests/test_convert.py test_convert.py-20060705203611-b1l0bapeku6foco0-1
=== modified file 'NEWS'
--- a/NEWS 2006-12-31 03:03:47 +0000
+++ b/NEWS 2006-12-31 03:39:10 +0000
@@ -41,7 +41,7 @@
* The LogWalker class is now a lot dumber.
- * Added --scheme option to svn-import.
+ * Added --scheme and --all option to svn-import.
* Implemented SvnRaTransport.list_dir().
=== modified file '__init__.py'
--- a/__init__.py 2006-12-30 17:33:56 +0000
+++ b/__init__.py 2006-12-31 03:39:10 +0000
@@ -116,12 +116,13 @@
takes_args = ['from_location', 'to_location?']
takes_options = [Option('trees', help='Create working trees'),
Option('shared', help='Create shared repository'),
+ Option('all', help='Convert all revisions, even those not in current branch history (implies --shared)'),
Option('scheme', type=get_scheme,
help='Branching scheme (none, trunk, or trunk-INT)')]
@display_command
def run(self, from_location, to_location=None, trees=False,
- shared=False, scheme=None):
+ shared=False, scheme=None, all=False):
from convert import convert_repository
from scheme import TrunkBranchingScheme
@@ -131,7 +132,10 @@
if to_location is None:
to_location = os.path.basename(from_location.rstrip("/\\"))
- convert_repository(from_location, to_location, scheme, shared, trees)
+ if all:
+ shared = True
+ convert_repository(from_location, to_location, scheme, shared, trees,
+ all)
register_command(cmd_svn_import)
=== modified file 'convert.py'
--- a/convert.py 2006-12-30 17:43:09 +0000
+++ b/convert.py 2006-12-31 03:39:10 +0000
@@ -53,7 +53,9 @@
return repos
-def convert_repository(url, output_dir, scheme, create_shared_repo=True, working_trees=False):
+def convert_repository(url, output_dir, scheme, create_shared_repo=True,
+ working_trees=False, all=False):
+ assert not all or create_shared_repo
if os.path.isfile(url):
tmp_repos = tempfile.mkdtemp(prefix='bzr-svn-dump-')
@@ -78,9 +80,8 @@
BzrDir.create_repository(output_dir, shared=True)
target_repos = Repository.open(output_dir)
target_repos.set_make_working_trees(working_trees)
- # FIXME: Copy all revisions first, even the ones that aren't ancestors
- # of currently existing branches?
- # source_repos.copy_content_into(target_repos)
+ if all:
+ source_repos.copy_content_into(target_repos)
branches = list(source_repos.find_branches())
mutter('branches: %r' % list(branches))
=== modified file 'fetch.py'
--- a/fetch.py 2006-12-30 19:29:57 +0000
+++ b/fetch.py 2006-12-31 03:39:10 +0000
@@ -287,32 +287,37 @@
# Loop over all the revnums until revision_id
# (or youngest_revnum) and call self.target.add_revision()
# or self.target.add_inventory() each time
+ needed = []
+ parents = {}
if revision_id is None:
- history_iterator = self.source.follow_history(self.source._latest_revnum)
+ for (branch, revnum) in self.source.follow_history(self.source._latest_revnum):
+ revid = self.source.generate_revision_id(revnum, branch)
+ parents[revid] = self.source._mainline_revision_parent(branch, revnum)
+
+ if not self.target.has_revision(revid):
+ needed.append(revid)
else:
(path, until_revnum) = self.source.parse_revision_id(revision_id)
- history_iterator = self.source.follow_branch(path, until_revnum)
-
- needed = []
- parents = {}
- prev_revid = None
- for (branch, revnum) in history_iterator:
- revid = self.source.generate_revision_id(revnum, branch)
-
- if prev_revid is not None:
- parents[prev_revid] = revid
-
- prev_revid = revid
-
- if not self.target.has_revision(revid):
- needed.append((branch, revnum, revid))
+
+ prev_revid = None
+ for (branch, revnum) in self.source.follow_branch(path, until_revnum):
+ revid = self.source.generate_revision_id(revnum, branch)
+
+ if prev_revid is not None:
+ parents[prev_revid] = revid
+
+ prev_revid = revid
+
+ if not self.target.has_revision(revid):
+ needed.append(revid)
+
+
+ parents[prev_revid] = None
if len(needed) == 0:
# Nothing to fetch
return
- parents[prev_revid] = None
-
repos_root = self.source.transport.get_repos_root()
needed.reverse()
@@ -321,7 +326,8 @@
pb = ui_factory.nested_progress_bar()
num = 0
try:
- for (branch, revnum, revid) in needed:
+ for revid in needed:
+ (branch, revnum) = self.source.parse_revision_id(revid)
pb.update('copying revision', num, len(needed))
parent_revid = parents[revid]
=== modified file 'repository.py'
--- a/repository.py 2006-12-30 21:08:37 +0000
+++ b/repository.py 2006-12-31 03:39:10 +0000
@@ -340,24 +340,30 @@
return SvnRevisionTree(self, revision_id, inventory)
+ def _mainline_revision_parent(self, path, revnum):
+ assert isinstance(path, basestring)
+ assert isinstance(revnum, int)
+ for (branch, rev) in self.follow_branch(path, revnum):
+ if rev < revnum:
+ return self.generate_revision_id(rev, branch)
+ return None
+
def revision_parents(self, revision_id, merged_data=None):
- (path, revnum) = self.parse_revision_id(revision_id)
-
- parent_path = None
parent_ids = []
- for (branch, rev) in self.follow_branch(path, revnum):
- if rev < revnum:
- parent_revnum = rev
- parent_path = branch
- parent_ids = [self.generate_revision_id(rev, branch)]
- break
+ (branch, revnum) = self.parse_revision_id(revision_id)
+ mainline_parent = self._mainline_revision_parent(branch, revnum)
+ if mainline_parent is not None:
+ parent_ids.append(mainline_parent)
+ (parent_path, parent_revnum) = self.parse_revision_id(mainline_parent)
+ else:
+ parent_path = None
# if the branch didn't change, bzr:merge can't have changed
if not self._log.touches_path(branch, revnum):
return parent_ids
if merged_data is None:
- new_merge = self.branchprop_list.get_property(path, revnum,
+ new_merge = self.branchprop_list.get_property(branch, revnum,
SVN_PROP_BZR_MERGE, "").splitlines()
if len(new_merge) == 0 or parent_path is None:
=== modified file 'tests/test_convert.py'
--- a/tests/test_convert.py 2006-12-25 23:09:33 +0000
+++ b/tests/test_convert.py 2006-12-31 03:39:10 +0000
@@ -18,6 +18,7 @@
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import NotBranchError
from bzrlib.repository import Repository
+from bzrlib.trace import mutter
import os
from convert import convert_repository
@@ -36,6 +37,31 @@
self.build_tree({'dc/trunk/file': 'otherdata'})
self.client_commit("dc", "change")
+ def test_fetch_alive(self):
+ self.build_tree({'dc/branches/somebranch/somefile': 'data'})
+ self.client_add("dc/branches/somebranch")
+ self.client_commit("dc", "add a branch")
+ self.client_delete("dc/branches/somebranch")
+ self.client_commit("dc", "remove branch")
+ convert_repository(self.repos_url, "e", TrunkBranchingScheme(),
+ all=False, create_shared_repo=True)
+ oldrepos = Repository.open(self.repos_url)
+ newrepos = Repository.open("e")
+ self.assertFalse(newrepos.has_revision("svn-v%d:2@%s-branches%%2fsomebranch" % (MAPPING_VERSION, oldrepos.uuid)))
+
+ def test_fetch_dead(self):
+ self.build_tree({'dc/branches/somebranch/somefile': 'data'})
+ self.client_add("dc/branches/somebranch")
+ self.client_commit("dc", "add a branch")
+ self.client_delete("dc/branches/somebranch")
+ self.client_commit("dc", "remove branch")
+ convert_repository(self.repos_url, "e", TrunkBranchingScheme(),
+ all=True, create_shared_repo=True)
+ oldrepos = Repository.open(self.repos_url)
+ newrepos = Repository.open("e")
+ mutter('q: %r' % newrepos.all_revision_ids())
+ self.assertTrue(newrepos.has_revision("svn-v%d:3@%s-branches%%2fsomebranch" % (MAPPING_VERSION, oldrepos.uuid)))
+
def test_shared_import_continue(self):
BzrDir.create_repository("e", shared=True)
More information about the bazaar-commits
mailing list