161
162
self.sources = MultipleRevisionSources(self.br1.repository,
162
163
self.br2.repository)
166
class MockRevisionSource(object):
167
"""A RevisionSource that takes a pregenerated graph.
169
This is useful for testing revision graph algorithms where
170
the actual branch existing is irrelevant.
173
def __init__(self, full_graph):
174
self._full_graph = full_graph
176
def get_revision_graph_with_ghosts(self, revision_ids):
177
# This is mocked out to just return a constant graph.
178
return self._full_graph
165
def intervene(self, ancestor, revision, revision_history=None):
166
from bzrlib.revision import get_intervening_revisions
167
return get_intervening_revisions(ancestor,revision, self.sources,
170
def test_intervene(self):
171
"""Find intermediate revisions, without requiring history"""
172
from bzrlib.errors import NotAncestor, NoSuchRevision
173
self.assertEquals(len(self.intervene('a@u-0-0', 'a@u-0-0')), 0)
174
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
175
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'),
176
['a@u-0-1', 'a@u-0-2'])
177
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-3'),
178
['a@u-0-1', 'a@u-0-2', 'b@u-0-3'])
179
self.assertEqual(self.intervene('b@u-0-3', 'a@u-0-3'),
180
['b@u-0-4', 'a@u-0-3'])
181
self.assertEqual(self.intervene('a@u-0-2', 'a@u-0-3',
182
self.br1.revision_history()),
184
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-5',
185
self.br1.revision_history()),
186
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
188
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6',
189
self.br1.revision_history()),
190
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
192
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'),
193
['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
195
self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6',
196
self.br2.revision_history()),
197
['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
198
self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10'),
199
['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
200
self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10',
201
self.br2.revision_history()),
202
['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
203
self.assertRaises(NotAncestor, self.intervene, 'b@u-0-10', 'b@u-0-6',
204
self.br2.revision_history())
205
self.assertRaises(NoSuchRevision, self.intervene, 'c@u-0-10',
206
'b@u-0-6', self.br2.revision_history())
207
self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10',
208
'c@u-0-6', self.br2.revision_history())
181
211
class TestCommonAncestor(TestCaseWithTransport):
251
282
history = rev.get_history(tree.branch.repository)
252
283
self.assertEqual([None, '1', '2' ,'3'], history)
254
def test_common_ancestor_rootless_graph(self):
255
# common_ancestor on a graph with no reachable roots - only
256
# ghosts - should still return a useful value.
258
# add a ghost node which would be a root if it wasn't a ghost.
259
graph.add_ghost('a_ghost')
260
# add a normal commit on top of that
261
graph.add_node('rev1', ['a_ghost'])
262
# add a left-branch revision
263
graph.add_node('left', ['rev1'])
264
# add a right-branch revision
265
graph.add_node('right', ['rev1'])
266
source = MockRevisionSource(graph)
267
self.assertEqual('rev1', common_ancestor('left', 'right', source))
270
286
class TestMultipleRevisionSources(TestCaseWithTransport):
271
287
"""Tests for the MultipleRevisionSources adapter."""