Merge lp:~jelmer/brz/inv-not-dict into lp:brz

Proposed by Jelmer Vernooij on 2018-03-24
Status: Merged
Approved by: Jelmer Vernooij on 2018-03-25
Approved revision: 6919
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/inv-not-dict
Merge into: lp:brz
Diff against target: 1417 lines (+210/-210)
26 files modified
breezy/bundle/serializer/v08.py (+1/-1)
breezy/bzr/inventory.py (+38/-38)
breezy/bzr/inventorytree.py (+11/-11)
breezy/bzr/vf_repository.py (+6/-6)
breezy/bzr/workingtree.py (+13/-13)
breezy/bzr/workingtree_4.py (+8/-8)
breezy/merge.py (+4/-4)
breezy/plugins/fastimport/bzr_commit_handler.py (+8/-8)
breezy/plugins/fastimport/revision_store.py (+6/-6)
breezy/plugins/repodebug/file_refs.py (+1/-1)
breezy/tests/per_interrepository/test_fetch.py (+1/-1)
breezy/tests/per_intertree/test_compare.py (+1/-1)
breezy/tests/per_inventory/basics.py (+2/-2)
breezy/tests/per_repository_reference/test_add_inventory.py (+2/-2)
breezy/tests/per_repository_vf/test_add_inventory_by_delta.py (+2/-2)
breezy/tests/per_repository_vf/test_fileid_involved.py (+1/-1)
breezy/tests/per_tree/test_tree.py (+1/-1)
breezy/tests/per_workingtree/test_nested_specifics.py (+1/-1)
breezy/tests/per_workingtree/test_parents.py (+4/-4)
breezy/tests/test_commit.py (+6/-6)
breezy/tests/test_dirstate.py (+1/-1)
breezy/tests/test_inv.py (+72/-72)
breezy/tests/test_revisiontree.py (+1/-1)
breezy/tests/test_transform.py (+1/-1)
breezy/tests/test_xml.py (+17/-17)
breezy/tree.py (+1/-1)
To merge this branch: bzr merge lp:~jelmer/brz/inv-not-dict
Reviewer Review Type Date Requested Status
Martin Packman 2018-03-24 Approve on 2018-03-25
Review via email: mp+342053@code.launchpad.net

Description of the change

Remove the __getitem__, __iter__ and __delitem__ implementations from Inventory.

Instead, add .get_entry(), .all_file_ids() and .delete().

To post a comment you must log in.
Martin Packman (gz) wrote :

Thanks. Couple of inline notes.

review: Approve
The Breezy Bot (the-breezy-bot) wrote :

Running landing tests failed
https://ci.breezy-vcs.org/job/brz-dev/86/

lp:~jelmer/brz/inv-not-dict updated on 2018-03-25
6919. By Jelmer Vernooij on 2018-03-25

Fix test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bundle/serializer/v08.py'
2--- breezy/bundle/serializer/v08.py 2018-02-24 15:50:23 +0000
3+++ breezy/bundle/serializer/v08.py 2018-03-25 02:37:06 +0000
4@@ -281,7 +281,7 @@
5
6 def finish_action(action, file_id, kind, meta_modified, text_modified,
7 old_path, new_path):
8- entry = new_tree.root_inventory[file_id]
9+ entry = new_tree.root_inventory.get_entry(file_id)
10 if entry.revision != default_revision_id:
11 action.add_utf8_property('last-changed', entry.revision)
12 if meta_modified:
13
14=== modified file 'breezy/bzr/inventory.py'
15--- breezy/bzr/inventory.py 2018-03-24 17:48:04 +0000
16+++ breezy/bzr/inventory.py 2018-03-25 02:37:06 +0000
17@@ -112,7 +112,7 @@
18 '2325'
19 >>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
20 InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None, revision=None)
21- >>> i['2326']
22+ >>> i.get_entry('2326')
23 InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None, revision=None)
24 >>> for path, entry in i.iter_entries():
25 ... print path
26@@ -179,7 +179,7 @@
27 # identify candidate head revision ids.
28 for inv in previous_inventories:
29 try:
30- ie = inv[self.file_id]
31+ ie = inv.get_entry(self.file_id)
32 except errors.NoSuchId:
33 pass
34 else:
35@@ -680,7 +680,7 @@
36 from_dir = self.root
37 yield '', self.root
38 elif isinstance(from_dir, (str, text_type)):
39- from_dir = self[from_dir]
40+ from_dir = self.get_entry(from_dir)
41
42 # unrolling the recursive called changed the time from
43 # 440ms/663ms (inline/total) to 116ms/116ms
44@@ -762,14 +762,14 @@
45 except errors.NoSuchId:
46 pass
47 else:
48- yield path, self[file_id]
49+ yield path, self.get_entry(file_id)
50 return
51 from_dir = self.root
52 if (specific_file_ids is None or yield_parents or
53 self.root.file_id in specific_file_ids):
54 yield u'', self.root
55 elif isinstance(from_dir, (str, text_type)):
56- from_dir = self[from_dir]
57+ from_dir = self.get_entry(from_dir)
58
59 if specific_file_ids is not None:
60 # TODO: jam 20070302 This could really be done as a loop rather
61@@ -779,7 +779,7 @@
62 def add_ancestors(file_id):
63 if not byid.has_id(file_id):
64 return
65- parent_id = byid[file_id].parent_id
66+ parent_id = byid.get_entry(file_id).parent_id
67 if parent_id is None:
68 return
69 if parent_id not in parents:
70@@ -811,8 +811,8 @@
71
72 def _make_delta(self, old):
73 """Make an inventory delta from two inventories."""
74- old_ids = set(old)
75- new_ids = set(self)
76+ old_ids = set(old.iter_all_ids())
77+ new_ids = set(self.iter_all_ids())
78 adds = new_ids - old_ids
79 deletes = old_ids - new_ids
80 common = old_ids.intersection(new_ids)
81@@ -820,11 +820,11 @@
82 for file_id in deletes:
83 delta.append((old.id2path(file_id), None, file_id, None))
84 for file_id in adds:
85- delta.append((None, self.id2path(file_id), file_id, self[file_id]))
86+ delta.append((None, self.id2path(file_id), file_id, self.get_entry(file_id)))
87 for file_id in common:
88- if old[file_id] != self[file_id]:
89+ if old.get_entry(file_id) != self.get_entry(file_id):
90 delta.append((old.id2path(file_id), self.id2path(file_id),
91- file_id, self[file_id]))
92+ file_id, self.get_entry(file_id)))
93 return delta
94
95 def make_entry(self, kind, name, parent_id, file_id=None):
96@@ -943,7 +943,7 @@
97 >>> inv = Inventory()
98 >>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
99 InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
100- >>> inv['123-123'].name
101+ >>> inv.get_entry('123-123').name
102 'hello.c'
103
104 Id's may be looked up from paths:
105@@ -1046,7 +1046,7 @@
106 for old_path, file_id in sorted(((op, f) for op, np, f, e in delta
107 if op is not None), reverse=True):
108 # Preserve unaltered children of file_id for later reinsertion.
109- file_id_children = getattr(self[file_id], 'children', {})
110+ file_id_children = getattr(self.get_entry(file_id), 'children', {})
111 if len(file_id_children):
112 children[file_id] = file_id_children
113 if self.id2path(file_id) != old_path:
114@@ -1113,7 +1113,7 @@
115 other.add(entry.copy())
116 return other
117
118- def __iter__(self):
119+ def iter_all_ids(self):
120 """Iterate over all file-ids."""
121 return iter(self._byid)
122
123@@ -1133,13 +1133,13 @@
124 """Returns number of entries."""
125 return len(self._byid)
126
127- def __getitem__(self, file_id):
128+ def get_entry(self, file_id):
129 """Return the entry for given file_id.
130
131 >>> inv = Inventory()
132 >>> inv.add(InventoryFile('123123', 'hello.c', ROOT_ID))
133 InventoryFile('123123', 'hello.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
134- >>> inv['123123'].name
135+ >>> inv.get_entry('123123').name
136 'hello.c'
137 """
138 try:
139@@ -1152,7 +1152,7 @@
140 return self._byid[file_id].kind
141
142 def get_child(self, parent_id, filename):
143- return self[parent_id].children.get(filename)
144+ return self.get_entry(parent_id).children.get(filename)
145
146 def _add_child(self, entry):
147 """Add an entry to the inventory, without adding it to its parent"""
148@@ -1214,7 +1214,7 @@
149 ie = make_entry(kind, parts[-1], parent_id, file_id)
150 return self.add(ie)
151
152- def __delitem__(self, file_id):
153+ def delete(self, file_id):
154 """Remove entry by id.
155
156 >>> inv = Inventory()
157@@ -1222,14 +1222,14 @@
158 InventoryFile('123', 'foo.c', parent_id='TREE_ROOT', sha1=None, len=None, revision=None)
159 >>> inv.has_id('123')
160 True
161- >>> del inv['123']
162+ >>> inv.delete('123')
163 >>> inv.has_id('123')
164 False
165 """
166- ie = self[file_id]
167+ ie = self.get_entry(file_id)
168 del self._byid[file_id]
169 if ie.parent_id is not None:
170- del self[ie.parent_id].children[ie.name]
171+ del self.get_entry(ie.parent_id).children[ie.name]
172
173 def __eq__(self, other):
174 """Compare two sets by comparing their contents.
175@@ -1273,10 +1273,10 @@
176
177 def _make_delta(self, old):
178 """Make an inventory delta from two inventories."""
179- old_getter = getattr(old, '_byid', old)
180- new_getter = self._byid
181- old_ids = set(old_getter)
182- new_ids = set(new_getter)
183+ old_getter = old.get_entry
184+ new_getter = self.get_entry
185+ old_ids = set(old.iter_all_ids())
186+ new_ids = set(self.iter_all_ids())
187 adds = new_ids - old_ids
188 deletes = old_ids - new_ids
189 if not adds and not deletes:
190@@ -1287,10 +1287,10 @@
191 for file_id in deletes:
192 delta.append((old.id2path(file_id), None, file_id, None))
193 for file_id in adds:
194- delta.append((None, self.id2path(file_id), file_id, self[file_id]))
195+ delta.append((None, self.id2path(file_id), file_id, self.get_entry(file_id)))
196 for file_id in common:
197- new_ie = new_getter[file_id]
198- old_ie = old_getter[file_id]
199+ new_ie = new_getter(file_id)
200+ old_ie = old_getter(file_id)
201 # If xml_serializer returns the cached InventoryEntries (rather
202 # than always doing .copy()), inlining the 'is' check saves 2.7M
203 # calls to __eq__. Under lsprof this saves 20s => 6s.
204@@ -1315,10 +1315,10 @@
205 if ie.kind == 'directory':
206 to_find_delete.extend(viewvalues(ie.children))
207 for file_id in reversed(to_delete):
208- ie = self[file_id]
209+ ie = self.get_entry(file_id)
210 del self._byid[file_id]
211 if ie.parent_id is not None:
212- del self[ie.parent_id].children[ie.name]
213+ del self.get_entry(ie.parent_id).children[ie.name]
214 else:
215 self.root = None
216
217@@ -1707,7 +1707,7 @@
218 if old_path is None:
219 old_key = None
220 else:
221- old_entry = self[file_id]
222+ old_entry = self.get_entry(file_id)
223 old_key = self._parent_id_basename_key(old_entry)
224 if new_path is None:
225 new_key = None
226@@ -1728,7 +1728,7 @@
227 new_key, [None, None])[1] = new_value
228 # validate that deletes are complete.
229 for file_id in deletes:
230- entry = self[file_id]
231+ entry = self.get_entry(file_id)
232 if entry.kind != 'directory':
233 continue
234 # This loop could potentially be better by using the id_basename
235@@ -1754,7 +1754,7 @@
236 parents.discard(('', None))
237 for parent_path, parent in parents:
238 try:
239- if result[parent].kind != 'directory':
240+ if result.get_entry(parent).kind != 'directory':
241 raise errors.InconsistentDelta(result.id2path(parent), parent,
242 'Not a directory, but given children')
243 except errors.NoSuchId:
244@@ -1880,7 +1880,7 @@
245 parent_id = b''
246 return StaticTuple(parent_id, entry.name.encode('utf8')).intern()
247
248- def __getitem__(self, file_id):
249+ def get_entry(self, file_id):
250 """map a single file_id -> InventoryEntry."""
251 if file_id is None:
252 raise errors.NoSuchId(self, file_id)
253@@ -1895,7 +1895,7 @@
254 raise errors.NoSuchId(self, file_id)
255
256 def _getitems(self, file_ids):
257- """Similar to __getitem__, but lets you query for multiple.
258+ """Similar to get_entry, but lets you query for multiple.
259
260 The returned order is undefined. And currently if an item doesn't
261 exist, it isn't included in the output.
262@@ -1929,13 +1929,13 @@
263 """Yield the parents of file_id up to the root."""
264 while file_id is not None:
265 try:
266- ie = self[file_id]
267+ ie = self.get_entry(file_id)
268 except KeyError:
269 raise errors.NoSuchId(tree=self, file_id=file_id)
270 yield ie
271 file_id = ie.parent_id
272
273- def __iter__(self):
274+ def iter_all_ids(self):
275 """Iterate over all file-ids."""
276 for key, _ in self.id_to_entry.iteritems():
277 yield key[-1]
278@@ -2172,7 +2172,7 @@
279 @property
280 def root(self):
281 """Get the root entry."""
282- return self[self.root_id]
283+ return self.get_entry(self.root_id)
284
285
286 class CHKInventoryDirectory(InventoryDirectory):
287
288=== modified file 'breezy/bzr/inventorytree.py'
289--- breezy/bzr/inventorytree.py 2018-03-24 23:49:53 +0000
290+++ breezy/bzr/inventorytree.py 2018-03-25 02:37:06 +0000
291@@ -300,7 +300,7 @@
292 with self.lock_read():
293 inv, inv_file_id = self._path2inv_file_id(path, file_id)
294 try:
295- ie = inv[inv_file_id]
296+ ie = inv.get_entry(inv_file_id)
297 except errors.NoSuchId:
298 raise errors.NoSuchFile(path)
299 else:
300@@ -807,7 +807,7 @@
301 def get_file_mtime(self, path, file_id=None):
302 inv, inv_file_id = self._path2inv_file_id(path, file_id)
303 try:
304- ie = inv[inv_file_id]
305+ ie = inv.get_entry(inv_file_id)
306 except errors.NoSuchId:
307 raise errors.NoSuchFile(path)
308 try:
309@@ -818,11 +818,11 @@
310
311 def get_file_size(self, path, file_id=None):
312 inv, inv_file_id = self._path2inv_file_id(path, file_id)
313- return inv[inv_file_id].text_size
314+ return inv.get_entry(inv_file_id).text_size
315
316 def get_file_sha1(self, path, file_id=None, stat_value=None):
317 inv, inv_file_id = self._path2inv_file_id(path, file_id)
318- ie = inv[inv_file_id]
319+ ie = inv.get_entry(inv_file_id)
320 if ie.kind == "file":
321 return ie.text_sha1
322 return None
323@@ -830,14 +830,14 @@
324 def get_file_revision(self, path, file_id=None):
325 inv, inv_file_id = self._path2inv_file_id(path, file_id)
326 try:
327- ie = inv[inv_file_id]
328+ ie = inv.get_entry(inv_file_id)
329 except errors.NoSuchId:
330 raise errors.NoSuchFile(path)
331 return ie.revision
332
333 def is_executable(self, path, file_id=None):
334 inv, inv_file_id = self._path2inv_file_id(path, file_id)
335- ie = inv[inv_file_id]
336+ ie = inv.get_entry(inv_file_id)
337 if ie.kind != "file":
338 return False
339 return ie.executable
340@@ -864,13 +864,13 @@
341
342 def get_symlink_target(self, path, file_id=None):
343 inv, inv_file_id = self._path2inv_file_id(path, file_id)
344- ie = inv[inv_file_id]
345+ ie = inv.get_entry(inv_file_id)
346 # Inventories store symlink targets in unicode
347 return ie.symlink_target
348
349 def get_reference_revision(self, path, file_id=None):
350 inv, inv_file_id = self._path2inv_file_id(path, file_id)
351- return inv[inv_file_id].reference_revision
352+ return inv.get_entry(inv_file_id).reference_revision
353
354 def get_root_id(self):
355 if self.root_inventory.root:
356@@ -879,7 +879,7 @@
357 def kind(self, path, file_id=None):
358 inv, inv_file_id = self._path2inv_file_id(path, file_id)
359 try:
360- return inv[inv_file_id].kind
361+ return inv.get_entry(inv_file_id).kind
362 except errors.NoSuchId:
363 raise errors.NoSuchFile(path)
364
365@@ -888,7 +888,7 @@
366 inv, file_id = self._path2inv_file_id(path)
367 if file_id is None:
368 return ('missing', None, None, None)
369- entry = inv[file_id]
370+ entry = inv.get_entry(file_id)
371 kind = entry.kind
372 if kind == 'file':
373 return (kind, entry.text_size, entry.executable, entry.text_sha1)
374@@ -918,7 +918,7 @@
375 else:
376 relroot = ""
377 # FIXME: stash the node in pending
378- entry = inv[currentdir[4]]
379+ entry = inv.get_entry(currentdir[4])
380 for name, child in entry.sorted_children():
381 toppath = relroot + name
382 dirblock.append((toppath, name, child.kind, None,
383
384=== modified file 'breezy/bzr/vf_repository.py'
385--- breezy/bzr/vf_repository.py 2018-03-24 23:49:53 +0000
386+++ breezy/bzr/vf_repository.py 2018-03-25 02:37:06 +0000
387@@ -258,7 +258,7 @@
388 result = (None, path, ie.file_id, ie)
389 self._basis_delta.append(result)
390 return result
391- elif ie != basis_inv[ie.file_id]:
392+ elif ie != basis_inv.get_entry(ie.file_id):
393 # common but altered
394 # TODO: avoid tis id2path call.
395 result = (basis_inv.id2path(ie.file_id), path, ie.file_id, ie)
396@@ -345,7 +345,7 @@
397 continue
398 if change[2] not in merged_ids:
399 if change[0] is not None:
400- basis_entry = basis_inv[change[2]]
401+ basis_entry = basis_inv.get_entry(change[2])
402 merged_ids[change[2]] = [
403 # basis revid
404 basis_entry.revision,
405@@ -371,7 +371,7 @@
406 for change in iter_changes:
407 # This probably looks up in basis_inv way to much.
408 if change[1][0] is not None:
409- head_candidate = [basis_inv[change[0]].revision]
410+ head_candidate = [basis_inv.get_entry(change[0]).revision]
411 else:
412 head_candidate = []
413 changes[change[0]] = change, merged_ids.get(change[0],
414@@ -391,7 +391,7 @@
415 # changed_content, versioned, parent, name, kind,
416 # executable)
417 try:
418- basis_entry = basis_inv[file_id]
419+ basis_entry = basis_inv.get_entry(file_id)
420 except errors.NoSuchId:
421 # a change from basis->some_parents but file_id isn't in basis
422 # so was new in the merge, which means it must have changed
423@@ -1330,7 +1330,7 @@
424 inv = self.revision_tree(parent_id).root_inventory
425 inventory_cache[parent_id] = inv
426 try:
427- parent_entry = inv[text_key[0]]
428+ parent_entry = inv.get_entry(text_key[0])
429 except (KeyError, errors.NoSuchId):
430 parent_entry = None
431 if parent_entry is not None:
432@@ -2610,7 +2610,7 @@
433 for file_key in list(texts_possibly_new_in_tree):
434 file_id, file_revision = file_key
435 try:
436- entry = basis_inv[file_id]
437+ entry = basis_inv.get_entry(file_id)
438 except errors.NoSuchId:
439 continue
440 if entry.revision == file_revision:
441
442=== modified file 'breezy/bzr/workingtree.py'
443--- breezy/bzr/workingtree.py 2018-03-24 17:48:04 +0000
444+++ breezy/bzr/workingtree.py 2018-03-25 02:37:06 +0000
445@@ -331,15 +331,15 @@
446 self._inventory_is_modified = True
447 # we preserve the root inventory entry object, but
448 # unlinkit from the byid index
449- del inv._byid[inv.root.file_id]
450+ inv.delete(inv.root.file_id)
451 inv.root.file_id = file_id
452 # and link it into the index with the new changed id.
453 inv._byid[inv.root.file_id] = inv.root
454 # and finally update all children to reference the new id.
455 # XXX: this should be safe to just look at the root.children
456 # list, not the WHOLE INVENTORY.
457- for fid in inv:
458- entry = inv[fid]
459+ for fid in inv.iter_all_ids():
460+ entry = inv.get_entry(fid)
461 if entry.parent_id == orig_root_id:
462 entry.parent_id = inv.root.file_id
463
464@@ -744,7 +744,7 @@
465 # For unversioned files on win32, we just assume they are not
466 # executable
467 return False
468- return inv[file_id].executable
469+ return inv.get_entry(file_id).executable
470
471 def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):
472 mode = stat_result.st_mode
473@@ -753,7 +753,7 @@
474 def is_executable(self, path, file_id=None):
475 if not self._supports_executable():
476 inv, inv_file_id = self._path2inv_file_id(path, file_id)
477- return inv[inv_file_id].executable
478+ return inv.get_entry(inv_file_id).executable
479 else:
480 mode = os.lstat(self.abspath(path)).st_mode
481 return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
482@@ -985,7 +985,7 @@
483 child_inv = inventory.Inventory(root_id=None)
484 if file_id is None:
485 file_id = self.path2id(sub_path)
486- new_root = my_inv[file_id]
487+ new_root = my_inv.get_entry(file_id)
488 my_inv.remove_recursive_id(file_id)
489 new_root.parent_id = None
490 child_inv.add(new_root)
491@@ -1061,7 +1061,7 @@
492 # absolute path
493 fap = from_dir_abspath + '/' + f
494
495- dir_ie = inv[from_dir_id]
496+ dir_ie = inv.get_entry(from_dir_id)
497 if dir_ie.kind == 'directory':
498 f_ie = dir_ie.children.get(f)
499 else:
500@@ -1178,7 +1178,7 @@
501 raise errors.BzrMoveFailedError(
502 '', to_dir, errors.NotVersionedError(path=to_dir))
503
504- to_dir_ie = to_inv[to_dir_id]
505+ to_dir_ie = to_inv.get_entry(to_dir_id)
506 if to_dir_ie.kind != 'directory':
507 raise errors.BzrMoveFailedError(
508 '', to_dir, errors.NotADirectory(to_abs))
509@@ -1191,7 +1191,7 @@
510 raise errors.BzrMoveFailedError(from_rel, to_dir,
511 errors.NotVersionedError(path=from_rel))
512
513- from_entry = from_inv[from_id]
514+ from_entry = from_inv.get_entry(from_id)
515 from_parent_id = from_entry.parent_id
516 to_rel = osutils.pathjoin(to_dir, from_tail)
517 rename_entry = InventoryWorkingTree._RenameEntry(
518@@ -1258,11 +1258,11 @@
519 from_rel, to_rel,
520 errors.NotVersionedError(path=from_rel))
521 # put entry back in the inventory so we can rename it
522- from_entry = basis_tree.root_inventory[from_id].copy()
523+ from_entry = basis_tree.root_inventory.get_entry(from_id).copy()
524 from_inv.add(from_entry)
525 else:
526 from_inv, from_inv_id = self._unpack_file_id(from_id)
527- from_entry = from_inv[from_inv_id]
528+ from_entry = from_inv.get_entry(from_inv_id)
529 from_parent_id = from_entry.parent_id
530 to_dir, to_tail = os.path.split(to_rel)
531 to_inv, to_dir_id = self._path2inv_file_id(to_dir)
532@@ -1464,7 +1464,7 @@
533 inv, inv_file_id = self._path2inv_file_id(path, file_id)
534 if inv_file_id is None:
535 raise errors.NoSuchFile(self, path)
536- return inv[inv_file_id].kind
537+ return inv.get_entry(inv_file_id).kind
538
539 def extras(self):
540 """Yield all unversioned files in this WorkingTree.
541@@ -1658,7 +1658,7 @@
542 else:
543 relroot = ""
544 # FIXME: stash the node in pending
545- entry = inv[top_id]
546+ entry = inv.get_entry(top_id)
547 if entry.kind == 'directory':
548 for name, child in entry.sorted_children():
549 dirblock.append((relroot + name, name, child.kind, None,
550
551=== modified file 'breezy/bzr/workingtree_4.py'
552--- breezy/bzr/workingtree_4.py 2018-03-24 17:48:04 +0000
553+++ breezy/bzr/workingtree_4.py 2018-03-25 02:37:06 +0000
554@@ -693,7 +693,7 @@
555 update_inventory = True
556 inv = self.root_inventory
557 to_dir_id = to_entry[0][2]
558- to_dir_ie = inv[to_dir_id]
559+ to_dir_ie = inv.get_entry(to_dir_id)
560 else:
561 update_inventory = False
562
563@@ -782,7 +782,7 @@
564 # to rollback
565 if update_inventory:
566 # rename the entry
567- from_entry = inv[from_id]
568+ from_entry = inv.get_entry(from_id)
569 current_parent = from_entry.parent_id
570 inv.rename(from_id, to_dir_id, from_tail)
571 rollbacks.add_cleanup(
572@@ -1885,7 +1885,7 @@
573 def get_file_revision(self, path, file_id=None):
574 with self.lock_read():
575 inv, inv_file_id = self._path2inv_file_id(path, file_id)
576- return inv[inv_file_id].revision
577+ return inv.get_entry(inv_file_id).revision
578
579 def get_file(self, path, file_id=None):
580 return BytesIO(self.get_file_text(path, file_id))
581@@ -1893,7 +1893,7 @@
582 def get_file_size(self, path, file_id=None):
583 """See Tree.get_file_size"""
584 inv, inv_file_id = self._path2inv_file_id(path, file_id)
585- return inv[inv_file_id].text_size
586+ return inv.get_entry(inv_file_id).text_size
587
588 def get_file_text(self, path, file_id=None):
589 content = None
590@@ -1911,7 +1911,7 @@
591
592 def get_reference_revision(self, path, file_id=None):
593 inv, inv_file_id = self._path2inv_file_id(path, file_id)
594- return inv[inv_file_id].reference_revision
595+ return inv.get_entry(inv_file_id).reference_revision
596
597 def iter_files_bytes(self, desired_files):
598 """See Tree.iter_files_bytes.
599@@ -1976,7 +1976,7 @@
600 inv, inv_file_id = self._path2inv_file_id(path)
601 if inv_file_id is None:
602 return ('missing', None, None, None)
603- entry = inv[inv_file_id]
604+ entry = inv.get_entry(inv_file_id)
605 kind = entry.kind
606 if kind == 'file':
607 return (kind, entry.text_size, entry.executable, entry.text_sha1)
608@@ -1987,7 +1987,7 @@
609
610 def is_executable(self, path, file_id=None):
611 inv, inv_file_id = self._path2inv_file_id(path, file_id)
612- ie = inv[inv_file_id]
613+ ie = inv.get_entry(inv_file_id)
614 if ie.kind != "file":
615 return False
616 return ie.executable
617@@ -2081,7 +2081,7 @@
618 else:
619 relroot = ""
620 # FIXME: stash the node in pending
621- entry = inv[file_id]
622+ entry = inv.get_entry(file_id)
623 for name, child in entry.sorted_children():
624 toppath = relroot + name
625 dirblock.append((toppath, name, child.kind, None,
626
627=== modified file 'breezy/merge.py'
628--- breezy/merge.py 2018-03-24 18:22:08 +0000
629+++ breezy/merge.py 2018-03-25 02:37:06 +0000
630@@ -956,7 +956,7 @@
631 lca_paths.append(path)
632
633 try:
634- base_ie = base_inventory[file_id]
635+ base_ie = base_inventory.get_entry(file_id)
636 except errors.NoSuchId:
637 base_ie = _none_entry
638 base_path = None
639@@ -964,7 +964,7 @@
640 base_path = self.base_tree.id2path(file_id)
641
642 try:
643- this_ie = this_inventory[file_id]
644+ this_ie = this_inventory.get_entry(file_id)
645 except errors.NoSuchId:
646 this_ie = _none_entry
647 this_path = None
648@@ -1193,7 +1193,7 @@
649 def merge_names(self, file_id):
650 def get_entry(tree):
651 try:
652- return tree.root_inventory[file_id]
653+ return tree.root_inventory.get_entry(file_id)
654 except errors.NoSuchId:
655 return None
656 this_entry = get_entry(self.this_tree)
657@@ -1894,7 +1894,7 @@
658 # XXX: The error would be clearer if it gave the URL of the source
659 # branch, but we don't have a reference to that here.
660 raise PathNotInTree(self._source_subpath, "Source tree")
661- subdir = other_inv[subdir_id]
662+ subdir = other_inv.get_entry(subdir_id)
663 parent_in_target = osutils.dirname(self._target_subdir)
664 target_id = self.this_tree.path2id(parent_in_target)
665 if target_id is None:
666
667=== modified file 'breezy/plugins/fastimport/bzr_commit_handler.py'
668--- breezy/plugins/fastimport/bzr_commit_handler.py 2018-03-24 23:49:53 +0000
669+++ breezy/plugins/fastimport/bzr_commit_handler.py 2018-03-25 02:37:06 +0000
670@@ -375,7 +375,7 @@
671 return
672 # Record it
673 try:
674- old_ie = inv[file_id]
675+ old_ie = inv.get_entry(file_id)
676 except errors.NoSuchId:
677 try:
678 self.record_new(path, ie)
679@@ -438,7 +438,7 @@
680 raise KeyError
681 if file_id is None:
682 raise KeyError
683- result = inv[file_id]
684+ result = inv.get_entry(file_id)
685 # dirname must be a directory for us to return it
686 if result.kind == 'directory':
687 self.directory_entries[dirname] = result
688@@ -459,7 +459,7 @@
689 self.mutter("ignoring delete of %s as not in inventory", path)
690 return
691 try:
692- ie = inv[file_id]
693+ ie = inv.get_entry(file_id)
694 except errors.NoSuchId:
695 self.mutter("ignoring delete of %s as not in inventory", path)
696 return
697@@ -479,7 +479,7 @@
698 self.warning("ignoring copy of %s to %s - source does not exist",
699 src_path, dest_path)
700 return
701- ie = inv[file_id]
702+ ie = inv.get_entry(file_id)
703 kind = ie.kind
704 if kind == 'file':
705 if newly_changed:
706@@ -509,11 +509,11 @@
707 "ignoring rename of %s to %s - old path does not exist" %
708 (old_path, new_path))
709 return
710- ie = inv[file_id]
711+ ie = inv.get_entry(file_id)
712 rev_id = ie.revision
713 new_file_id = inv.path2id(new_path)
714 if new_file_id is not None:
715- self.record_delete(new_path, inv[new_file_id])
716+ self.record_delete(new_path, inv.get_entry(new_file_id))
717 self.record_rename(old_path, new_path, file_id, ie)
718
719 # The revision-id for this entry will be/has been updated and
720@@ -713,7 +713,7 @@
721 file_id = new_inv.path2id(dir)
722 if file_id is None:
723 continue
724- ie = new_inv[file_id]
725+ ie = new_inv.get_entry(file_id)
726 if ie.kind != 'directory':
727 continue
728 if len(ie.children) == 0:
729@@ -734,7 +734,7 @@
730 else:
731 new_inv = inventory.Inventory(revision_id=self.revision_id)
732 # This is set in the delta so remove it to prevent a duplicate
733- del new_inv[inventory.ROOT_ID]
734+ new_inv.delete(inventory.ROOT_ID)
735 try:
736 new_inv.apply_delta(delta)
737 except errors.InconsistentDelta:
738
739=== modified file 'breezy/plugins/fastimport/revision_store.py'
740--- breezy/plugins/fastimport/revision_store.py 2018-03-10 13:56:26 +0000
741+++ breezy/plugins/fastimport/revision_store.py 2018-03-25 02:37:06 +0000
742@@ -79,7 +79,7 @@
743 except KeyError:
744 # The content wasn't shown as 'new'. Just validate this fact
745 assert file_id not in self._new_info_by_id
746- old_ie = self._basis_inv[file_id]
747+ old_ie = self._basis_inv.get_entry(file_id)
748 old_text_key = (file_id, old_ie.revision)
749 stream = self._repo.texts.get_record_stream([old_text_key],
750 'unordered', True)
751@@ -91,7 +91,7 @@
752 if file_id in self._new_info_by_id:
753 ie = self._new_info_by_id[file_id][1]
754 return ie.symlink_target
755- return self._basis_inv[file_id].symlink_target
756+ return self._basis_inv.get_entry(file_id).symlink_target
757
758 def get_reference_revision(self, path, file_id=None):
759 raise NotImplementedError(_TreeShim.get_reference_revision)
760@@ -114,7 +114,7 @@
761 # Since the *very* common case is that the file already exists, it
762 # probably is better to optimize for that
763 try:
764- old_ie = basis_inv[file_id]
765+ old_ie = basis_inv.get_entry(file_id)
766 except errors.NoSuchId:
767 old_ie = None
768 if ie is None:
769@@ -281,12 +281,12 @@
770 heads = []
771 for inv in self._rev_parent_invs:
772 try:
773- old_rev = inv[ie.file_id].revision
774+ old_rev = inv.get_entry(ie.file_id).revision
775 except errors.NoSuchId:
776 pass
777 else:
778 if old_rev in head_set:
779- rev_id = inv[ie.file_id].revision
780+ rev_id = inv.get_entry(ie.file_id).revision
781 heads.append(rev_id)
782 head_set.remove(rev_id)
783
784@@ -511,7 +511,7 @@
785 else:
786 new_inv = inventory.Inventory(revision_id=revision_id)
787 # This is set in the delta so remove it to prevent a duplicate
788- del new_inv[inventory.ROOT_ID]
789+ new_inv.delete(inventory.ROOT_ID)
790 new_inv.apply_delta(inv_delta)
791 validator = self.repo.add_inventory(revision_id, new_inv, parents)
792 return validator, new_inv
793
794=== modified file 'breezy/plugins/repodebug/file_refs.py'
795--- breezy/plugins/repodebug/file_refs.py 2017-09-07 08:21:29 +0000
796+++ breezy/plugins/repodebug/file_refs.py 2018-03-25 02:37:06 +0000
797@@ -42,7 +42,7 @@
798 # print len(all_invs)
799 for inv in repo.iter_inventories(all_invs, 'unordered'):
800 try:
801- entry = inv[file_id]
802+ entry = inv.get_entry(file_id)
803 except errors.NoSuchId:
804 # This file doesn't even appear in this inv.
805 continue
806
807=== modified file 'breezy/tests/per_interrepository/test_fetch.py'
808--- breezy/tests/per_interrepository/test_fetch.py 2017-11-24 09:25:13 +0000
809+++ breezy/tests/per_interrepository/test_fetch.py 2018-03-25 02:37:06 +0000
810@@ -498,7 +498,7 @@
811 source.lock_write()
812 self.addCleanup(source.unlock)
813 source.start_write_group()
814- inv['id'].revision = 'b'
815+ inv.get_entry('id').revision = 'b'
816 inv.revision_id = 'b'
817 sha1 = source.add_inventory('b', inv, ['a'])
818 rev = Revision(timestamp=0,
819
820=== modified file 'breezy/tests/per_intertree/test_compare.py'
821--- breezy/tests/per_intertree/test_compare.py 2018-03-24 23:49:53 +0000
822+++ breezy/tests/per_intertree/test_compare.py 2018-03-25 02:37:06 +0000
823@@ -590,7 +590,7 @@
824 (from_basename, to_basename), (kind, None), (False, False))
825
826 def deleted(self, tree, file_id):
827- entry = tree.root_inventory[file_id]
828+ entry = tree.root_inventory.get_entry(file_id)
829 path = tree.id2path(file_id)
830 return (file_id, (path, None), True, (True, False), (entry.parent_id, None),
831 (entry.name, None), (entry.kind, None),
832
833=== modified file 'breezy/tests/per_inventory/basics.py'
834--- breezy/tests/per_inventory/basics.py 2018-02-17 00:06:35 +0000
835+++ breezy/tests/per_inventory/basics.py 2018-03-25 02:37:06 +0000
836@@ -107,7 +107,7 @@
837 (None, "a", "a-id", self.make_file('a-id', 'a', 'tree-root')),
838 ], 'new-rev-1')
839 self.assertEqual('a', inv.id2path('a-id'))
840- a_ie = inv['a-id']
841+ a_ie = inv.get_entry('a-id')
842 b_ie = self.make_file(a_ie.file_id, "b", a_ie.parent_id)
843 inv = inv.create_by_apply_delta([("a", "b", "a-id", b_ie)], 'new-rev-2')
844 self.assertEqual("b", inv.id2path('a-id'))
845@@ -128,7 +128,7 @@
846 inv = self.make_init_inventory()
847 self.assertTrue(inv.is_root('tree-root'))
848 self.assertFalse(inv.is_root('booga'))
849- ie = inv['tree-root'].copy()
850+ ie = inv.get_entry('tree-root').copy()
851 ie.file_id = 'booga'
852 inv = inv.create_by_apply_delta([("", None, "tree-root", None),
853 (None, "", "booga", ie)], 'new-rev-2')
854
855=== modified file 'breezy/tests/per_repository_reference/test_add_inventory.py'
856--- breezy/tests/per_repository_reference/test_add_inventory.py 2017-05-21 18:10:28 +0000
857+++ breezy/tests/per_repository_reference/test_add_inventory.py 2018-03-25 02:37:06 +0000
858@@ -49,7 +49,7 @@
859 repo.lock_read()
860 self.addCleanup(repo.unlock)
861 inv2 = repo.get_inventory(revid)
862- content1 = dict((file_id, inv[file_id]) for file_id in inv)
863- content2 = dict((file_id, inv[file_id]) for file_id in inv2)
864+ content1 = dict((file_id, inv.get_entry(file_id)) for file_id in inv.iter_all_ids())
865+ content2 = dict((file_id, inv.get_entry(file_id)) for file_id in inv2.iter_all_ids())
866 self.assertEqual(content1, content2)
867 self.assertRaises(errors.NoSuchRevision, base.get_inventory, revid)
868
869=== modified file 'breezy/tests/per_repository_vf/test_add_inventory_by_delta.py'
870--- breezy/tests/per_repository_vf/test_add_inventory_by_delta.py 2017-05-21 18:10:28 +0000
871+++ breezy/tests/per_repository_vf/test_add_inventory_by_delta.py 2018-03-25 02:37:06 +0000
872@@ -73,9 +73,9 @@
873 for file_id in deletes:
874 delta.append((old.id2path(file_id), None, file_id, None))
875 for file_id in adds:
876- delta.append((None, new.id2path(file_id), file_id, new[file_id]))
877+ delta.append((None, new.id2path(file_id), file_id, new.get_entry(file_id)))
878 for file_id in common:
879- if old[file_id] != new[file_id]:
880+ if old.get_entry(file_id) != new.get_entry(file_id):
881 delta.append((old.id2path(file_id), new.id2path(file_id),
882 file_id, new[file_id]))
883 return delta
884
885=== modified file 'breezy/tests/per_repository_vf/test_fileid_involved.py'
886--- breezy/tests/per_repository_vf/test_fileid_involved.py 2018-03-20 00:30:39 +0000
887+++ breezy/tests/per_repository_vf/test_fileid_involved.py 2018-03-25 02:37:06 +0000
888@@ -51,7 +51,7 @@
889 old_rt = b.repository.revision_tree('A-id')
890 new_inv = inventory.mutable_inventory_from_tree(old_rt)
891 new_inv.revision_id = 'B-id'
892- new_inv['a-file-id'].revision = 'ghost-id'
893+ new_inv.get_entry('a-file-id').revision = 'ghost-id'
894 new_rev = _mod_revision.Revision('B-id',
895 timestamp=time.time(),
896 timezone=0,
897
898=== modified file 'breezy/tests/per_tree/test_tree.py'
899--- breezy/tests/per_tree/test_tree.py 2018-03-24 23:49:53 +0000
900+++ breezy/tests/per_tree/test_tree.py 2018-03-25 02:37:06 +0000
901@@ -107,7 +107,7 @@
902 tree = self.create_nested()
903 tree.lock_read()
904 self.addCleanup(tree.unlock)
905- entry = tree.root_inventory['sub-root']
906+ entry = tree.root_inventory.get_entry('sub-root')
907 self.assertEqual([(u'subtree', 'sub-root')],
908 list(tree.iter_references()))
909
910
911=== modified file 'breezy/tests/per_workingtree/test_nested_specifics.py'
912--- breezy/tests/per_workingtree/test_nested_specifics.py 2018-03-22 02:21:11 +0000
913+++ breezy/tests/per_workingtree/test_nested_specifics.py 2018-03-25 02:37:06 +0000
914@@ -44,7 +44,7 @@
915 tree.lock_read()
916 self.addCleanup(tree.unlock)
917 self.assertEqual('subtree-revision',
918- tree.root_inventory['subtree-id'].reference_revision)
919+ tree.root_inventory.get_entry('subtree-id').reference_revision)
920
921 def test_extract_while_locked(self):
922 tree = self.make_branch_and_tree('.')
923
924=== modified file 'breezy/tests/per_workingtree/test_parents.py'
925--- breezy/tests/per_workingtree/test_parents.py 2018-03-24 13:45:31 +0000
926+++ breezy/tests/per_workingtree/test_parents.py 2018-03-25 02:37:06 +0000
927@@ -419,11 +419,11 @@
928 for file_id in deletes:
929 delta.append((old.id2path(file_id), None, file_id, None))
930 for file_id in adds:
931- delta.append((None, new.id2path(file_id), file_id, new[file_id]))
932+ delta.append((None, new.id2path(file_id), file_id, new.get_entry(file_id)))
933 for file_id in common:
934- if old[file_id] != new[file_id]:
935+ if old.get_entry(file_id) != new.get_entry(file_id):
936 delta.append((old.id2path(file_id), new.id2path(file_id),
937- file_id, new[file_id]))
938+ file_id, new.get_entry(file_id)))
939 return delta
940
941 def fake_up_revision(self, tree, revid, shape):
942@@ -440,7 +440,7 @@
943 def get_file_text(self, path, file_id=None):
944 if file_id is None:
945 file_id = self.path2id(path)
946- ie = self.root_inventory[file_id]
947+ ie = self.root_inventory.get_entry(file_id)
948 if ie.kind != "file":
949 return ""
950 return 'a' * ie.text_size
951
952=== modified file 'breezy/tests/test_commit.py'
953--- breezy/tests/test_commit.py 2018-03-12 00:47:15 +0000
954+++ breezy/tests/test_commit.py 2018-03-25 02:37:06 +0000
955@@ -331,9 +331,9 @@
956 wt.unlock()
957
958 inv = b.repository.get_inventory(r4)
959- eq(inv['hello-id'].revision, r4)
960- eq(inv['a-id'].revision, r1)
961- eq(inv['b-id'].revision, r3)
962+ eq(inv.get_entry('hello-id').revision, r4)
963+ eq(inv.get_entry('a-id').revision, r1)
964+ eq(inv.get_entry('b-id').revision, r3)
965
966 def test_removed_commit(self):
967 """Commit with a removed file"""
968@@ -373,10 +373,10 @@
969 ['dirid', 'file1id', 'file2id'])
970 wt.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
971 inv = b.repository.get_inventory('1')
972- self.assertEqual('1', inv['dirid'].revision)
973- self.assertEqual('1', inv['file1id'].revision)
974+ self.assertEqual('1', inv.get_entry('dirid').revision)
975+ self.assertEqual('1', inv.get_entry('file1id').revision)
976 # FIXME: This should raise a KeyError I think, rbc20051006
977- self.assertRaises(BzrError, inv.__getitem__, 'file2id')
978+ self.assertRaises(BzrError, inv.get_entry, 'file2id')
979
980 def test_strict_commit(self):
981 """Try and commit with unknown files and strict = True, should fail."""
982
983=== modified file 'breezy/tests/test_dirstate.py'
984--- breezy/tests/test_dirstate.py 2017-11-17 03:06:50 +0000
985+++ breezy/tests/test_dirstate.py 2018-03-25 02:37:06 +0000
986@@ -925,7 +925,7 @@
987 for entry in state._iter_entries():
988 values.append(entry[0] + entry[1][0][:1])
989 self.assertEqual(expected_result1, values)
990- del inv['b-id']
991+ inv.delete('b-id')
992 state.set_state_from_inventory(inv)
993 values = []
994 for entry in state._iter_entries():
995
996=== modified file 'breezy/tests/test_inv.py'
997--- breezy/tests/test_inv.py 2018-02-16 19:38:39 +0000
998+++ breezy/tests/test_inv.py 2018-03-25 02:37:06 +0000
999@@ -314,7 +314,7 @@
1000 inv.root.file_id = b'some-new-root'
1001 ie.name = u'file2'
1002 self.assertEqual(b'some-tree-root', inv2.root.file_id)
1003- self.assertEqual(u'hello', inv2[b'hello-id'].name)
1004+ self.assertEqual(u'hello', inv2.get_entry(b'hello-id').name)
1005
1006 def test_copy_empty(self):
1007 """Make sure an empty inventory can be copied."""
1008@@ -611,7 +611,7 @@
1009 file1.text_sha1 = ''
1010 delta = [(None, u'path', 'file-id', file1)]
1011 res_inv = self.apply_delta(self, inv, delta, invalid_delta=False)
1012- self.assertEqual('file-id', res_inv['file-id'].file_id)
1013+ self.assertEqual('file-id', res_inv.get_entry('file-id').file_id)
1014
1015 def test_remove_file(self):
1016 inv = self.get_empty_inventory()
1017@@ -940,18 +940,18 @@
1018 inv.revision_id = "revid"
1019 inv.root.revision = "rootrev"
1020 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1021- inv["fileid"].revision = "filerev"
1022- inv["fileid"].executable = True
1023- inv["fileid"].text_sha1 = "ffff"
1024- inv["fileid"].text_size = 1
1025+ inv.get_entry("fileid").revision = "filerev"
1026+ inv.get_entry("fileid").executable = True
1027+ inv.get_entry("fileid").text_sha1 = "ffff"
1028+ inv.get_entry("fileid").text_size = 1
1029 chk_bytes = self.get_chk_bytes()
1030 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1031 bytes = ''.join(chk_inv.to_lines())
1032 new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
1033- root_entry = new_inv[inv.root.file_id]
1034+ root_entry = new_inv.get_entry(inv.root.file_id)
1035 self.assertEqual(None, root_entry._children)
1036 self.assertEqual({'file'}, set(root_entry.children))
1037- file_direct = new_inv["fileid"]
1038+ file_direct = new_inv.get_entry("fileid")
1039 file_found = root_entry.children['file']
1040 self.assertEqual(file_direct.kind, file_found.kind)
1041 self.assertEqual(file_direct.file_id, file_found.file_id)
1042@@ -977,20 +977,20 @@
1043 self.assertEqual(120, p_id_basename._root_node.maximum_size)
1044 self.assertEqual(2, p_id_basename._root_node._key_width)
1045
1046- def test___iter__(self):
1047+ def test_iter_all_ids(self):
1048 inv = Inventory()
1049 inv.revision_id = "revid"
1050 inv.root.revision = "rootrev"
1051 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1052- inv["fileid"].revision = "filerev"
1053- inv["fileid"].executable = True
1054- inv["fileid"].text_sha1 = "ffff"
1055- inv["fileid"].text_size = 1
1056+ inv.get_entry("fileid").revision = "filerev"
1057+ inv.get_entry("fileid").executable = True
1058+ inv.get_entry("fileid").text_sha1 = "ffff"
1059+ inv.get_entry("fileid").text_size = 1
1060 chk_bytes = self.get_chk_bytes()
1061 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1062 bytes = ''.join(chk_inv.to_lines())
1063 new_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
1064- fileids = sorted(new_inv.__iter__())
1065+ fileids = sorted(new_inv.iter_all_ids())
1066 self.assertEqual([inv.root.file_id, "fileid"], fileids)
1067
1068 def test__len__(self):
1069@@ -998,29 +998,29 @@
1070 inv.revision_id = "revid"
1071 inv.root.revision = "rootrev"
1072 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1073- inv["fileid"].revision = "filerev"
1074- inv["fileid"].executable = True
1075- inv["fileid"].text_sha1 = "ffff"
1076- inv["fileid"].text_size = 1
1077+ inv.get_entry("fileid").revision = "filerev"
1078+ inv.get_entry("fileid").executable = True
1079+ inv.get_entry("fileid").text_sha1 = "ffff"
1080+ inv.get_entry("fileid").text_size = 1
1081 chk_bytes = self.get_chk_bytes()
1082 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1083 self.assertEqual(2, len(chk_inv))
1084
1085- def test___getitem__(self):
1086+ def test_get_entry(self):
1087 inv = Inventory()
1088 inv.revision_id = b"revid"
1089 inv.root.revision = b"rootrev"
1090 inv.add(InventoryFile(b"fileid", u"file", inv.root.file_id))
1091- inv[b"fileid"].revision = b"filerev"
1092- inv[b"fileid"].executable = True
1093- inv[b"fileid"].text_sha1 = b"ffff"
1094- inv[b"fileid"].text_size = 1
1095+ inv.get_entry(b"fileid").revision = b"filerev"
1096+ inv.get_entry(b"fileid").executable = True
1097+ inv.get_entry(b"fileid").text_sha1 = b"ffff"
1098+ inv.get_entry(b"fileid").text_size = 1
1099 chk_bytes = self.get_chk_bytes()
1100 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1101 data = b''.join(chk_inv.to_lines())
1102 new_inv = CHKInventory.deserialise(chk_bytes, data, (b"revid",))
1103- root_entry = new_inv[inv.root.file_id]
1104- file_entry = new_inv[b"fileid"]
1105+ root_entry = new_inv.get_entry(inv.root.file_id)
1106+ file_entry = new_inv.get_entry(b"fileid")
1107 self.assertEqual("directory", root_entry.kind)
1108 self.assertEqual(inv.root.file_id, root_entry.file_id)
1109 self.assertEqual(inv.root.parent_id, root_entry.parent_id)
1110@@ -1034,17 +1034,17 @@
1111 self.assertEqual(b"ffff", file_entry.text_sha1)
1112 self.assertEqual(1, file_entry.text_size)
1113 self.assertEqual(True, file_entry.executable)
1114- self.assertRaises(errors.NoSuchId, new_inv.__getitem__, 'missing')
1115+ self.assertRaises(errors.NoSuchId, new_inv.get_entry, 'missing')
1116
1117 def test_has_id_true(self):
1118 inv = Inventory()
1119 inv.revision_id = "revid"
1120 inv.root.revision = "rootrev"
1121 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1122- inv["fileid"].revision = "filerev"
1123- inv["fileid"].executable = True
1124- inv["fileid"].text_sha1 = "ffff"
1125- inv["fileid"].text_size = 1
1126+ inv.get_entry("fileid").revision = "filerev"
1127+ inv.get_entry("fileid").executable = True
1128+ inv.get_entry("fileid").text_sha1 = "ffff"
1129+ inv.get_entry("fileid").text_size = 1
1130 chk_bytes = self.get_chk_bytes()
1131 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1132 self.assertTrue(chk_inv.has_id('fileid'))
1133@@ -1066,11 +1066,11 @@
1134 fileentry = InventoryFile("fileid", "file", "dirid")
1135 inv.add(direntry)
1136 inv.add(fileentry)
1137- inv["fileid"].revision = "filerev"
1138- inv["fileid"].executable = True
1139- inv["fileid"].text_sha1 = "ffff"
1140- inv["fileid"].text_size = 1
1141- inv["dirid"].revision = "filerev"
1142+ inv.get_entry("fileid").revision = "filerev"
1143+ inv.get_entry("fileid").executable = True
1144+ inv.get_entry("fileid").text_sha1 = "ffff"
1145+ inv.get_entry("fileid").text_size = 1
1146+ inv.get_entry("dirid").revision = "filerev"
1147 chk_bytes = self.get_chk_bytes()
1148 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1149 bytes = ''.join(chk_inv.to_lines())
1150@@ -1087,11 +1087,11 @@
1151 fileentry = InventoryFile("fileid", "file", "dirid")
1152 inv.add(direntry)
1153 inv.add(fileentry)
1154- inv["fileid"].revision = "filerev"
1155- inv["fileid"].executable = True
1156- inv["fileid"].text_sha1 = "ffff"
1157- inv["fileid"].text_size = 1
1158- inv["dirid"].revision = "filerev"
1159+ inv.get_entry("fileid").revision = "filerev"
1160+ inv.get_entry("fileid").executable = True
1161+ inv.get_entry("fileid").text_sha1 = "ffff"
1162+ inv.get_entry("fileid").text_size = 1
1163+ inv.get_entry("dirid").revision = "filerev"
1164 chk_bytes = self.get_chk_bytes()
1165 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1166 bytes = ''.join(chk_inv.to_lines())
1167@@ -1172,18 +1172,18 @@
1168 inv.revision_id = "revid"
1169 inv.root.revision = "rootrev"
1170 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1171- inv["fileid"].revision = "filerev"
1172- inv["fileid"].executable = True
1173- inv["fileid"].text_sha1 = "ffff"
1174- inv["fileid"].text_size = 1
1175+ inv.get_entry("fileid").revision = "filerev"
1176+ inv.get_entry("fileid").executable = True
1177+ inv.get_entry("fileid").text_sha1 = "ffff"
1178+ inv.get_entry("fileid").text_size = 1
1179 inv2 = Inventory()
1180 inv2.revision_id = "revid2"
1181 inv2.root.revision = "rootrev"
1182 inv2.add(InventoryFile("fileid", "file", inv.root.file_id))
1183- inv2["fileid"].revision = "filerev2"
1184- inv2["fileid"].executable = False
1185- inv2["fileid"].text_sha1 = "bbbb"
1186- inv2["fileid"].text_size = 2
1187+ inv2.get_entry("fileid").revision = "filerev2"
1188+ inv2.get_entry("fileid").executable = False
1189+ inv2.get_entry("fileid").text_sha1 = "bbbb"
1190+ inv2.get_entry("fileid").text_size = 2
1191 # get fresh objects.
1192 chk_bytes = self.get_chk_bytes()
1193 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1194@@ -1202,10 +1202,10 @@
1195 inv.revision_id = "revid"
1196 inv.root.revision = "rootrev"
1197 inv.add(InventoryFile("fileid", "file", inv.root.file_id))
1198- inv["fileid"].revision = "filerev"
1199- inv["fileid"].executable = True
1200- inv["fileid"].text_sha1 = "ffff"
1201- inv["fileid"].text_size = 1
1202+ inv.get_entry("fileid").revision = "filerev"
1203+ inv.get_entry("fileid").executable = True
1204+ inv.get_entry("fileid").text_sha1 = "ffff"
1205+ inv.get_entry("fileid").text_size = 1
1206 # get fresh objects.
1207 chk_bytes = self.get_chk_bytes()
1208 tmp_inv = CHKInventory.from_inventory(chk_bytes, inv)
1209@@ -1327,14 +1327,14 @@
1210 inv.root.revision = "rootrev"
1211 root_id = inv.root.file_id
1212 inv.add(InventoryFile("fileid", u'f\xefle', root_id))
1213- inv["fileid"].revision = "filerev"
1214- inv["fileid"].text_sha1 = "ffff"
1215- inv["fileid"].text_size = 0
1216+ inv.get_entry("fileid").revision = "filerev"
1217+ inv.get_entry("fileid").text_sha1 = "ffff"
1218+ inv.get_entry("fileid").text_size = 0
1219 inv.add(InventoryDirectory("dirid", u'dir-\N{EURO SIGN}', root_id))
1220 inv.add(InventoryFile("childid", u'ch\xefld', "dirid"))
1221- inv["childid"].revision = "filerev"
1222- inv["childid"].text_sha1 = "ffff"
1223- inv["childid"].text_size = 0
1224+ inv.get_entry("childid").revision = "filerev"
1225+ inv.get_entry("childid").text_sha1 = "ffff"
1226+ inv.get_entry("childid").text_size = 0
1227 chk_bytes = self.get_chk_bytes()
1228 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1229 bytes = ''.join(chk_inv.to_lines())
1230@@ -1360,16 +1360,16 @@
1231 inv.root.revision = "rootrev"
1232 root_id = inv.root.file_id
1233 inv.add(InventoryFile("fileid", "file", root_id))
1234- inv["fileid"].revision = "filerev"
1235- inv["fileid"].executable = True
1236- inv["fileid"].text_sha1 = "ffff"
1237- inv["fileid"].text_size = 1
1238+ inv.get_entry("fileid").revision = "filerev"
1239+ inv.get_entry("fileid").executable = True
1240+ inv.get_entry("fileid").text_sha1 = "ffff"
1241+ inv.get_entry("fileid").text_size = 1
1242 inv.add(InventoryDirectory("dirid", "dir", root_id))
1243 inv.add(InventoryFile("childid", "child", "dirid"))
1244- inv["childid"].revision = "filerev"
1245- inv["childid"].executable = False
1246- inv["childid"].text_sha1 = "dddd"
1247- inv["childid"].text_size = 1
1248+ inv.get_entry("childid").revision = "filerev"
1249+ inv.get_entry("childid").executable = False
1250+ inv.get_entry("childid").text_sha1 = "dddd"
1251+ inv.get_entry("childid").text_size = 1
1252 chk_bytes = self.get_chk_bytes()
1253 chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
1254 bytes = ''.join(chk_inv.to_lines())
1255@@ -1388,7 +1388,7 @@
1256
1257 def test__preload_handles_partially_evaluated_inventory(self):
1258 new_inv = self.make_basic_utf8_inventory()
1259- ie = new_inv[new_inv.root_id]
1260+ ie = new_inv.get_entry(new_inv.root_id)
1261 self.assertIs(None, ie._children)
1262 self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
1263 sorted(ie.children.keys()))
1264@@ -1399,7 +1399,7 @@
1265 # No change
1266 self.assertEqual([u'dir-\N{EURO SIGN}', u'f\xefle'],
1267 sorted(ie._children.keys()))
1268- ie_dir = new_inv["dirid"]
1269+ ie_dir = new_inv.get_entry("dirid")
1270 self.assertEqual([u'ch\xefld'],
1271 sorted(ie_dir._children.keys()))
1272
1273@@ -1574,9 +1574,9 @@
1274 inv = mutable_inventory_from_tree(tree)
1275 self.assertEqual(revid, inv.revision_id)
1276 self.assertEqual(2, len(inv))
1277- self.assertEqual("a", inv['thefileid'].name)
1278+ self.assertEqual("a", inv.get_entry('thefileid').name)
1279 # The inventory should be mutable and independent of
1280 # the original tree
1281- self.assertFalse(tree.root_inventory['thefileid'].executable)
1282- inv['thefileid'].executable = True
1283- self.assertFalse(tree.root_inventory['thefileid'].executable)
1284+ self.assertFalse(tree.root_inventory.get_entry('thefileid').executable)
1285+ inv.get_entry('thefileid').executable = True
1286+ self.assertFalse(tree.root_inventory.get_entry('thefileid').executable)
1287
1288=== modified file 'breezy/tests/test_revisiontree.py'
1289--- breezy/tests/test_revisiontree.py 2017-11-24 09:25:13 +0000
1290+++ breezy/tests/test_revisiontree.py 2018-03-25 02:37:06 +0000
1291@@ -76,6 +76,6 @@
1292
1293 def test_get_file_mtime_ghost(self):
1294 path = next(iter(self.rev_tree.all_versioned_paths()))
1295- self.rev_tree.root_inventory[self.rev_tree.path2id(path)].revision = 'ghostrev'
1296+ self.rev_tree.root_inventory.get_entry(self.rev_tree.path2id(path)).revision = 'ghostrev'
1297 self.assertRaises(FileTimestampUnavailable,
1298 self.rev_tree.get_file_mtime, path)
1299
1300=== modified file 'breezy/tests/test_transform.py'
1301--- breezy/tests/test_transform.py 2018-03-24 02:22:27 +0000
1302+++ breezy/tests/test_transform.py 2018-03-25 02:37:06 +0000
1303@@ -400,7 +400,7 @@
1304 tree.lock_read()
1305 self.addCleanup(tree.unlock)
1306 self.assertEqual('subtree-revision',
1307- tree.root_inventory['subtree-id'].reference_revision)
1308+ tree.root_inventory.get_entry('subtree-id').reference_revision)
1309
1310 def test_conflicts(self):
1311 transform, root = self.get_transform()
1312
1313=== modified file 'breezy/tests/test_xml.py'
1314--- breezy/tests/test_xml.py 2018-02-17 02:02:38 +0000
1315+++ breezy/tests/test_xml.py 2018-03-25 02:37:06 +0000
1316@@ -227,11 +227,11 @@
1317 inv = breezy.bzr.xml5.serializer_v5.read_inventory(inp)
1318 eq = self.assertEqual
1319 eq(len(inv), 4)
1320- ie = inv['bar-20050824000535-6bc48cfad47ed134']
1321+ ie = inv.get_entry('bar-20050824000535-6bc48cfad47ed134')
1322 eq(ie.kind, 'file')
1323 eq(ie.revision, 'mbp@foo-00')
1324 eq(ie.name, 'bar')
1325- eq(inv[ie.parent_id].kind, 'directory')
1326+ eq(inv.get_entry(ie.parent_id).kind, 'directory')
1327
1328 def test_unpack_basis_inventory_5(self):
1329 """Unpack canned new-style inventory"""
1330@@ -240,11 +240,11 @@
1331 eq = self.assertEqual
1332 eq(len(inv), 4)
1333 eq(inv.revision_id, 'mbp@sourcefrog.net-20050905063503-43948f59fa127d92')
1334- ie = inv['bar-20050824000535-6bc48cfad47ed134']
1335+ ie = inv.get_entry('bar-20050824000535-6bc48cfad47ed134')
1336 eq(ie.kind, 'file')
1337 eq(ie.revision, 'mbp@foo-00')
1338 eq(ie.name, 'bar')
1339- eq(inv[ie.parent_id].kind, 'directory')
1340+ eq(inv.get_entry(ie.parent_id).kind, 'directory')
1341
1342 def test_unpack_inventory_5a(self):
1343 inv = breezy.bzr.xml5.serializer_v5.read_inventory_from_string(
1344@@ -357,13 +357,13 @@
1345 inv.add(inventory.InventoryDirectory('dir-id', 'dir',
1346 'tree-root-321'))
1347 inv.add(inventory.InventoryLink('link-id', 'link', 'tree-root-321'))
1348- inv['tree-root-321'].revision = 'rev_outer'
1349- inv['dir-id'].revision = 'rev_outer'
1350- inv['file-id'].revision = 'rev_outer'
1351- inv['file-id'].text_sha1 = 'A'
1352- inv['file-id'].text_size = 1
1353- inv['link-id'].revision = 'rev_outer'
1354- inv['link-id'].symlink_target = 'a'
1355+ inv.get_entry('tree-root-321').revision = 'rev_outer'
1356+ inv.get_entry('dir-id').revision = 'rev_outer'
1357+ inv.get_entry('file-id').revision = 'rev_outer'
1358+ inv.get_entry('file-id').text_sha1 = 'A'
1359+ inv.get_entry('file-id').text_size = 1
1360+ inv.get_entry('link-id').revision = 'rev_outer'
1361+ inv.get_entry('link-id').symlink_target = 'a'
1362 return inv
1363
1364 def test_roundtrip_inventory_v7(self):
1365@@ -377,7 +377,7 @@
1366 inv2 = xml7.serializer_v7.read_inventory_from_string(txt)
1367 self.assertEqual(5, len(inv2))
1368 for path, ie in inv.iter_entries():
1369- self.assertEqual(ie, inv2[ie.file_id])
1370+ self.assertEqual(ie, inv2.get_entry(ie.file_id))
1371
1372 def test_roundtrip_inventory_v6(self):
1373 inv = self.get_sample_inventory()
1374@@ -388,7 +388,7 @@
1375 inv2 = xml6.serializer_v6.read_inventory_from_string(txt)
1376 self.assertEqual(4, len(inv2))
1377 for path, ie in inv.iter_entries():
1378- self.assertEqual(ie, inv2[ie.file_id])
1379+ self.assertEqual(ie, inv2.get_entry(ie.file_id))
1380
1381 def test_wrong_format_v7(self):
1382 """Can't accidentally open a file with wrong serializer"""
1383@@ -415,9 +415,9 @@
1384 lines = s_v7.write_inventory_to_lines(inv)
1385 self.assertEqual(breezy.osutils.split_lines(txt), lines)
1386 inv2 = s_v7.read_inventory_from_string(txt)
1387- self.assertEqual('tree-root-321', inv2['nested-id'].parent_id)
1388- self.assertEqual('rev-outer', inv2['nested-id'].revision)
1389- self.assertEqual('rev-inner', inv2['nested-id'].reference_revision)
1390+ self.assertEqual('tree-root-321', inv2.get_entry('nested-id').parent_id)
1391+ self.assertEqual('rev-outer', inv2.get_entry('nested-id').revision)
1392+ self.assertEqual('rev-inner', inv2.get_entry('nested-id').reference_revision)
1393
1394 def test_roundtrip_inventory_v8(self):
1395 inv = self.get_sample_inventory()
1396@@ -425,7 +425,7 @@
1397 inv2 = xml8.serializer_v8.read_inventory_from_string(txt)
1398 self.assertEqual(4, len(inv2))
1399 for path, ie in inv.iter_entries():
1400- self.assertEqual(ie, inv2[ie.file_id])
1401+ self.assertEqual(ie, inv2.get_entry(ie.file_id))
1402
1403 def test_inventory_text_v8(self):
1404 inv = self.get_sample_inventory()
1405
1406=== modified file 'breezy/tree.py'
1407--- breezy/tree.py 2018-03-24 10:24:48 +0000
1408+++ breezy/tree.py 2018-03-25 02:37:06 +0000
1409@@ -1186,7 +1186,7 @@
1410 return (None, None)
1411 else:
1412 self._out_of_order_processed.add(file_id)
1413- cur_ie = other_tree.root_inventory[file_id]
1414+ cur_ie = other_tree.root_inventory.get_entry(file_id)
1415 return (cur_path, cur_ie)
1416
1417 def iter_all(self):

Subscribers

People subscribed via source and target branches