126
124
result = sorted(branch.repository.get_ancestry(rev_id))
127
125
self.assertEquals(result, [None] + sorted(anc))
130
def test_is_ancestor(self):
131
"""Test checking whether a revision is an ancestor of another revision"""
132
br1, br2 = make_branches(self)
133
revisions = br1.revision_history()
134
revisions_2 = br2.revision_history()
139
self.addCleanup(br1.unlock)
141
self.addCleanup(br2.unlock)
143
self.assertTrue(self.applyDeprecated(one_zero,
144
is_ancestor, revisions[0], revisions[0], br1))
145
self.assertTrue(self.applyDeprecated(one_zero,
146
is_ancestor, revisions[1], revisions[0], sources))
147
self.assertFalse(self.applyDeprecated(one_zero,
148
is_ancestor, revisions[0], revisions[1], sources))
149
self.assertTrue(self.applyDeprecated(one_zero,
150
is_ancestor, revisions_2[3], revisions[0], sources))
151
# disabled mbp 20050914, doesn't seem to happen anymore
152
## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
153
## revisions[0], br1)
154
self.assertTrue(self.applyDeprecated(one_zero,
155
is_ancestor, revisions[3], revisions_2[4], sources))
156
self.assertTrue(self.applyDeprecated(one_zero,
157
is_ancestor, revisions[3], revisions_2[4], br1))
158
self.assertTrue(self.applyDeprecated(one_zero,
159
is_ancestor, revisions[3], revisions_2[3], sources))
160
## self.assert_(not is_ancestor(revisions[3], revisions_2[3], br1))
163
128
class TestIntermediateRevisions(TestCaseWithTransport):
202
167
class TestCommonAncestor(TestCaseWithTransport):
203
168
"""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)
216
def test_common_ancestor(self):
217
"""Pick a reasonable merge base"""
218
br1, br2 = make_branches(self)
219
revisions = br1.revision_history()
220
revisions_2 = br2.revision_history()
221
sources = self.applyDeprecated(one_three,
222
MultipleRevisionSources, br1.repository, br2.repository)
223
expected_ancestors_list = {revisions[3]:(0, 0),
225
revisions_2[4]:(2, 1),
227
revisions_2[3]:(4, 2),
228
revisions[0]:(5, 3) }
229
ancestors_list = find_present_ancestors(revisions[3], sources)
230
self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
231
for key, value in expected_ancestors_list.iteritems():
232
self.assertEqual(ancestors_list[key], value,
233
"key %r, %r != %r" % (key, ancestors_list[key],
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])
260
def test_combined(self):
262
Ensure it's not order-sensitive
264
br1, br2 = make_branches(self)
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)
273
self.assertEquals(combined_1[1], combined_2[1])
274
self.assertEquals(combined_1[2], combined_2[2])
275
self.assertEquals(combined_1[3], combined_2[3])
276
self.assertEquals(combined_1, combined_2)
278
170
def test_get_history(self):
279
171
# TODO: test ghosts on the left hand branch's impact
280
172
# TODO: test ghosts on all parents, we should get some
294
186
history = rev.get_history(tree.branch.repository)
295
187
self.assertEqual([None, '1', '2' ,'3'], history)
297
def test_common_ancestor_rootless_graph(self):
298
# common_ancestor on a graph with no reachable roots - only
299
# ghosts - should still return a useful value.
301
# add a ghost node which would be a root if it wasn't a ghost.
302
graph.add_ghost('a_ghost')
303
# add a normal commit on top of that
304
graph.add_node('rev1', ['a_ghost'])
305
# add a left-branch revision
306
graph.add_node('left', ['rev1'])
307
# add a right-branch revision
308
graph.add_node('right', ['rev1'])
309
source = MockRevisionSource(graph)
310
self.assertCommonAncestorEqual('rev1', source, 'left', 'right')
313
class TestMultipleRevisionSources(TestCaseWithTransport):
314
"""Tests for the MultipleRevisionSources adapter."""
316
def test_get_revision_graph_merges_ghosts(self):
317
# when we ask for the revision graph for B, which
318
# is in repo 1 with a ghost of A, and which is not
319
# in repo 2, which has A, the revision_graph()
320
# should return A and B both.
321
tree_1 = self.make_branch_and_tree('1')
322
tree_1.set_parent_ids(['A'], allow_leftmost_as_ghost=True)
323
tree_1.commit('foo', rev_id='B', allow_pointless=True)
324
tree_2 = self.make_branch_and_tree('2')
325
tree_2.commit('bar', rev_id='A', allow_pointless=True)
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')
336
self.assertEqual({'B':['A'],
340
190
class TestReservedId(TestCase):