Rev 3518: Handle more cases when the other tree has extra nodes. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/multi_walker
John Arbash Meinel
john at arbash-meinel.com
Mon Jun 30 22:32:39 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/multi_walker
------------------------------------------------------------
revno: 3518
revision-id: john at arbash-meinel.com-20080630213204-w4f20aico7ta1bs1
parent: john at arbash-meinel.com-20080630212750-h05siuu3vd40dhhf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: multi_walker
timestamp: Mon 2008-06-30 16:32:04 -0500
message:
Handle more cases when the other tree has extra nodes.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_tree.py'
--- a/bzrlib/tests/test_tree.py 2008-06-30 21:27:50 +0000
+++ b/bzrlib/tests/test_tree.py 2008-06-30 21:32:04 +0000
@@ -291,7 +291,7 @@
self.assertWalkerNext(u'e', 'b-id', True, [u'b'], iterator)
self.assertRaises(StopIteration, iterator.next)
- def test_other_extra(self):
+ def test_other_extra_in_middle(self):
tree = self.make_branch_and_tree('tree')
self.build_tree(['tree/a', 'tree/b', 'tree/d'])
tree.add(['a', 'b', 'd'], ['a-id', 'b-id', 'd-id'])
@@ -306,3 +306,20 @@
self.assertWalkerNext(u'd', 'd-id', True, [u'd'], iterator)
self.assertWalkerNext(u'b', 'b-id', False, [u'b'], iterator)
self.assertRaises(StopIteration, iterator.next)
+
+ def test_other_extra_at_end(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/a', 'tree/b', 'tree/d'])
+ tree.add(['a', 'b', 'd'], ['a-id', 'b-id', 'd-id'])
+ tree.commit('first', rev_id='first-rev-id')
+ tree.remove(['d'])
+
+ basis_tree, root_id = self.lock_and_get_basis_and_root_id(tree)
+ walker = _mod_tree.MultiWalker(tree, [basis_tree])
+ iterator = walker.iter_all()
+ self.assertWalkerNext(u'', root_id, True, [u''], iterator)
+ self.assertWalkerNext(u'a', 'a-id', True, [u'a'], iterator)
+ self.assertWalkerNext(u'b', 'b-id', True, [u'b'], iterator)
+ self.assertWalkerNext(u'd', 'd-id', False, [u'd'], iterator)
+ self.assertRaises(StopIteration, iterator.next)
+
=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py 2008-06-30 21:27:50 +0000
+++ b/bzrlib/tree.py 2008-06-30 21:32:04 +0000
@@ -983,6 +983,11 @@
# Track extra nodes in the other trees
others_extra = [{} for i in xrange(len(self._other_trees))]
+ # Keep track of any nodes that were properly processed just out of
+ # order, that way we don't return them at the end, we don't have to
+ # track *all* processed file_ids, just the out-of-order ones
+ out_of_order_processed = set()
+
def lookup_by_file_id(idx, file_id):
# TODO: Is id2path better as the first call, or is
# inventory[file_id] better as a first check?
@@ -995,6 +1000,7 @@
if cur_path is None:
return (None, None)
else:
+ out_of_order_processed.add(file_id)
cur_ie = self._other_trees[idx].inventory[file_id]
return (cur_path, cur_ie)
@@ -1025,8 +1031,9 @@
while (other_has_more and
self._cmp_path_by_dirblock(other_path, master_path) < 0):
other_file_id = other_ie.file_id
- others_extra[idx][other_file_id] = (other_path,
- other_ie)
+ if other_file_id not in out_of_order_processed:
+ others_extra[idx][other_file_id] = (other_path,
+ other_ie)
other_has_more, other_path, other_ie = \
self._step_one(other_walkers[idx])
if other_has_more and other_ie.file_id == file_id:
@@ -1045,6 +1052,15 @@
# We've matched all the walkers, yield this datapoint
yield master_path, file_id, master_ie, other_values
+ # Make sure we finished iterating all the other trees
+ for idx, (other_has_more, other_path, other_ie) in enumerate(other_entries):
+ while other_has_more:
+ other_file_id = other_ie.file_id
+ if other_file_id not in out_of_order_processed:
+ others_extra[idx][other_file_id] = (other_path, other_ie)
+ other_has_more, other_path, other_ie = \
+ self._step_one(other_walkers[idx])
+
# We have walked all of the master tree, now we want to find any extra
# nodes in the other trees
for idx, other_extra in enumerate(others_extra):
More information about the bazaar-commits
mailing list