~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib.branch import Branch
26
26
from bzrlib.errors import NoSuchRevision
27
27
from bzrlib.deprecated_graph import Graph
28
 
from bzrlib.revision import (find_present_ancestors, combined_graph,
29
 
                             common_ancestor,
30
 
                             is_ancestor, MultipleRevisionSources,
 
28
from bzrlib.revision import (find_present_ancestors,
31
29
                             NULL_REVISION)
32
 
from bzrlib.symbol_versioning import one_zero, one_three
 
30
from bzrlib.symbol_versioning import one_three
33
31
from bzrlib.tests import TestCase, TestCaseWithTransport
34
32
from bzrlib.trace import mutter
35
33
from bzrlib.workingtree import WorkingTree
126
124
                result = sorted(branch.repository.get_ancestry(rev_id))
127
125
                self.assertEquals(result, [None] + sorted(anc))
128
126
    
129
 
    
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()
135
 
        sources = br1
136
 
 
137
 
        br1.lock_read()
138
 
        br2.lock_read()
139
 
        self.addCleanup(br1.unlock)
140
 
        br2.lock_read()
141
 
        self.addCleanup(br2.unlock)
142
 
 
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))
161
 
 
162
127
 
163
128
class TestIntermediateRevisions(TestCaseWithTransport):
164
129
 
202
167
class TestCommonAncestor(TestCaseWithTransport):
203
168
    """Test checking whether a revision is an ancestor of another revision"""
204
169
 
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))
209
 
 
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)
214
 
                        in possible)
215
 
 
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), 
224
 
                                   revisions[2]:(1, 1),
225
 
                                   revisions_2[4]:(2, 1), 
226
 
                                   revisions[1]:(3, 2),
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],
234
 
                                                    value))
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,
252
 
                                       None, revisions[5])
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])
259
 
 
260
 
    def test_combined(self):
261
 
        """combined_graph
262
 
        Ensure it's not order-sensitive
263
 
        """
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)
277
 
 
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)
296
188
 
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.
300
 
        graph = Graph()
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')
311
 
 
312
 
 
313
 
class TestMultipleRevisionSources(TestCaseWithTransport):
314
 
    """Tests for the MultipleRevisionSources adapter."""
315
 
 
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,
333
 
            one_three)
334
 
        rev_graph = self.callDeprecated([expected_warning, expected_warning],
335
 
                        source.get_revision_graph, 'B')
336
 
        self.assertEqual({'B':['A'],
337
 
                          'A':[]}, rev_graph)
338
 
 
339
189
 
340
190
class TestReservedId(TestCase):
341
191