Rev 6001: (mbp) remove __contains__ methods from inventory and dict (Martin Pool) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Jun 28 19:12:14 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6001 [merge]
revision-id: pqm at pqm.ubuntu.com-20110628191210-bwblsxn26kyu3swl
parent: pqm at pqm.ubuntu.com-20110628181601-fw80wa3q857wrk8q
parent: mbp at canonical.com-20110628172526-10cok2s17dvw7x62
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2011-06-28 19:12:10 +0000
message:
(mbp) remove __contains__ methods from inventory and dict (Martin Pool)
modified:
bzrlib/add.py add.py-20050323030017-3a77d63feda58e33
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/serializer/v08.py v06.py-20051119041339-ee43f97270b01823
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/log.py log.py-20050505065812-c40ce11702fe5fb1
bzrlib/merge.py merge.py-20050513021216-953b65a438527106
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
bzrlib/plugins/weave_fmt/test_repository.py test_repository.py-20110111044027-wcf1gzbx2k90apb7-1
bzrlib/tests/blackbox/test_join.py test_join.py-20060928210902-95dkqa6boh8uq92b-1
bzrlib/tests/per_inventory/basics.py basics.py-20070903044446-kdjwbiu1p1zi9phs-1
bzrlib/tests/per_tree/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
bzrlib/tests/test_shelf.py test_prepare_shelf.p-20081005181341-n74qe6gu1e65ad4v-2
bzrlib/tests/test_smart_add.py test_smart_add.py-20050824235919-c60dcdb0c8e999ce
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/tree.py tree.py-20050309040759-9d5f2496be663e77
bzrlib/vf_repository.py vf_repository.py-20110502151858-yh9nnoxpokg86unk-1
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/add.py'
--- a/bzrlib/add.py 2011-05-23 12:30:49 +0000
+++ b/bzrlib/add.py 2011-06-14 02:21:41 +0000
@@ -86,7 +86,7 @@
Else, we look for an entry in the base tree with the same path.
"""
- if (parent_ie.file_id in self.base_tree):
+ if self.base_tree.has_id(parent_ie.file_id):
base_parent_ie = self.base_tree.inventory[parent_ie.file_id]
base_child_ie = base_parent_ie.children.get(
osutils.basename(path))
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2011-06-27 15:42:09 +0000
+++ b/bzrlib/builtins.py 2011-06-28 17:25:26 +0000
@@ -796,8 +796,9 @@
require_versioned=True)
# find_ids_across_trees may include some paths that don't
# exist in 'tree'.
- entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
- for file_id in file_ids if file_id in tree)
+ entries = sorted(
+ (tree.id2path(file_id), tree.inventory[file_id])
+ for file_id in file_ids if tree.has_id(file_id))
else:
entries = tree.inventory.entries()
@@ -2154,7 +2155,7 @@
basis_inv = basis.inventory
inv = wt.inventory
for file_id in inv:
- if file_id in basis_inv:
+ if basis_inv.has_id(file_id):
continue
if inv.is_root(file_id) and len(basis_inv) == 0:
continue
=== modified file 'bzrlib/bundle/serializer/v08.py'
--- a/bzrlib/bundle/serializer/v08.py 2011-04-18 15:53:40 +0000
+++ b/bzrlib/bundle/serializer/v08.py 2011-06-14 02:21:41 +0000
@@ -263,7 +263,7 @@
def do_diff(file_id, old_path, new_path, action, force_binary):
def tree_lines(tree, require_text=False):
- if file_id in tree:
+ if tree.has_id(file_id):
tree_file = tree.get_file(file_id)
if require_text is True:
tree_file = text_file(tree_file)
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2011-06-19 02:48:01 +0000
+++ b/bzrlib/commit.py 2011-06-28 17:25:26 +0000
@@ -723,7 +723,7 @@
if self.specific_files or self.exclude:
specific_files = self.specific_files or []
for path, old_ie in self.basis_inv.iter_entries():
- if old_ie.file_id in self.builder.new_inventory:
+ if self.builder.new_inventory.has_id(old_ie.file_id):
# already added - skip.
continue
if (is_inside_any(specific_files, path)
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2011-04-19 10:42:59 +0000
+++ b/bzrlib/inventory.py 2011-06-14 02:21:41 +0000
@@ -48,6 +48,10 @@
)
from bzrlib.static_tuple import StaticTuple
+from bzrlib.symbol_versioning import (
+ deprecated_in,
+ deprecated_method,
+ )
class InventoryEntry(object):
@@ -100,8 +104,6 @@
InventoryDirectory('2325', 'wibble', parent_id='123', revision=None)
>>> i.path2id('src/wibble')
'2325'
- >>> '2325' in i
- True
>>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None, revision=None)
>>> i['2326']
@@ -170,7 +172,7 @@
candidates = {}
# identify candidate head revision ids.
for inv in previous_inventories:
- if self.file_id in inv:
+ if inv.has_id(self.file_id):
ie = inv[self.file_id]
if ie.revision in candidates:
# same revision value in two different inventories:
@@ -629,15 +631,16 @@
inserted, other than through the Inventory API.
"""
+ @deprecated_method(deprecated_in((2, 4, 0)))
def __contains__(self, file_id):
"""True if this entry contains a file with given id.
>>> inv = Inventory()
>>> inv.add(InventoryFile('123', 'foo.c', ROOT_ID))
InventoryFile('123', 'foo.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
- >>> '123' in inv
+ >>> inv.has_id('123')
True
- >>> '456' in inv
+ >>> inv.has_id('456')
False
Note that this method along with __iter__ are not encouraged for use as
@@ -756,7 +759,7 @@
if (not yield_parents and specific_file_ids is not None and
len(specific_file_ids) == 1):
file_id = list(specific_file_ids)[0]
- if file_id in self:
+ if self.has_id(file_id):
yield self.id2path(file_id), self[file_id]
return
from_dir = self.root
@@ -772,7 +775,7 @@
parents = set()
byid = self
def add_ancestors(file_id):
- if file_id not in byid:
+ if not byid.has_id(file_id):
return
parent_id = byid[file_id].parent_id
if parent_id is None:
@@ -962,7 +965,7 @@
>>> inv.path2id('hello.c')
'123-123'
- >>> '123-123' in inv
+ >>> inv.has_id('123-123')
True
There are iterators over the contents:
@@ -1231,10 +1234,10 @@
>>> inv = Inventory()
>>> inv.add(InventoryFile('123', 'foo.c', ROOT_ID))
InventoryFile('123', 'foo.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
- >>> '123' in inv
+ >>> inv.has_id('123')
True
>>> del inv['123']
- >>> '123' in inv
+ >>> inv.has_id('123')
False
"""
ie = self[file_id]
=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py 2011-06-16 12:50:32 +0000
+++ b/bzrlib/log.py 2011-06-28 15:39:43 +0000
@@ -109,7 +109,7 @@
revno = 1
for revision_id in branch.revision_history():
this_inv = branch.repository.get_inventory(revision_id)
- if file_id in this_inv:
+ if this_inv.has_id(file_id):
this_ie = this_inv[file_id]
this_path = this_inv.id2path(file_id)
else:
=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py 2011-06-28 15:58:20 +0000
+++ b/bzrlib/merge.py 2011-06-28 17:25:26 +0000
@@ -990,12 +990,12 @@
else:
lca_entries.append(lca_ie)
- if file_id in base_inventory:
+ if base_inventory.has_id(file_id):
base_ie = base_inventory[file_id]
else:
base_ie = _none_entry
- if file_id in this_inventory:
+ if this_inventory.has_id(file_id):
this_ie = this_inventory[file_id]
else:
this_ie = _none_entry
@@ -1106,9 +1106,10 @@
other_root = self.tt.trans_id_file_id(other_root_file_id)
if other_root == self.tt.root:
return
- if self.other_tree.inventory.root.file_id in self.this_tree.inventory:
- # the other tree's root is a non-root in the current tree (as when
- # a previously unrelated branch is merged into another)
+ if self.this_tree.inventory.has_id(
+ self.other_tree.inventory.root.file_id):
+ # the other tree's root is a non-root in the current tree (as
+ # when a previously unrelated branch is merged into another)
return
if self.tt.final_kind(other_root) is not None:
other_root_is_present = True
@@ -1166,7 +1167,7 @@
@staticmethod
def contents_sha1(tree, file_id):
"""Determine the sha1 of the file contents (used as a key method)."""
- if file_id not in tree:
+ if not tree.has_id(file_id):
return None
return tree.get_file_sha1(file_id)
@@ -1342,7 +1343,7 @@
def _do_merge_contents(self, file_id):
"""Performs a merge on file_id contents."""
def contents_pair(tree):
- if file_id not in tree:
+ if not tree.has_id(file_id):
return (None, None)
kind = tree.kind(file_id)
if kind == "file":
@@ -1923,7 +1924,7 @@
name_in_target = osutils.basename(self._target_subdir)
merge_into_root = subdir.copy()
merge_into_root.name = name_in_target
- if merge_into_root.file_id in self.this_tree.inventory:
+ if self.this_tree.inventory.has_id(merge_into_root.file_id):
# Give the root a new file-id.
# This can happen fairly easily if the directory we are
# incorporating is the root, and both trees have 'TREE_ROOT' as
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2011-06-16 13:28:23 +0000
+++ b/bzrlib/mutabletree.py 2011-06-19 02:24:39 +0000
@@ -162,7 +162,7 @@
if sub_tree_id == self.get_root_id():
raise errors.BadReferenceTarget(self, sub_tree,
'Trees have the same root id.')
- if sub_tree_id in self:
+ if self.has_id(sub_tree_id):
raise errors.BadReferenceTarget(self, sub_tree,
'Root id already present in tree')
self._add([sub_tree_path], [sub_tree_id], ['tree-reference'])
=== modified file 'bzrlib/plugins/weave_fmt/test_repository.py'
--- a/bzrlib/plugins/weave_fmt/test_repository.py 2011-02-19 15:23:08 +0000
+++ b/bzrlib/plugins/weave_fmt/test_repository.py 2011-06-28 15:39:43 +0000
@@ -311,7 +311,7 @@
inp = StringIO(_working_inventory_v4)
inv = xml4.serializer_v4.read_inventory(inp)
self.assertEqual(len(inv), 4)
- self.assert_('bar-20050901064931-73b4b1138abc9cd2' in inv)
+ self.assert_(inv.has_id('bar-20050901064931-73b4b1138abc9cd2'))
def test_unpack_revision(self):
"""Test unpacking a canned revision v4"""
=== modified file 'bzrlib/tests/blackbox/test_join.py'
--- a/bzrlib/tests/blackbox/test_join.py 2010-04-28 07:53:34 +0000
+++ b/bzrlib/tests/blackbox/test_join.py 2011-06-14 02:21:41 +0000
@@ -74,13 +74,13 @@
sub_tree.lock_read()
self.addCleanup(sub_tree.unlock)
self.assertEqual('file1-id', sub_tree.path2id('file1'))
- self.assertTrue('file1-id' in sub_tree)
+ self.assertTrue(sub_tree.has_id('file1-id'))
self.assertEqual('subtree-root-id', sub_tree.path2id(''))
self.assertEqual('', sub_tree.id2path('subtree-root-id'))
self.assertIs(None, base_tree.path2id('subtree/file1'))
base_tree.lock_read()
self.addCleanup(base_tree.unlock)
- self.assertTrue('file1-id' not in base_tree)
+ self.assertFalse(base_tree.has_id('file1-id'))
self.assertEqual('subtree-root-id', base_tree.path2id('subtree'))
self.assertEqual('subtree', base_tree.id2path('subtree-root-id'))
@@ -95,5 +95,3 @@
retcode=3)
self.assertContainsRe(err, r"Can't join trees")
self.assertContainsRe(err, r"use bzr upgrade")
-
-
=== modified file 'bzrlib/tests/per_inventory/basics.py'
--- a/bzrlib/tests/per_inventory/basics.py 2009-09-24 20:09:36 +0000
+++ b/bzrlib/tests/per_inventory/basics.py 2011-06-14 02:21:41 +0000
@@ -35,6 +35,9 @@
from bzrlib.tests.per_inventory import TestCaseWithInventory
+from bzrlib.symbol_versioning import (
+ deprecated_in,
+ )
class TestInventory(TestCaseWithInventory):
@@ -149,7 +152,10 @@
inv = self.inv_to_test_inv(inv)
self.assertEqual(inv.path2id('src'), 'src-id')
self.assertEqual(inv.path2id('src/bye.c'), 'bye-id')
- self.assertTrue('src-id' in inv)
+ self.assertTrue(
+ self.applyDeprecated(
+ deprecated_in((2, 4, 0)),
+ inv.__contains__, 'src-id'))
def test_non_directory_children(self):
"""Test path2id when a parent directory has no children"""
=== modified file 'bzrlib/tests/per_tree/test_tree.py'
--- a/bzrlib/tests/per_tree/test_tree.py 2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/per_tree/test_tree.py 2011-06-14 02:21:41 +0000
@@ -24,6 +24,10 @@
)
from bzrlib.tests import TestSkipped
from bzrlib.tests.per_tree import TestCaseWithTree
+from bzrlib.symbol_versioning import (
+ deprecated_in,
+ )
+
class TestAnnotate(TestCaseWithTree):
@@ -94,7 +98,8 @@
tree.lock_read()
self.addCleanup(tree.unlock)
path = tree.id2path('sub-root')
- self.assertEqual('sub-1', tree.get_reference_revision('sub-root', path))
+ self.assertEqual('sub-1',
+ tree.get_reference_revision('sub-root', path))
def test_iter_references(self):
tree = self.create_nested()
@@ -257,8 +262,14 @@
tree = self._convert_tree(work_tree)
tree.lock_read()
self.addCleanup(tree.unlock)
- self.assertTrue('file-id' in tree)
- self.assertFalse('dir-id' in tree)
+ self.assertTrue(
+ self.applyDeprecated(
+ deprecated_in((2, 4, 0)),
+ tree.__contains__, 'file-id'))
+ self.assertFalse(
+ self.applyDeprecated(
+ deprecated_in((2, 4, 0)),
+ tree.__contains__, 'dir-id'))
class TestExtras(TestCaseWithTree):
=== modified file 'bzrlib/tests/test_shelf.py'
--- a/bzrlib/tests/test_shelf.py 2011-06-10 08:58:30 +0000
+++ b/bzrlib/tests/test_shelf.py 2011-06-19 02:24:39 +0000
@@ -330,8 +330,8 @@
return creator, tree
def check_shelve_deletion(self, tree):
- self.assertTrue('foo-id' in tree)
- self.assertTrue('bar-id' in tree)
+ self.assertTrue(tree.has_id('foo-id'))
+ self.assertTrue(tree.has_id('bar-id'))
self.assertFileEqual('baz', 'tree/foo/bar')
def test_shelve_deletion(self):
@@ -573,15 +573,15 @@
creator.transform()
creator.finalize()
# validate the test setup
- self.assertTrue('foo-id' in tree)
- self.assertTrue('bar-id' in tree)
+ self.assertTrue(tree.has_id('foo-id'))
+ self.assertTrue(tree.has_id('bar-id'))
self.assertFileEqual('baz', 'tree/foo/bar')
with open('shelf', 'r+b') as shelf_file:
unshelver = shelf.Unshelver.from_tree_and_shelf(tree, shelf_file)
self.addCleanup(unshelver.finalize)
unshelver.make_merger().do_merge()
- self.assertFalse('foo-id' in tree)
- self.assertFalse('bar-id' in tree)
+ self.assertFalse(tree.has_id('foo-id'))
+ self.assertFalse(tree.has_id('bar-id'))
def test_unshelve_base(self):
tree = self.make_branch_and_tree('tree')
=== modified file 'bzrlib/tests/test_smart_add.py'
--- a/bzrlib/tests/test_smart_add.py 2011-05-20 12:16:57 +0000
+++ b/bzrlib/tests/test_smart_add.py 2011-06-14 02:21:41 +0000
@@ -115,11 +115,11 @@
self.assertNotEqual(None, c_id)
self.base_tree.lock_read()
self.addCleanup(self.base_tree.unlock)
- self.assertFalse(c_id in self.base_tree)
+ self.assertFalse(self.base_tree.has_id(c_id))
d_id = new_tree.path2id('subdir/d')
self.assertNotEqual(None, d_id)
- self.assertFalse(d_id in self.base_tree)
+ self.assertFalse(self.base_tree.has_id(d_id))
def test_copy_existing_dir(self):
self.make_base_tree()
@@ -140,7 +140,7 @@
self.assertNotEqual(None, a_id)
self.base_tree.lock_read()
self.addCleanup(self.base_tree.unlock)
- self.assertFalse(a_id in self.base_tree)
+ self.assertFalse(self.base_tree.has_id(a_id))
class TestAddActions(tests.TestCase):
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2011-06-28 15:58:20 +0000
+++ b/bzrlib/transform.py 2011-06-28 17:25:26 +0000
@@ -2945,7 +2945,7 @@
if basis_tree is None:
basis_tree = working_tree.basis_tree()
basis_tree.lock_read()
- if file_id in basis_tree:
+ if basis_tree.has_id(file_id):
if wt_sha1 != basis_tree.get_file_sha1(file_id):
keep_content = True
elif target_kind is None and not target_versioned:
@@ -2981,8 +2981,8 @@
basis_tree = working_tree.basis_tree()
basis_tree.lock_read()
new_sha1 = target_tree.get_file_sha1(file_id)
- if (file_id in basis_tree and new_sha1 ==
- basis_tree.get_file_sha1(file_id)):
+ if (basis_tree.has_id(file_id) and
+ new_sha1 == basis_tree.get_file_sha1(file_id)):
if file_id in merge_modified:
del merge_modified[file_id]
else:
@@ -3139,7 +3139,7 @@
elif c_type == 'unversioned parent':
file_id = tt.inactive_file_id(conflict[1])
# special-case the other tree root (move its children instead)
- if path_tree and file_id in path_tree:
+ if path_tree and path_tree.has_id(file_id):
if path_tree.path2id('') == file_id:
# This is the root entry, skip it
continue
=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py 2011-06-14 02:23:26 +0000
+++ b/bzrlib/tree.py 2011-06-19 02:24:39 +0000
@@ -127,6 +127,7 @@
def has_id(self, file_id):
raise NotImplementedError(self.has_id)
+ @deprecated_method(deprecated_in((2, 4, 0)))
def __contains__(self, file_id):
return self.has_id(file_id)
=== modified file 'bzrlib/vf_repository.py'
--- a/bzrlib/vf_repository.py 2011-06-28 11:42:02 +0000
+++ b/bzrlib/vf_repository.py 2011-06-28 17:25:26 +0000
@@ -279,7 +279,7 @@
def _get_delta(self, ie, basis_inv, path):
"""Get a delta against the basis inventory for ie."""
- if ie.file_id not in basis_inv:
+ if not basis_inv.has_id(ie.file_id):
# add
result = (None, path, ie.file_id, ie)
self._basis_delta.append(result)
@@ -398,7 +398,7 @@
# this masks when a change may have occurred against the basis.
# To match this we always issue a delta, because the revision
# of the root will always be changing.
- if ie.file_id in basis_inv:
+ if basis_inv.has_id(ie.file_id):
delta = (basis_inv.id2path(ie.file_id), path,
ie.file_id, ie)
else:
@@ -423,7 +423,7 @@
head_set = self._heads(ie.file_id, parent_candiate_entries.keys())
heads = []
for inv in parent_invs:
- if ie.file_id in inv:
+ if inv.has_id(ie.file_id):
old_rev = inv[ie.file_id].revision
if old_rev in head_set:
heads.append(inv[ie.file_id].revision)
@@ -3071,7 +3071,7 @@
# the parents inserted are not those commit would do - in particular
# they are not filtered by heads(). RBC, AB
for revision, tree in parent_trees.iteritems():
- if ie.file_id not in tree:
+ if not tree.has_id(ie.file_id):
continue
parent_id = tree.get_file_revision(ie.file_id)
if parent_id in text_parents:
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-06-28 11:29:03 +0000
+++ b/bzrlib/workingtree.py 2011-06-28 17:25:26 +0000
@@ -2077,8 +2077,6 @@
return True
return self.inventory.has_id(file_id)
- __contains__ = has_id
-
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
def __iter__(self):
"""Iterate through file_ids for this tree.
@@ -2260,7 +2258,7 @@
parent_tree = self.branch.repository.revision_tree(parent_id)
parent_tree.lock_read()
try:
- if file_id not in parent_tree:
+ if not parent_tree.has_id(file_id):
continue
ie = parent_tree.inventory[file_id]
if ie.kind != 'file':
@@ -2314,7 +2312,7 @@
for s in _mod_rio.RioReader(hashfile):
# RioReader reads in Unicode, so convert file_ids back to utf8
file_id = osutils.safe_file_id(s.get("file_id"), warn=False)
- if file_id not in self.inventory:
+ if not self.inventory.has_id(file_id):
continue
text_hash = s.get("hash")
if text_hash == self.get_file_sha1(file_id):
@@ -2855,7 +2853,7 @@
:raises: NoSuchId if any fileid is not currently versioned.
"""
for file_id in file_ids:
- if file_id not in self._inventory:
+ if not self._inventory.has_id(file_id):
raise errors.NoSuchId(self, file_id)
for file_id in file_ids:
if self._inventory.has_id(file_id):
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-06-28 17:19:51 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-06-28 17:25:26 +0000
@@ -208,6 +208,10 @@
.. Changes that may require updates in plugins or other code that uses
bzrlib.
+* Checking for a file id in a `Tree` or `Inventory` using ``in`` is now
+ deprecated. Instead, use `has_id`.
+ (Martin Pool)
+
* Exporters are now all exposed as generators, rather than as single-call
functions, so that calling code can take stream the output.
(Xaav, Martin Pool)
More information about the bazaar-commits
mailing list