Rev 5791: Move the logic about InventoryDirectory => TreeReference into iter_entries in http://bazaar.launchpad.net/~jameinel/bzr/2.4-wt-inventory-tree-reference-764677

John Arbash Meinel john at arbash-meinel.com
Mon May 9 13:51:57 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/2.4-wt-inventory-tree-reference-764677

------------------------------------------------------------
revno: 5791
revision-id: john at arbash-meinel.com-20110509135143-9o1gtycdhmd29ayj
parent: john at arbash-meinel.com-20110506145419-0vz67uunkutxipso
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-wt-inventory-tree-reference-764677
timestamp: Mon 2011-05-09 15:51:43 +0200
message:
  Move the logic about InventoryDirectory => TreeReference into iter_entries
  rather than having it in _generate_inventory.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_workingtree.py'
--- a/bzrlib/tests/test_workingtree.py	2011-05-05 01:58:00 +0000
+++ b/bzrlib/tests/test_workingtree.py	2011-05-09 13:51:43 +0000
@@ -236,6 +236,47 @@
                 workingtree.WorkingTreeFormat.get_formats))
 
 
+class TestWorkingTreeIterEntriesByDir_wSubtrees(TestCaseWithTransport):
+
+    def make_simple_tree(self):
+        tree = self.make_branch_and_tree('tree', format='development-subtree')
+        self.build_tree(['tree/a/', 'tree/a/b/', 'tree/a/b/c'])
+        tree.set_root_id('root-id')
+        tree.add(['a', 'a/b', 'a/b/c'], ['a-id', 'b-id', 'c-id'])
+        tree.commit('initial')
+        return tree
+
+    def test_just_directory(self):
+        tree = self.make_simple_tree()
+        self.assertEqual([('directory', 'root-id'),
+                          ('directory', 'a-id'),
+                          ('directory', 'b-id'),
+                          ('file', 'c-id')],
+                         [(ie.kind, ie.file_id)
+                          for path, ie in tree.iter_entries_by_dir()])
+        subtree = self.make_branch_and_tree('tree/a/b')
+        self.assertEqual([('tree-reference', 'b-id')],
+                         [(ie.kind, ie.file_id)
+                          for path, ie in tree.iter_entries_by_dir(['b-id'])])
+
+    def test_direct_subtree(self):
+        tree = self.make_simple_tree()
+        subtree = self.make_branch_and_tree('tree/a/b')
+        self.assertEqual([('directory', 'root-id'),
+                          ('directory', 'a-id'),
+                          ('tree-reference', 'b-id')],
+                         [(ie.kind, ie.file_id)
+                          for path, ie in tree.iter_entries_by_dir()])
+
+    def test_indirect_subtree(self):
+        tree = self.make_simple_tree()
+        subtree = self.make_branch_and_tree('tree/a')
+        self.assertEqual([('directory', 'root-id'),
+                          ('tree-reference', 'a-id')],
+                         [(ie.kind, ie.file_id)
+                          for path, ie in tree.iter_entries_by_dir()])
+
+
 class TestWorkingTreeFormatRegistry(TestCase):
 
     def setUp(self):

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2011-05-04 22:23:20 +0000
+++ b/bzrlib/workingtree.py	2011-05-09 13:51:43 +0000
@@ -572,6 +572,34 @@
     def id2abspath(self, file_id):
         return self.abspath(self.id2path(file_id))
 
+    def _check_for_tree_references(self, iterator):
+        """See if directories have become tree-references."""
+        blocked_parent_ids = set()
+        for path, ie in iterator:
+            if ie.parent_id in blocked_parent_ids:
+                # This entry was pruned because one of its parents became a
+                # TreeReference. If this is a directory, mark it as blocked.
+                if ie.kind == 'directory':
+                    blocked_parent_ids.add(ie.file_id)
+                continue
+            if ie.kind == 'directory' and self._directory_is_tree_reference(path):
+                # This InventoryDirectory needs to be a TreeReference
+                ie = inventory.TreeReference(ie.file_id, ie.name, ie.parent_id)
+                blocked_parent_ids.add(ie.file_id)
+            yield path, ie
+
+    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
+        """See Tree.iter_entries_by_dir()"""
+        # The only trick here is that if we supports_tree_reference then we
+        # need to detect if a directory becomes a tree-reference.
+        iterator = super(WorkingTree, self).iter_entries_by_dir(
+                specific_file_ids=specific_file_ids,
+                yield_parents=yield_parents)
+        if not self.supports_tree_reference():
+            return iterator
+        else:
+            return self._check_for_tree_references(iterator)
+
     def get_file_size(self, file_id):
         """See Tree.get_file_size"""
         # XXX: this returns the on-disk size; it should probably return the

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2011-05-06 14:53:40 +0000
+++ b/bzrlib/workingtree_4.py	2011-05-09 13:51:43 +0000
@@ -318,9 +318,6 @@
                 name_unicode = utf8_decode(name)[0]
                 file_id = key[2]
                 kind = minikind_to_kind[minikind]
-                if (name and kind == 'directory'
-                    and self._directory_is_tree_reference(name_unicode)):
-                    kind = 'tree-reference'
                 inv_entry = factory[kind](file_id, name_unicode,
                                           parent_ie.file_id)
                 if kind == 'file':



More information about the bazaar-commits mailing list