Rev 2252: Update file ids in working tree after dpush. in http://people.samba.org/bzr/jelmer/bzr-svn/0.5
Jelmer Vernooij
jelmer at samba.org
Mon Dec 8 20:28:15 GMT 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/0.5
------------------------------------------------------------
revno: 2252
revision-id: jelmer at samba.org-20081208202813-zsnpsfhyoqmo7zw5
parent: jelmer at samba.org-20081208200231-w1ufez92dkfvlhtr
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.5
timestamp: Mon 2008-12-08 21:28:13 +0100
message:
Update file ids in working tree after dpush.
modified:
foreign/__init__.py foreign.py-20080827193306-rxeku2c2obec90c4-1
foreign/upgrade.py upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
tests/test_push.py test_push.py-20070201165715-g2ievcdfqi33wqsy-1
=== modified file 'foreign/__init__.py'
--- a/foreign/__init__.py 2008-12-08 20:02:31 +0000
+++ b/foreign/__init__.py 2008-12-08 20:28:13 +0000
@@ -132,6 +132,7 @@
from bzrlib.errors import BzrCommandError, NoWorkingTree
from bzrlib.trace import info
from bzrlib.workingtree import WorkingTree
+ from upgrade import update_workingtree_fileids
if directory is None:
directory = "."
@@ -169,6 +170,13 @@
if source_wt is not None:
source_wt.pull(target_branch, overwrite=True,
stop_revision=new_last_revid)
+ source_wt.lock_write()
+ try:
+ update_workingtree_fileids(source_wt,
+ source_wt.branch.repository.revision_tree(old_last_revid),
+ source_wt.branch.repository.revision_tree(new_last_revid))
+ finally:
+ source_wt.unlock()
else:
source_branch.pull(target_branch, overwrite=True,
stop_revision=new_last_revid)
=== modified file 'foreign/upgrade.py'
--- a/foreign/upgrade.py 2008-11-25 01:04:07 +0000
+++ b/foreign/upgrade.py 2008-12-08 20:28:13 +0000
@@ -78,6 +78,31 @@
yield new_tree.id2path(new_file_id), old_file_id, new_file_id
+def update_workingtree_fileids(wt, old_tree, new_tree):
+ """Update all file ids in wt according to old_tree/new_tree.
+
+ old_tree and new_tree should be two RevisionTree's that differ only
+ in file ids.
+ """
+ fileid_renames = dict([(path, (old_fileid, new_fileid)) for (path, old_fileid, new_fileid) in determine_fileid_renames(old_tree, new_tree)])
+ 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(new_tree.get_revision_id())
+
+
def upgrade_workingtree(wt, foreign_repository, new_mapping, mapping_registry,
allow_changes=False, verbose=False):
"""Upgrade a working tree.
@@ -93,24 +118,10 @@
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)
+
+ old_tree = wt.branch.repository.revision_tree(old_revid)
+ new_tree = wt.branch.repository.revision_tree(last_revid)
+ update_workingtree_fileids(wt, old_tree, new_tree)
finally:
wt.unlock()
=== modified file 'tests/test_push.py'
--- a/tests/test_push.py 2008-12-08 19:56:16 +0000
+++ b/tests/test_push.py 2008-12-08 20:28:13 +0000
@@ -114,7 +114,7 @@
wt.add(["foo/bliel"])
newid2 = wt.commit(message="Commit from Bzr")
- revid_map = dpush(self.svndir.open_branch(), self.bzrdir.open_branch())
+ revid_map, fileid_map = dpush(self.svndir.open_branch(), self.bzrdir.open_branch())
self.assertEquals(set([newid1, newid2]), set(revid_map.keys()))
repos = self.svndir.find_repository()
More information about the bazaar-commits
mailing list