~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-15 21:00:35 UTC
  • mfrom: (3228.4.15 revision_graph)
  • Revision ID: pqm@pqm.ubuntu.com-20080315210035-5qwda8bre2nwsra3
(jam) Update PackRepo.get_revision_graph() to efficiently handle
        ghosts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib import (
22
22
    revision,
 
23
    symbol_versioning,
23
24
    )
24
25
from bzrlib.branch import Branch
25
26
from bzrlib.errors import NoSuchRevision
28
29
                             common_ancestor,
29
30
                             is_ancestor, MultipleRevisionSources,
30
31
                             NULL_REVISION)
31
 
from bzrlib.symbol_versioning import one_zero
 
32
from bzrlib.symbol_versioning import one_zero, one_three
32
33
from bzrlib.tests import TestCase, TestCaseWithTransport
33
34
from bzrlib.trace import mutter
34
35
from bzrlib.workingtree import WorkingTree
177
178
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
178
179
 
179
180
        from bzrlib.revision import MultipleRevisionSources
180
 
        self.sources = MultipleRevisionSources(self.br1.repository,
181
 
                                               self.br2.repository)
 
181
        self.sources = self.applyDeprecated(one_three,
 
182
                        MultipleRevisionSources, self.br1.repository,
 
183
                                                 self.br2.repository)
182
184
 
183
185
 
184
186
 
200
202
class TestCommonAncestor(TestCaseWithTransport):
201
203
    """Test checking whether a revision is an ancestor of another revision"""
202
204
 
 
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
 
203
216
    def test_common_ancestor(self):
204
217
        """Pick a reasonable merge base"""
205
218
        br1, br2 = make_branches(self)
206
219
        revisions = br1.revision_history()
207
220
        revisions_2 = br2.revision_history()
208
 
        sources = MultipleRevisionSources(br1.repository, br2.repository)
 
221
        sources = self.applyDeprecated(one_three, 
 
222
                    MultipleRevisionSources, br1.repository, br2.repository)
209
223
        expected_ancestors_list = {revisions[3]:(0, 0), 
210
224
                                   revisions[2]:(1, 1),
211
225
                                   revisions_2[4]:(2, 1), 
218
232
            self.assertEqual(ancestors_list[key], value, 
219
233
                              "key %r, %r != %r" % (key, ancestors_list[key],
220
234
                                                    value))
221
 
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
222
 
                          revisions[0])
223
 
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
224
 
                          revisions[1])
225
 
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
226
 
                          revisions[1])
227
 
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
228
 
                          revisions[2])
229
 
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
230
 
                          revisions_2[4])
231
 
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
232
 
                          revisions_2[4])
233
 
        self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
234
 
                        (revisions[4], revisions_2[5]))
235
 
        self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
236
 
                        (revisions[4], revisions_2[5]))
237
 
        self.assertEqual(None, common_ancestor(None, revisions[5], sources))
238
 
        self.assertEqual(NULL_REVISION,
239
 
            common_ancestor(NULL_REVISION, NULL_REVISION, sources))
240
 
        self.assertEqual(NULL_REVISION,
241
 
            common_ancestor(revisions[0], NULL_REVISION, sources))
242
 
        self.assertEqual(NULL_REVISION,
243
 
            common_ancestor(NULL_REVISION, revisions[0], sources))
 
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])
244
259
 
245
260
    def test_combined(self):
246
261
        """combined_graph
247
262
        Ensure it's not order-sensitive
248
263
        """
249
264
        br1, br2 = make_branches(self)
250
 
        source = MultipleRevisionSources(br1.repository, br2.repository)
251
 
        combined_1 = combined_graph(br1.last_revision(),
252
 
                                    br2.last_revision(), source)
253
 
        combined_2 = combined_graph(br2.last_revision(),
254
 
                                    br1.last_revision(), source)
 
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)
255
273
        self.assertEquals(combined_1[1], combined_2[1])
256
274
        self.assertEquals(combined_1[2], combined_2[2])
257
275
        self.assertEquals(combined_1[3], combined_2[3])
289
307
        # add a right-branch revision
290
308
        graph.add_node('right', ['rev1'])
291
309
        source = MockRevisionSource(graph)
292
 
        self.assertEqual('rev1', common_ancestor('left', 'right', source))
 
310
        self.assertCommonAncestorEqual('rev1', source, 'left', 'right')
293
311
 
294
312
 
295
313
class TestMultipleRevisionSources(TestCaseWithTransport):
305
323
        tree_1.commit('foo', rev_id='B', allow_pointless=True)
306
324
        tree_2 = self.make_branch_and_tree('2')
307
325
        tree_2.commit('bar', rev_id='A', allow_pointless=True)
308
 
        source = MultipleRevisionSources(tree_1.branch.repository,
309
 
                                         tree_2.branch.repository)
 
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')
310
336
        self.assertEqual({'B':['A'],
311
 
                          'A':[]},
312
 
                         source.get_revision_graph('B'))
 
337
                          'A':[]}, rev_graph)
313
338
 
314
339
 
315
340
class TestReservedId(TestCase):