~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Robert Collins
  • Date: 2006-03-22 16:26:09 UTC
  • mto: (1666.1.5 integration)
  • mto: This revision was merged to the branch mainline in revision 1622.
  • Revision ID: robertc@robertcollins.net-20060322162609-fd4ba4a57afd33ed
Fix common_ancestor to still calculate a common ancestor when ghosts are
present along all paths of ancestry - there are no 'import' revisions
available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.branch import Branch
21
21
from bzrlib.errors import NoSuchRevision
22
22
from bzrlib.commit import commit
 
23
from bzrlib.graph import Graph
23
24
from bzrlib.revision import (find_present_ancestors, combined_graph,
 
25
                             common_ancestor,
24
26
                             is_ancestor, MultipleRevisionSources)
25
27
from bzrlib.tests import TestCaseWithTransport
26
28
from bzrlib.trace import mutter
31
33
    """Create two branches
32
34
 
33
35
    branch 1 has 6 commits, branch 2 has 3 commits
34
 
    commit 10 was a psuedo merge from branch 1
35
 
    but has been disabled until ghost support is
36
 
    implemented.
 
36
    commit 10 is a ghosted merge merge from branch 1
37
37
 
38
38
    the object graph is
39
39
    B:     A:
208
208
                          'c@u-0-6', self.br2.revision_history())
209
209
 
210
210
 
 
211
class MockRevisionSource(object):
 
212
    """A RevisionSource that takes a pregenerated graph.
 
213
 
 
214
    This is useful for testing revision graph algorithms where
 
215
    the actual branch existing is irrelevant.
 
216
    """
 
217
 
 
218
    def __init__(self, full_graph):
 
219
        self._full_graph = full_graph
 
220
 
 
221
    def get_revision_graph_with_ghosts(self, revision_ids):
 
222
        # This is mocked out to just return a constant graph.
 
223
        return self._full_graph
 
224
 
 
225
 
211
226
class TestCommonAncestor(TestCaseWithTransport):
212
227
    """Test checking whether a revision is an ancestor of another revision"""
213
228
 
214
229
    def test_common_ancestor(self):
215
230
        """Pick a reasonable merge base"""
216
 
        from bzrlib.revision import common_ancestor
217
231
        br1, br2 = make_branches(self)
218
232
        revisions = br1.revision_history()
219
233
        revisions_2 = br2.revision_history()
282
296
        history = rev.get_history(tree.branch.repository)
283
297
        self.assertEqual([None, '1', '2' ,'3'], history)
284
298
 
 
299
    def test_common_ancestor_rootless_graph(self):
 
300
        # common_ancestor on a graph with no reachable roots - only
 
301
        # ghosts - should still return a useful value.
 
302
        graph = Graph()
 
303
        # add a ghost node which would be a root if it wasn't a ghost.
 
304
        graph.add_ghost('a_ghost')
 
305
        # add a normal commit on top of that
 
306
        graph.add_node('rev1', ['a_ghost'])
 
307
        # add a left-branch revision
 
308
        graph.add_node('left', ['rev1'])
 
309
        # add a right-branch revision
 
310
        graph.add_node('right', ['rev1'])
 
311
        source = MockRevisionSource(graph)
 
312
        self.assertEqual('rev1', common_ancestor('left', 'right', source))
 
313
 
285
314
 
286
315
class TestMultipleRevisionSources(TestCaseWithTransport):
287
316
    """Tests for the MultipleRevisionSources adapter."""