Rev 4671: Change the api a bit. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-faster-log-dir-bug374730
John Arbash Meinel
john at arbash-meinel.com
Wed Sep 23 23:05:53 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-faster-log-dir-bug374730
------------------------------------------------------------
revno: 4671
revision-id: john at arbash-meinel.com-20090923220537-eflh2f38dfflxvix
parent: john at arbash-meinel.com-20090923215633-u3dxk23wsnlx4tqs
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.1-faster-log-dir-bug374730
timestamp: Wed 2009-09-23 17:05:37 -0500
message:
Change the api a bit.
When expanding, we can just get the simple set of all file-ids, along
with a dict mapping parents => children. That is enough to allow
us to walk in proper sorted order.
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2009-09-23 21:56:33 +0000
+++ b/bzrlib/inventory.py 2009-09-23 22:05:37 +0000
@@ -1570,34 +1570,36 @@
"""
# When we hit the TREE_ROOT, we'll get an interesting parent of None,
# but we don't actually want to recurse into that
- interesting_parents = set([None])
+ interesting = set([None])
# TODO: Pre-pass over the list of fileids to see if anything is already
# deserialized in self._fileid_to_entry_cache
directories_to_expand = set()
- # children_of_parent_id = {}
+ children_of_parent_id = {}
# It is okay if some of the fileids are missing
for entry in self._getitems(file_ids):
if entry.kind == 'directory':
directories_to_expand.add(entry.file_id)
- interesting_parents.add(entry.parent_id)
- #children_of_parent_id.setdefault(entry.parent_id, []).append(entry)
+ interesting.add(entry.parent_id)
+ children_of_parent_id.setdefault(entry.parent_id, []
+ ).append(entry.file_id)
- # Now, interesting_parents has all of the direct parents, but not the
+ # Now, interesting has all of the direct parents, but not the
# parents of those parents. It also may have some duplicates with
# specific_fileids
- remaining_parents = interesting_parents.difference(file_ids)
+ remaining_parents = interesting.difference(file_ids)
while remaining_parents:
next_parents = set()
for entry in self._getitems(remaining_parents):
next_parents.add(entry.parent_id)
- #children_of_parent_id.setdefault(entry.parent_id, []).append(entry)
+ children_of_parent_id.setdefault(entry.parent_id, []
+ ).append(entry.file_id)
# Remove any search tips we've already processed
- remaining_parents = next_parents.difference(interesting_parents)
- interesting_parents.update(remaining_parents)
+ remaining_parents = next_parents.difference(interesting)
+ interesting.update(remaining_parents)
# We should probably also .difference(directories_to_expand)
- interesting_parents.discard(None)
- result_file_ids = set(file_ids)
+ interesting.discard(None)
+ interesting.update(file_ids)
while directories_to_expand:
# Expand directories by looking in the
# parent_id_basename_to_file_id map
@@ -1605,12 +1607,14 @@
directories_to_expand = set()
items = self.parent_id_basename_to_file_id.iteritems(keys)
next_file_ids = set([item[1] for item in items])
- next_file_ids = next_file_ids.difference(result_file_ids)
- result_file_ids.update(next_file_ids)
+ next_file_ids = next_file_ids.difference(interesting)
+ interesting.update(next_file_ids)
for entry in self._getitems(next_file_ids):
if entry.kind == 'directory':
directories_to_expand.add(entry.file_id)
- return interesting_parents, result_file_ids
+ children_of_parent_id.setdefault(entry.parent_id, []
+ ).append(entry.file_id)
+ return interesting, children_of_parent_id
def filter(self, specific_fileids):
"""Get an inventory view filtered against a set of file-ids.
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2009-09-23 21:56:33 +0000
+++ b/bzrlib/tests/test_inv.py 2009-09-23 22:05:37 +0000
@@ -1176,11 +1176,20 @@
self.assertEqual(sorted(expected_fileids),
sorted([ie.file_id for ie in inv._getitems(file_ids)]))
- def assertExpand(self, parent_ids, other_ids, inv, file_ids):
- val_parents, val_other = inv._expand_fileids_to_parents_and_children(
- file_ids)
- self.assertEqual(set(parent_ids), val_parents)
- self.assertEqual(set(other_ids), val_other)
+ def assertExpand(self, all_ids, inv, file_ids):
+ (val_all_ids,
+ val_children) = inv._expand_fileids_to_parents_and_children(file_ids)
+ self.assertEqual(set(all_ids), val_all_ids)
+ entries = inv._getitems(val_all_ids)
+ expected_children = {}
+ for entry in entries:
+ s = expected_children.setdefault(entry.parent_id, [])
+ s.append(entry.file_id)
+ val_children = dict((k, sorted(v)) for k, v
+ in val_children.iteritems())
+ expected_children = dict((k, sorted(v)) for k, v
+ in expected_children.iteritems())
+ self.assertEqual(expected_children, val_children)
def test_make_simple_inventory(self):
inv = self.make_simple_inventory()
@@ -1215,16 +1224,16 @@
def test_single_file(self):
inv = self.make_simple_inventory()
- self.assertExpand(['TREE_ROOT'], ['top-id'], inv, ['top-id'])
+ self.assertExpand(['TREE_ROOT', 'top-id'], inv, ['top-id'])
def test_get_all_parents(self):
inv = self.make_simple_inventory()
- self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id'],
- ['subsub-file1-id'], inv, ['subsub-file1-id'])
+ self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id',
+ 'subsub-file1-id',
+ ], inv, ['subsub-file1-id'])
def test_get_children(self):
inv = self.make_simple_inventory()
- self.assertExpand(['TREE_ROOT'],
- ['dir1-id', 'sub-dir1-id', 'sub-file1-id',
- 'sub-file2-id', 'subsub-file1-id',
+ self.assertExpand(['TREE_ROOT', 'dir1-id', 'sub-dir1-id',
+ 'sub-file1-id', 'sub-file2-id', 'subsub-file1-id',
], inv, ['dir1-id'])
More information about the bazaar-commits
mailing list