Rev 5806: (jelmer) Split Inventory._get_mutable_inventory() out into in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Apr 20 01:22:16 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5806 [merge]
revision-id: pqm at pqm.ubuntu.com-20110420012213-nagud1jxln5o6j36
parent: pqm at pqm.ubuntu.com-20110419213424-01noh6bpf72g1cn2
parent: jelmer at samba.org-20110419105124-09pxxlxj6f4285x1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-04-20 01:22:13 +0000
message:
(jelmer) Split Inventory._get_mutable_inventory() out into
mutable_inventory_from_tree. (Jelmer Vernooij)
modified:
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/memorytree.py memorytree.py-20060906023413-4wlkalbdpsxi2r4y-1
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
bzrlib/tests/per_repository/test_fileid_involved.py test_file_involved.py-20051215205901-728a172d1014daaa
bzrlib/tests/test_inv.py testinv.py-20050722220913-1dc326138d1a5892
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2011-04-05 01:12:15 +0000
+++ b/bzrlib/inventory.py 2011-04-19 10:42:59 +0000
@@ -822,14 +822,6 @@
file_id, self[file_id]))
return delta
- def _get_mutable_inventory(self):
- """Returns a mutable copy of the object.
-
- Some inventories are immutable, yet working trees, for example, needs
- to mutate exisiting inventories instead of creating a new one.
- """
- raise NotImplementedError(self._get_mutable_inventory)
-
def make_entry(self, kind, name, parent_id, file_id=None):
"""Simple thunk to bzrlib.inventory.make_entry."""
return make_entry(kind, name, parent_id, file_id)
@@ -1133,10 +1125,6 @@
other.add(entry.copy())
return other
- def _get_mutable_inventory(self):
- """See CommonInventory._get_mutable_inventory."""
- return copy.deepcopy(self)
-
def __iter__(self):
"""Iterate over all file-ids."""
return iter(self._byid)
@@ -1619,14 +1607,6 @@
self._fileid_to_entry_cache[result.file_id] = result
return result
- def _get_mutable_inventory(self):
- """See CommonInventory._get_mutable_inventory."""
- entries = self.iter_entries()
- inv = Inventory(None, self.revision_id)
- for path, inv_entry in entries:
- inv.add(inv_entry.copy())
- return inv
-
def create_by_apply_delta(self, inventory_delta, new_revision_id,
propagate_caches=False):
"""Create a new CHKInventory by applying inventory_delta to this one.
@@ -2400,3 +2380,15 @@
raise errors.InconsistentDelta(new_path, item[1],
"new_path with no entry")
yield item
+
+
+def mutable_inventory_from_tree(tree):
+ """Create a new inventory that has the same contents as a specified tree.
+
+ :param tree: Revision tree to create inventory from
+ """
+ entries = tree.iter_entries_by_dir()
+ inv = Inventory(None, tree.get_revision_id())
+ for path, inv_entry in entries:
+ inv.add(inv_entry.copy())
+ return inv
=== modified file 'bzrlib/memorytree.py'
--- a/bzrlib/memorytree.py 2011-04-11 10:05:16 +0000
+++ b/bzrlib/memorytree.py 2011-04-19 10:42:59 +0000
@@ -28,6 +28,7 @@
revision as _mod_revision,
)
from bzrlib.decorators import needs_read_lock
+from bzrlib.inventory import Inventory
from bzrlib.osutils import sha_file
from bzrlib.mutabletree import needs_tree_write_lock
from bzrlib.transport.memory import MemoryTransport
@@ -219,11 +220,12 @@
self._parent_ids = []
else:
self._parent_ids = [self._branch_revision_id]
- self._inventory = self._basis_tree._inventory._get_mutable_inventory()
+ self._inventory = Inventory(None, self._basis_tree.get_revision_id())
self._file_transport = MemoryTransport()
# TODO copy the revision trees content, or do it lazy, or something.
- inventory_entries = self._inventory.iter_entries()
+ inventory_entries = self._basis_tree.iter_entries_by_dir()
for path, entry in inventory_entries:
+ self._inventory.add(entry.copy())
if path == '':
continue
if entry.kind == 'directory':
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2011-04-17 18:24:56 +0000
+++ b/bzrlib/mutabletree.py 2011-04-19 10:42:59 +0000
@@ -30,9 +30,9 @@
bzrdir,
errors,
hooks,
+ inventory as _mod_inventory,
osutils,
revisiontree,
- inventory,
trace,
tree,
)
@@ -620,7 +620,7 @@
# Same as in _add_one below, if the inventory doesn't
# think this is a directory, update the inventory
if this_ie.kind != 'directory':
- this_ie = inventory.make_entry('directory',
+ this_ie = _mod_inventory.make_entry('directory',
this_ie.name, this_ie.parent_id, this_id)
del inv[this_id]
inv.add(this_ie)
@@ -693,7 +693,7 @@
# TODO: Consider re-evaluating the need for this with CHKInventory
# we don't strictly need to mutate an inventory for this
# it only makes sense when apply_delta is cheaper than get_inventory()
- inventory = basis.inventory._get_mutable_inventory()
+ inventory = _mod_inventory.mutable_inventory_from_tree(basis)
basis.unlock()
inventory.apply_delta(delta)
rev_tree = revisiontree.InventoryRevisionTree(self.branch.repository,
@@ -701,8 +701,6 @@
self.set_parent_trees([(new_revid, rev_tree)])
-
-
class MutableTreeHooks(hooks.Hooks):
"""A dictionary mapping a hook name to a list of callables for mutabletree
hooks.
@@ -811,7 +809,7 @@
if parent_ie.kind != 'directory':
# nb: this relies on someone else checking that the path we're using
# doesn't contain symlinks.
- new_parent_ie = inventory.make_entry('directory', parent_ie.name,
+ new_parent_ie = _mod_inventory.make_entry('directory', parent_ie.name,
parent_ie.parent_id, parent_ie.file_id)
del inv[parent_ie.file_id]
inv.add(new_parent_ie)
=== modified file 'bzrlib/tests/per_repository/test_fileid_involved.py'
--- a/bzrlib/tests/per_repository/test_fileid_involved.py 2010-02-10 17:52:08 +0000
+++ b/bzrlib/tests/per_repository/test_fileid_involved.py 2011-04-19 10:42:59 +0000
@@ -19,6 +19,7 @@
from bzrlib import (
errors,
+ inventory,
remote,
revision as _mod_revision,
tests,
@@ -325,7 +326,7 @@
('add', ('a', 'a-file-id', 'file', 'some content\n'))])
b = builder.get_branch()
old_rt = b.repository.revision_tree('A-id')
- new_inv = old_rt.inventory._get_mutable_inventory()
+ new_inv = inventory.mutable_inventory_from_tree(old_rt)
new_inv.revision_id = 'B-id'
new_inv['a-file-id'].revision = 'ghost-id'
new_rev = _mod_revision.Revision('B-id',
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2011-04-14 07:53:38 +0000
+++ b/bzrlib/tests/test_inv.py 2011-04-19 10:51:24 +0000
@@ -34,6 +34,7 @@
InventoryDirectory,
InventoryEntry,
TreeReference,
+ mutable_inventory_from_tree,
)
from bzrlib.tests import (
TestCase,
@@ -1436,3 +1437,29 @@
inv = self.make_simple_inventory()
self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id', 'top-id',
'subsub-file1-id'], inv, ['top-id', 'subsub-file1-id'])
+
+
+class TestMutableInventoryFromTree(TestCaseWithTransport):
+
+ def test_empty(self):
+ repository = self.make_repository('.')
+ tree = repository.revision_tree(revision.NULL_REVISION)
+ inv = mutable_inventory_from_tree(tree)
+ self.assertEquals(revision.NULL_REVISION, inv.revision_id)
+ self.assertEquals(0, len(inv))
+
+ def test_some_files(self):
+ wt = self.make_branch_and_tree('.')
+ self.build_tree(['a'])
+ wt.add(['a'], ['thefileid'])
+ revid = wt.commit("commit")
+ tree = wt.branch.repository.revision_tree(revid)
+ inv = mutable_inventory_from_tree(tree)
+ self.assertEquals(revid, inv.revision_id)
+ self.assertEquals(2, len(inv))
+ self.assertEquals("a", inv['thefileid'].name)
+ # The inventory should be mutable and independent of
+ # the original tree
+ self.assertFalse(tree.inventory['thefileid'].executable)
+ inv['thefileid'].executable = True
+ self.assertFalse(tree.inventory['thefileid'].executable)
More information about the bazaar-commits
mailing list