Rev 3519: Handle some edge cases when we have multiple other trees. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/multi_walker

John Arbash Meinel john at arbash-meinel.com
Mon Jun 30 23:04:59 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/multi_walker

------------------------------------------------------------
revno: 3519
revision-id: john at arbash-meinel.com-20080630220425-vyug6b2sb2yqzz86
parent: john at arbash-meinel.com-20080630213204-w4f20aico7ta1bs1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: multi_walker
timestamp: Mon 2008-06-30 17:04:25 -0500
message:
  Handle some edge cases when we have multiple other trees.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_tree.py'
--- a/bzrlib/tests/test_tree.py	2008-06-30 21:32:04 +0000
+++ b/bzrlib/tests/test_tree.py	2008-06-30 22:04:25 +0000
@@ -202,14 +202,24 @@
             self.assertIs(None, master_ie, 'master should not have an entry')
         self.assertEqual(len(exp_other_paths), len(other_values),
                             'Wrong number of other entries')
-        for exp_other_path, (other_path, other_ie) in \
-                zip(exp_other_paths, other_values):
-            self.assertEqual(exp_other_path, other_path, "Other path incorrect")
-            if exp_other_path is None:
-                self.assertIs(None, other_ie, "Other should not have an entry")
-            else:
-                self.assertEqual(file_id, other_ie.file_id,
-                                 "Incorrect other entry")
+        other_paths = []
+        other_file_ids = []
+        for path, ie in other_values:
+            other_paths.append(path)
+            if ie is None:
+                other_file_ids.append(None)
+            else:
+                other_file_ids.append(ie.file_id)
+        
+        exp_file_ids = []
+        for path in exp_other_paths:
+            if path is None:
+                exp_file_ids.append(None)
+            else:
+                exp_file_ids.append(file_id)
+        self.assertEqual(exp_other_paths, other_paths, "Other paths incorrect")
+        self.assertEqual(exp_file_ids, other_file_ids,
+                         "Other file_ids incorrect")
 
     def lock_and_get_basis_and_root_id(self, tree):
         tree.lock_read()
@@ -323,3 +333,22 @@
         self.assertWalkerNext(u'd', 'd-id', False, [u'd'], iterator)
         self.assertRaises(StopIteration, iterator.next)
 
+    def test_others_extra_at_end(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/a', 'tree/b', 'tree/c', 'tree/d'])
+        tree.add(['a', 'b', 'c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
+        tree.commit('first', rev_id='first-rev-id')
+        tree.remove(['d'])
+        tree.commit('second', rev_id='second-rev-id')
+        tree.remove(['c'])
+
+        basis_tree, root_id = self.lock_and_get_basis_and_root_id(tree)
+        first_tree = tree.branch.repository.revision_tree('first-rev-id')
+        walker = _mod_tree.MultiWalker(tree, [basis_tree, first_tree])
+        iterator = walker.iter_all()
+        self.assertWalkerNext(u'', root_id, True, [u'', u''], iterator)
+        self.assertWalkerNext(u'a', 'a-id', True, [u'a', u'a'], iterator)
+        self.assertWalkerNext(u'b', 'b-id', True, [u'b', u'b'], iterator)
+        self.assertWalkerNext(u'c', 'c-id', False, [u'c', u'c'], iterator)
+        self.assertWalkerNext(u'd', 'd-id', False, [None, u'd'], iterator)
+        self.assertRaises(StopIteration, iterator.next)

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2008-06-30 21:32:04 +0000
+++ b/bzrlib/tree.py	2008-06-30 22:04:25 +0000
@@ -1063,15 +1063,20 @@
 
         # We have walked all of the master tree, now we want to find any extra
         # nodes in the other trees
+        def path_key(other):
+            path = other[0]
+            dirname, basename = os.path.split(path)
+            return (dirname.split(u'/'), basename)
+
         for idx, other_extra in enumerate(others_extra):
             # TODO: we could use a key=XXX rather than cmp=XXX
-            others = sorted(other_extra.itervalues(),
-                            cmp=self._cmp_path_by_dirblock)
+            others = sorted(other_extra.itervalues(), key=path_key)
             for other_path, other_ie in others:
                 file_id = other_ie.file_id
                 other_extra.pop(file_id)
-                other_values = [(other_path, other_ie)]
+                other_values = [(None, None) for i in xrange(idx)]
+                other_values.append((other_path, other_ie))
                 for alt_idx, alt_extra in enumerate(others_extra[idx+1:]):
-                    other_values.append(lookup_by_file_id(alt_idx + idx,
+                    other_values.append(lookup_by_file_id(alt_idx + idx + 1,
                                                           file_id))
                 yield other_path, file_id, None, other_values



More information about the bazaar-commits mailing list