~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-30 23:05:35 UTC
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070130230535-kx1rd478rtigyc3v
standalone installer: win98 support

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,
24
23
    )
25
24
from bzrlib.branch import Branch
26
25
from bzrlib.errors import NoSuchRevision
27
 
from bzrlib.deprecated_graph import Graph
 
26
from bzrlib.graph import Graph
28
27
from bzrlib.revision import (find_present_ancestors, combined_graph,
29
28
                             common_ancestor,
30
29
                             is_ancestor, MultipleRevisionSources,
31
30
                             NULL_REVISION)
32
 
from bzrlib.symbol_versioning import one_zero, one_three
33
31
from bzrlib.tests import TestCase, TestCaseWithTransport
34
32
from bzrlib.trace import mutter
35
33
from bzrlib.workingtree import WorkingTree
41
39
        r'bzrlib\.tests\.test_revision')
42
40
 
43
41
# XXX: Make this a method of a merge base case
44
 
def make_branches(self, format=None):
 
42
def make_branches(self):
45
43
    """Create two branches
46
44
 
47
45
    branch 1 has 6 commits, branch 2 has 3 commits
60
58
    so A is missing b6 at the start
61
59
    and B is missing a3, a4, a5
62
60
    """
63
 
    tree1 = self.make_branch_and_tree("branch1", format=format)
 
61
    tree1 = self.make_branch_and_tree("branch1")
64
62
    br1 = tree1.branch
65
63
    
66
64
    tree1.commit("Commit one", rev_id="a@u-0-0")
134
132
        revisions_2 = br2.revision_history()
135
133
        sources = br1
136
134
 
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))
 
135
        self.assert_(is_ancestor(revisions[0], revisions[0], br1))
 
136
        self.assert_(is_ancestor(revisions[1], revisions[0], sources))
 
137
        self.assert_(not is_ancestor(revisions[0], revisions[1], sources))
 
138
        self.assert_(is_ancestor(revisions_2[3], revisions[0], sources))
151
139
        # disabled mbp 20050914, doesn't seem to happen anymore
152
140
        ## 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))
 
141
        ##                  revisions[0], br1)        
 
142
        self.assert_(is_ancestor(revisions[3], revisions_2[4], sources))
 
143
        self.assert_(is_ancestor(revisions[3], revisions_2[4], br1))
 
144
        self.assert_(is_ancestor(revisions[3], revisions_2[3], sources))
160
145
        ## self.assert_(not is_ancestor(revisions[3], revisions_2[3], br1))
161
146
 
162
147
 
178
163
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
179
164
 
180
165
        from bzrlib.revision import MultipleRevisionSources
181
 
        self.sources = self.applyDeprecated(one_three,
182
 
                        MultipleRevisionSources, self.br1.repository,
183
 
                                                 self.br2.repository)
 
166
        self.sources = MultipleRevisionSources(self.br1.repository,
 
167
                                               self.br2.repository)
184
168
 
185
169
 
186
170
 
202
186
class TestCommonAncestor(TestCaseWithTransport):
203
187
    """Test checking whether a revision is an ancestor of another revision"""
204
188
 
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
189
    def test_common_ancestor(self):
217
190
        """Pick a reasonable merge base"""
218
191
        br1, br2 = make_branches(self)
219
192
        revisions = br1.revision_history()
220
193
        revisions_2 = br2.revision_history()
221
 
        sources = self.applyDeprecated(one_three, 
222
 
                    MultipleRevisionSources, br1.repository, br2.repository)
 
194
        sources = MultipleRevisionSources(br1.repository, br2.repository)
223
195
        expected_ancestors_list = {revisions[3]:(0, 0), 
224
196
                                   revisions[2]:(1, 1),
225
197
                                   revisions_2[4]:(2, 1), 
232
204
            self.assertEqual(ancestors_list[key], value, 
233
205
                              "key %r, %r != %r" % (key, ancestors_list[key],
234
206
                                                    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])
 
207
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
 
208
                          revisions[0])
 
209
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
 
210
                          revisions[1])
 
211
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
 
212
                          revisions[1])
 
213
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
 
214
                          revisions[2])
 
215
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
 
216
                          revisions_2[4])
 
217
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
 
218
                          revisions_2[4])
 
219
        self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
 
220
                        (revisions[4], revisions_2[5]))
 
221
        self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
 
222
                        (revisions[4], revisions_2[5]))
 
223
        self.assertEqual(None, common_ancestor(None, revisions[5], sources))
 
224
        self.assertEqual(NULL_REVISION,
 
225
            common_ancestor(NULL_REVISION, NULL_REVISION, sources))
 
226
        self.assertEqual(NULL_REVISION,
 
227
            common_ancestor(revisions[0], NULL_REVISION, sources))
 
228
        self.assertEqual(NULL_REVISION,
 
229
            common_ancestor(NULL_REVISION, revisions[0], sources))
259
230
 
260
231
    def test_combined(self):
261
232
        """combined_graph
262
233
        Ensure it's not order-sensitive
263
234
        """
264
235
        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)
 
236
        source = MultipleRevisionSources(br1.repository, br2.repository)
 
237
        combined_1 = combined_graph(br1.last_revision(),
 
238
                                    br2.last_revision(), source)
 
239
        combined_2 = combined_graph(br2.last_revision(),
 
240
                                    br1.last_revision(), source)
273
241
        self.assertEquals(combined_1[1], combined_2[1])
274
242
        self.assertEquals(combined_1[2], combined_2[2])
275
243
        self.assertEquals(combined_1[3], combined_2[3])
307
275
        # add a right-branch revision
308
276
        graph.add_node('right', ['rev1'])
309
277
        source = MockRevisionSource(graph)
310
 
        self.assertCommonAncestorEqual('rev1', source, 'left', 'right')
 
278
        self.assertEqual('rev1', common_ancestor('left', 'right', source))
311
279
 
312
280
 
313
281
class TestMultipleRevisionSources(TestCaseWithTransport):
323
291
        tree_1.commit('foo', rev_id='B', allow_pointless=True)
324
292
        tree_2 = self.make_branch_and_tree('2')
325
293
        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')
 
294
        source = MultipleRevisionSources(tree_1.branch.repository,
 
295
                                         tree_2.branch.repository)
336
296
        self.assertEqual({'B':['A'],
337
 
                          'A':[]}, rev_graph)
 
297
                          'A':[]},
 
298
                         source.get_revision_graph('B'))
338
299
 
339
300
 
340
301
class TestReservedId(TestCase):
348
309
        self.assertEqual(False, revision.is_reserved_id(
349
310
            'arch:a@example.com/c--b--v--r'))
350
311
        self.assertEqual(False, revision.is_reserved_id(None))
351
 
 
352
 
 
353
 
class TestRevisionMethods(TestCase):
354
 
 
355
 
    def test_get_summary(self):
356
 
        r = revision.Revision('1')
357
 
        r.message = 'a'
358
 
        self.assertEqual('a', r.get_summary())
359
 
        r.message = 'a\nb'
360
 
        self.assertEqual('a', r.get_summary())
361
 
        r.message = '\na\nb'
362
 
        self.assertEqual('a', r.get_summary())
363
 
 
364
 
    def test_get_apparent_author(self):
365
 
        r = revision.Revision('1')
366
 
        r.committer = 'A'
367
 
        self.assertEqual('A', r.get_apparent_author())
368
 
        r.properties['author'] = 'B'
369
 
        self.assertEqual('B', r.get_apparent_author())