~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Aaron Bentley
  • Date: 2006-03-18 23:40:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1615.
  • Revision ID: aaron.bentley@utoronto.ca-20060318234051-415e5fcb51da82e4
Allow merge against self, make fetching self a noop

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
24
23
from bzrlib.revision import (find_present_ancestors, combined_graph,
25
 
                             common_ancestor,
26
24
                             is_ancestor, MultipleRevisionSources)
27
25
from bzrlib.tests import TestCaseWithTransport
28
26
from bzrlib.trace import mutter
33
31
    """Create two branches
34
32
 
35
33
    branch 1 has 6 commits, branch 2 has 3 commits
36
 
    commit 10 is a ghosted merge merge from branch 1
 
34
    commit 10 was a psuedo merge from branch 1
 
35
    but has been disabled until ghost support is
 
36
    implemented.
37
37
 
38
38
    the object graph is
39
39
    B:     A:
55
55
    tree1.commit("Commit two", rev_id="a@u-0-1")
56
56
    tree1.commit("Commit three", rev_id="a@u-0-2")
57
57
 
58
 
    tree2 = tree1.bzrdir.clone("branch2").open_workingtree()
 
58
    tree2 = self.make_branch_and_tree("branch2")
59
59
    br2 = tree2.branch
 
60
    br2.update_revisions(br1)
60
61
    tree2.commit("Commit four", rev_id="b@u-0-3")
61
62
    tree2.commit("Commit five", rev_id="b@u-0-4")
62
63
    revisions_2 = br2.revision_history()
161
162
        self.sources = MultipleRevisionSources(self.br1.repository,
162
163
                                               self.br2.repository)
163
164
 
164
 
 
165
 
 
166
 
class MockRevisionSource(object):
167
 
    """A RevisionSource that takes a pregenerated graph.
168
 
 
169
 
    This is useful for testing revision graph algorithms where
170
 
    the actual branch existing is irrelevant.
171
 
    """
172
 
 
173
 
    def __init__(self, full_graph):
174
 
        self._full_graph = full_graph
175
 
 
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, 
 
168
                                         revision_history)
 
169
 
 
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()), 
 
183
                         ['a@u-0-3'])
 
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', 
 
187
                          'a@u-0-5'])
 
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', 
 
191
                          'b@u-0-6'])
 
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', 
 
194
                          'b@u-0-5'])
 
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())
179
209
 
180
210
 
181
211
class TestCommonAncestor(TestCaseWithTransport):
183
213
 
184
214
    def test_common_ancestor(self):
185
215
        """Pick a reasonable merge base"""
 
216
        from bzrlib.revision import common_ancestor
186
217
        br1, br2 = make_branches(self)
187
218
        revisions = br1.revision_history()
188
219
        revisions_2 = br2.revision_history()
251
282
        history = rev.get_history(tree.branch.repository)
252
283
        self.assertEqual([None, '1', '2' ,'3'], history)
253
284
 
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.
257
 
        graph = Graph()
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))
268
 
 
269
285
 
270
286
class TestMultipleRevisionSources(TestCaseWithTransport):
271
287
    """Tests for the MultipleRevisionSources adapter."""