Rev 1795: Transform fileids in workingtree during upgrade. in file:///data/jelmer/bzr-svn/trunk/

Jelmer Vernooij jelmer at samba.org
Thu Sep 4 08:32:59 BST 2008


At file:///data/jelmer/bzr-svn/trunk/

------------------------------------------------------------
revno: 1795
revision-id: jelmer at samba.org-20080904073257-m61ps9eh1kqnqltp
parent: jelmer at samba.org-20080904070124-g6a5h455j0sypfcc
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Thu 2008-09-04 09:32:57 +0200
message:
  Transform fileids in workingtree during upgrade.
modified:
  TODO                           todo-20060729211917-2kpobww0zyvvo0j2-1
  upgrade.py                     upgrade.py-20070106192108-0rakplee2lzah4gs-1
=== modified file 'TODO'
--- a/TODO	2008-09-01 13:22:31 +0000
+++ b/TODO	2008-09-04 07:32:57 +0000
@@ -5,7 +5,6 @@
   + remove Mapping.get_guessed_layout()
 
 - generate deltas rather than fulltexts when creating file id maps
-- transform file ids in workingtree in svn-upgrade
 
 tests:
 - more blackbox tests

=== modified file 'upgrade.py'
--- a/upgrade.py	2008-09-01 20:53:16 +0000
+++ b/upgrade.py	2008-09-04 07:32:57 +0000
@@ -47,17 +47,31 @@
         return revid + mapping_suffix + upgrade_suffix
 
 
+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 new_file_id is not None:
+            yield old_file_id, new_file_id
+
+
 def upgrade_workingtree(wt, svn_repository, new_mapping=None, 
                         allow_changes=False, verbose=False):
     """Upgrade a working tree.
 
     :param svn_repository: Subversion repository object
     """
+    orig_basis_tree = wt.basis_tree()
     renames = upgrade_branch(wt.branch, svn_repository, new_mapping=new_mapping,
                              allow_changes=allow_changes, verbose=verbose)
     last_revid = wt.branch.last_revision()
-    wt.set_parent_trees([(last_revid, wt.branch.repository.revision_tree(last_revid))])
-    # TODO: Should also adjust file ids in working tree if necessary
+    wt.set_last_revision(last_revid)
+
+    # Adjust file ids in working tree
+    for (old_fileid, new_fileid) in determine_fileid_renames(orig_basis_tree, wt.basis_tree()):
+        path = wt.id2path(old_fileid)
+        wt.remove(path)
+        wt.add([path], [new_fileid])
+
     return renames
 
 




More information about the bazaar-commits mailing list