200
202
class TestCommonAncestor(TestCaseWithTransport):
201
203
"""Test checking whether a revision is an ancestor of another revision"""
205
def assertCommonAncestorEqual(self, expected, sources, rev_a, rev_b):
206
self.assertEqual(expected,
207
self.applyDeprecated(one_three,
208
common_ancestor, rev_a, rev_b, sources))
210
def assertCommonAncestorIn(self, possible, sources, rev_a, rev_b):
211
"""assert that we pick one among multiple possible common ancestors"""
212
self.assertTrue(self.applyDeprecated(one_three,
213
common_ancestor, rev_a, rev_b, sources)
203
216
def test_common_ancestor(self):
204
217
"""Pick a reasonable merge base"""
205
218
br1, br2 = make_branches(self)
206
219
revisions = br1.revision_history()
207
220
revisions_2 = br2.revision_history()
208
sources = MultipleRevisionSources(br1.repository, br2.repository)
221
sources = self.applyDeprecated(one_three,
222
MultipleRevisionSources, br1.repository, br2.repository)
209
223
expected_ancestors_list = {revisions[3]:(0, 0),
210
224
revisions[2]:(1, 1),
211
225
revisions_2[4]:(2, 1),
218
232
self.assertEqual(ancestors_list[key], value,
219
233
"key %r, %r != %r" % (key, ancestors_list[key],
221
self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
223
self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
225
self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
227
self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
229
self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
231
self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
233
self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
234
(revisions[4], revisions_2[5]))
235
self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
236
(revisions[4], revisions_2[5]))
237
self.assertEqual(None, common_ancestor(None, revisions[5], sources))
238
self.assertEqual(NULL_REVISION,
239
common_ancestor(NULL_REVISION, NULL_REVISION, sources))
240
self.assertEqual(NULL_REVISION,
241
common_ancestor(revisions[0], NULL_REVISION, sources))
242
self.assertEqual(NULL_REVISION,
243
common_ancestor(NULL_REVISION, revisions[0], sources))
235
self.assertCommonAncestorEqual(revisions[0], sources,
236
revisions[0], revisions[0])
237
self.assertCommonAncestorEqual(revisions[1], sources,
238
revisions[1], revisions[2])
239
self.assertCommonAncestorEqual(revisions[1], sources,
240
revisions[1], revisions[1])
241
self.assertCommonAncestorEqual(revisions[2], sources,
242
revisions[2], revisions_2[4])
243
self.assertCommonAncestorEqual(revisions_2[4], sources,
244
revisions[3], revisions_2[4])
245
self.assertCommonAncestorEqual(revisions_2[4], sources,
246
revisions[4], revisions_2[5])
247
self.assertCommonAncestorIn((revisions[4], revisions_2[5]), sources,
248
revisions[5], revisions_2[6])
249
self.assertCommonAncestorIn((revisions[4], revisions_2[5]), sources,
250
revisions_2[6], revisions[5])
251
self.assertCommonAncestorEqual(None, sources,
253
self.assertCommonAncestorEqual(NULL_REVISION, sources,
254
NULL_REVISION, NULL_REVISION)
255
self.assertCommonAncestorEqual(NULL_REVISION, sources,
256
revisions[0], NULL_REVISION)
257
self.assertCommonAncestorEqual(NULL_REVISION, sources,
258
NULL_REVISION, revisions[0])
245
260
def test_combined(self):
246
261
"""combined_graph
247
262
Ensure it's not order-sensitive
249
264
br1, br2 = make_branches(self)
250
source = MultipleRevisionSources(br1.repository, br2.repository)
251
combined_1 = combined_graph(br1.last_revision(),
252
br2.last_revision(), source)
253
combined_2 = combined_graph(br2.last_revision(),
254
br1.last_revision(), source)
265
source = self.applyDeprecated(one_three,
266
MultipleRevisionSources, br1.repository, br2.repository)
267
combined_1 = self.applyDeprecated(one_three,
268
combined_graph, br1.last_revision(),
269
br2.last_revision(), source)
270
combined_2 = self.applyDeprecated(one_three,
271
combined_graph, br2.last_revision(),
272
br1.last_revision(), source)
255
273
self.assertEquals(combined_1[1], combined_2[1])
256
274
self.assertEquals(combined_1[2], combined_2[2])
257
275
self.assertEquals(combined_1[3], combined_2[3])
305
323
tree_1.commit('foo', rev_id='B', allow_pointless=True)
306
324
tree_2 = self.make_branch_and_tree('2')
307
325
tree_2.commit('bar', rev_id='A', allow_pointless=True)
308
source = MultipleRevisionSources(tree_1.branch.repository,
309
tree_2.branch.repository)
326
source = self.applyDeprecated(one_three,
327
MultipleRevisionSources, tree_1.branch.repository,
328
tree_2.branch.repository)
329
# get_revision_graph calls the deprecated
330
# get_revision_graph_with_ghosts once for each repository.
331
expected_warning = symbol_versioning.deprecation_string(
332
tree_1.branch.repository.get_revision_graph_with_ghosts,
334
rev_graph = self.callDeprecated([expected_warning, expected_warning],
335
source.get_revision_graph, 'B')
310
336
self.assertEqual({'B':['A'],
312
source.get_revision_graph('B'))
315
340
class TestReservedId(TestCase):