Rev 4293: (aaron, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Apr 15 17:24:59 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4293
revision-id: pqm at pqm.ubuntu.com-20090415162451-bmgy1sh0fgs1cv7p
parent: pqm at pqm.ubuntu.com-20090415082033-tds4zs962x6kwc2c
parent: jelmer at samba.org-20090415111359-td8oouuqs7mc9knk
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-04-15 17:24:51 +0100
message:
  (aaron,
  	jelmer) Use TreeTransform to update file ids in working tree after
  	dpush.
modified:
  bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
  bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4285.3.2
    revision-id: jelmer at samba.org-20090415111359-td8oouuqs7mc9knk
    parent: aaron at aaronbentley.com-20090413191143-miq7d5z8hjjljsu0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: dpush
    timestamp: Wed 2009-04-15 13:13:59 +0200
    message:
      Remove unused functions for updating the file ids of a tree.
    modified:
      bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
      bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4285.3.1
    revision-id: aaron at aaronbentley.com-20090413191143-miq7d5z8hjjljsu0
    parent: pqm at pqm.ubuntu.com-20090411130119-4kn8b6070uyqg5xx
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: bzr.dev
    timestamp: Mon 2009-04-13 15:11:43 -0400
    message:
      Implement dpush via sexy APIs
    modified:
      bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
      bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2009-04-09 21:50:23 +0000
+++ b/bzrlib/foreign.py	2009-04-15 11:13:59 +0000
@@ -28,6 +28,7 @@
     errors,
     osutils,
     registry,
+    transform,
     )
 """)
 
@@ -269,57 +270,28 @@
         raise NotImplementedError(self.dpull)
 
 
-def _determine_fileid_renames(old_inv, new_inv):
-    """Determine the file ids based on a old and a new inventory that 
-    are equal in content.
-
-    :param old_inv: Old inventory
-    :param new_inv: New inventory
-    :return: Dictionary a (old_id, new_id) tuple for each path in the 
-        inventories.
-    """
-    ret = {}
-    if len(old_inv) != len(new_inv):
-        raise AssertionError("Inventories are not of the same size")
-    for old_file_id in old_inv:
-        path = old_inv.id2path(old_file_id)
-        new_file_id = new_inv.path2id(path)
-        if new_file_id is None:
-            raise AssertionError(
-                "Unable to find %s in new inventory" % old_file_id)
-        ret[path] = (old_file_id, new_file_id)
-    return ret
-
-
-def update_workinginv_fileids(wt, old_inv, new_inv):
-    """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 = _determine_fileid_renames(old_inv, new_inv)
-    old_fileids = []
-    new_fileids = []
-    new_root_id = None
-    # Adjust file ids in working tree
-    # Sorted, so we process parents before children
-    for path in sorted(fileid_renames.keys()):
-        (old_fileid, new_fileid) = fileid_renames[path]
-        if path != "":
-            new_fileids.append((path, new_fileid))
-            # unversion() works recursively so we only have to unversion the 
-            # top-level. Unfortunately unversioning / is not supported yet, 
-            # so unversion its children instead and use set_root_id() for /
-            if old_inv[old_fileid].parent_id == old_inv.root.file_id:
-                old_fileids.append(old_fileid)
-        else:
-            new_root_id = new_fileid
-    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_inv.revision_id)
+def update_workingtree_fileids(wt, target_tree):
+    """Update the file ids in a working tree based on another tree.
+
+    :param wt: Working tree in which to update file ids
+    :param target_tree: Tree to retrieve new file ids from, based on path
+    """
+    tt = transform.TreeTransform(wt)
+    try:
+        for f, p, c, v, d, n, k, e in target_tree.iter_changes(wt):
+            if v == (True, False):
+                trans_id = tt.trans_id_tree_path(p[0])
+                tt.unversion_file(trans_id)
+            elif v == (False, True):
+                trans_id = tt.trans_id_tree_path(p[1])
+                tt.version_file(f, trans_id)
+        tt.apply()
+    finally:
+        tt.finalize()
+    if len(wt.get_parent_ids()) == 1:
+        wt.set_parent_trees([(target_tree.get_revision_id(), target_tree)])
+    else:
+        wt.set_last_revision(target_tree.get_revision_id())
 
 
 class cmd_dpush(Command):
@@ -385,14 +357,10 @@
                 if source_wt is not None and old_last_revid != new_last_revid:
                     source_wt.lock_write()
                     try:
-                        update_workinginv_fileids(source_wt, 
-                            source_wt.branch.repository.get_inventory(
-                                old_last_revid),
-                            source_wt.branch.repository.get_inventory(
-                                new_last_revid))
+                        target = source_wt.branch.repository.revision_tree(
+                            new_last_revid)
+                        update_workingtree_fileids(source_wt, target)
                     finally:
                         source_wt.unlock()
         finally:
             target_branch.unlock()
-
-

=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py	2009-04-09 21:50:23 +0000
+++ b/bzrlib/tests/test_foreign.py	2009-04-15 11:13:59 +0000
@@ -309,46 +309,21 @@
 
 
 class WorkingTreeFileUpdateTests(TestCaseWithTransport):
-    """Tests for _determine_fileid_renames()."""
-
-    def test_det_renames_same(self):
-        a = Inventory()
-        a.add_path("bla", "directory", "bla-a")
-        b = Inventory()
-        b.add_path("bla", "directory", "bla-a")
-        self.assertEquals({
-            '': ('TREE_ROOT', 'TREE_ROOT'), 
-            'bla': ('bla-a', 'bla-a')},
-            foreign._determine_fileid_renames(a, b))
-
-    def test_det_renames_simple(self):
-        a = Inventory()
-        a.add_path("bla", "directory", "bla-a")
-        b = Inventory()
-        b.add_path("bla", "directory", "bla-b")
-        self.assertEquals({
-            '': ('TREE_ROOT', 'TREE_ROOT'), 
-            'bla': ('bla-a', 'bla-b'),
-            }, foreign._determine_fileid_renames(a, b))
-
-    def test_det_renames_root(self):
-        a = Inventory()
-        a.add_path("", "directory", "bla-a")
-        b = Inventory()
-        b.add_path("", "directory", "bla-b")
-        self.assertEquals(
-                {"": ("bla-a", "bla-b")},
-                foreign._determine_fileid_renames(a, b))
-
-    def test_update_workinginv(self):
-        a = Inventory()
-        a.add_path("bla", "directory", "bla-a")
-        b = Inventory()
-        b.add_path("bla", "directory", "bla-b")
+    """Tests for update_workingtree_fileids()."""
+
+    def test_update_workingtree(self):
         wt = self.make_branch_and_tree('br1')
         self.build_tree_contents([('br1/bla', 'original contents\n')])
         wt.add('bla', 'bla-a')
-        foreign.update_workinginv_fileids(wt, a, b)
+        wt.commit('bla-a')
+        target = wt.bzrdir.sprout('br2').open_workingtree()
+        target.unversion(['bla-a'])
+        target.add('bla', 'bla-b')
+        target.commit('bla-b')
+        target_basis = target.basis_tree()
+        target_basis.lock_read()
+        self.addCleanup(target_basis.unlock)
+        foreign.update_workingtree_fileids(wt, target_basis)
         wt.lock_read()
         try:
             self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory))




More information about the bazaar-commits mailing list