Rev 1898: Upgrade tags as well during svn-upgrade. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Tue Sep 9 22:25:53 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1898
revision-id: jelmer at samba.org-20080909212551-5ar93j5yvuj4coyk
parent: jelmer at samba.org-20080909191654-aycxaqj50by2w8bo
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Tue 2008-09-09 23:25:51 +0200
message:
Upgrade tags as well during svn-upgrade.
modified:
NEWS news-20061231030336-h9fhq245ie0de8bs-1
foreign/upgrade.py upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
tests/test_commit.py test_commit.py-20060624213521-l5kcufywkh9mnilk-1
=== modified file 'NEWS'
--- a/NEWS 2008-09-09 00:50:59 +0000
+++ b/NEWS 2008-09-09 21:25:51 +0000
@@ -48,6 +48,8 @@
* Fix corner case corruption pulling from a svn repository that contains bzr-roundtripped
revisions. (#260416)
+ * Upgrade tags as well during svn-upgrade.
+
INTERNALS
* Remove custom commit code for working tree.
=== modified file 'foreign/upgrade.py'
--- a/foreign/upgrade.py 2008-09-09 13:36:52 +0000
+++ b/foreign/upgrade.py 2008-09-09 21:25:51 +0000
@@ -73,8 +73,10 @@
def determine_fileid_renames(old_tree, new_tree):
for old_file_id in old_tree:
new_file_id = new_tree.path2id(old_tree.id2path(old_file_id))
+ if old_file_id == new_file_id:
+ continue
if new_file_id is not None:
- yield old_file_id, new_file_id
+ yield new_tree.id2path(new_file_id), old_file_id, new_file_id
def upgrade_workingtree(wt, foreign_repository, new_mapping, mapping_registry,
@@ -86,21 +88,55 @@
wt.lock_write()
try:
old_revid = wt.last_revision()
- renames = upgrade_branch(wt.branch, foreign_repository, new_mapping=new_mapping,
+ revid_renames = upgrade_branch(wt.branch, foreign_repository, new_mapping=new_mapping,
mapping_registry=mapping_registry,
allow_changes=allow_changes, verbose=verbose)
last_revid = wt.branch.last_revision()
+ if old_revid == last_revid:
+ return revid_renames
+
+ fileid_renames = dict([(path, (old_fileid, new_fileid)) for (path, old_fileid, new_fileid) in determine_fileid_renames(wt.branch.repository.revision_tree(old_revid), wt.branch.repository.revision_tree(last_revid))])
+ old_fileids = []
+ new_fileids = []
+ new_root_id = None
+ # Adjust file ids in working tree
+ for path in sorted(fileid_renames.keys(), reverse=True):
+ if path != "":
+ old_fileids.append(fileid_renames[path][0])
+ new_fileids.append((path, fileid_renames[path][1]))
+ else:
+ new_root_id = fileid_renames[path][1]
+ new_fileids.reverse()
+ wt.unversion(old_fileids)
+ if new_root_id is not None:
+ wt.set_root_id(new_root_id)
+ wt.add([x[0] for x in new_fileids], [x[1] for x in new_fileids])
wt.set_last_revision(last_revid)
-
- # Adjust file ids in working tree
- for (old_fileid, new_fileid) in determine_fileid_renames(wt.branch.repository.revision_tree(old_revid), wt.basis_tree()):
- path = wt.id2path(old_fileid)
- wt.remove(path)
- wt.add([path], [new_fileid])
finally:
wt.unlock()
- return renames
+ return revid_renames
+
+
+def upgrade_tags(tags, repository, foreign_repository, new_mapping, mapping_registry,
+ allow_changes=False, verbose=False, branch_renames=None):
+ """Upgrade a tags dictionary."""
+ pb = ui.ui_factory.nested_progress_bar()
+ try:
+ tags_dict = tags.get_tag_dict()
+ for i, (name, revid) in enumerate(tags_dict.items()):
+ pb.update("upgrading tags", i, len(tags_dict))
+ if branch_renames is not None and revid in branch_renames:
+ renames = branch_renames
+ else:
+ renames = upgrade_repository(repository, foreign_repository,
+ revision_id=revid, new_mapping=new_mapping,
+ mapping_registry=mapping_registry,
+ allow_changes=allow_changes, verbose=verbose)
+ if revid in renames:
+ tags.set_tag(name, renames[revid])
+ finally:
+ pb.finished()
def upgrade_branch(branch, foreign_repository, new_mapping,
@@ -117,6 +153,9 @@
revision_id=revid, new_mapping=new_mapping,
mapping_registry=mapping_registry,
allow_changes=allow_changes, verbose=verbose)
+ upgrade_tags(branch.tags, branch.repository, foreign_repository,
+ new_mapping=new_mapping, mapping_registry=mapping_registry,
+ allow_changes=allow_changes, verbose=verbose)
if len(renames) > 0:
branch.generate_revision_history(renames[revid])
return renames
@@ -143,7 +182,7 @@
dictionary.
"""
rename_map = {}
- # Create a list of revisions that can be renamed during the upgade
+ # Create a list of revisions that can be renamed during the upgrade
for revid in revs:
assert isinstance(revid, str)
try:
@@ -176,7 +215,7 @@
from bzrlib.plugins.rebase.rebase import generate_transpose_plan
check_rebase_version(MIN_REBASE_VERSION)
- graph = repository.get_graph()
+ graph = foreign_repository.get_graph()
if revision_id is None:
potential = repository.all_revision_ids()
else:
@@ -201,8 +240,7 @@
heads = [revision_id]
plan = generate_transpose_plan(graph.iter_ancestry(heads), upgrade_map,
- graph,
- lambda revid: create_upgraded_revid(revid, new_mapping.upgrade_suffix))
+ graph, lambda revid: create_upgraded_revid(revid, new_mapping.upgrade_suffix))
def remove_parents((oldrevid, (newrevid, parents))):
return (oldrevid, newrevid)
upgrade_map.update(dict(map(remove_parents, plan.items())))
=== modified file 'tests/test_commit.py'
--- a/tests/test_commit.py 2008-09-09 13:45:01 +0000
+++ b/tests/test_commit.py 2008-09-09 21:25:51 +0000
@@ -138,9 +138,9 @@
wt = WorkingTree.open("dc")
wt.set_pending_merges(["some-ghost-revision"])
oldid = wt.path2id("foo")
- wt.commit(message="data")
+ wt.commit(message="data") # 1
wt.rename_one("foo", "bar")
- wt.commit(message="doe")
+ wt.commit(message="doe") # 2
paths = self.client_log(repos_url, 2, 0)[2][0]
self.assertEquals('D', paths["/foo"][0])
self.assertEquals('A', paths["/bar"][0])
More information about the bazaar-commits
mailing list