211
211
class TestCommonAncestor(TestCaseWithTransport):
212
212
"""Test checking whether a revision is an ancestor of another revision"""
214
def test_old_common_ancestor(self):
215
"""Pick a resonable merge base using the old functionality"""
216
from bzrlib.revision import old_common_ancestor as common_ancestor
217
br1, br2 = make_branches(self)
218
revisions = br1.revision_history()
219
revisions_2 = br2.revision_history()
220
sources = br1.repository
222
expected_ancestors_list = {revisions[3]:(0, 0),
224
revisions_2[4]:(2, 1),
226
revisions_2[3]:(4, 2),
227
revisions[0]:(5, 3) }
228
ancestors_list = find_present_ancestors(revisions[3], sources)
229
self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
230
for key, value in expected_ancestors_list.iteritems():
231
self.assertEqual(ancestors_list[key], value,
232
"key %r, %r != %r" % (key, ancestors_list[key],
235
self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
237
self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
239
self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
241
self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
243
self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
245
self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
248
self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
249
revisions[4]) # revisions_2[5] is equally valid
250
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
253
214
def test_common_ancestor(self):
254
215
"""Pick a reasonable merge base"""
255
216
from bzrlib.revision import common_ancestor
285
246
revisions[4]) # revisions_2[5] is equally valid
286
247
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
287
248
revisions[4]) # revisions_2[5] is equally valid
249
self.assertEqual(None, common_ancestor(None, revisions[5], sources))
289
251
def test_combined(self):
290
252
"""combined_graph