~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
 
20
 
from bzrlib.tests import TestCaseWithTransport
21
20
from bzrlib.branch import Branch
 
21
from bzrlib.errors import NoSuchRevision
22
22
from bzrlib.commit import commit
23
 
from bzrlib.fetch import fetch
24
23
from bzrlib.revision import (find_present_ancestors, combined_graph,
25
24
                             is_ancestor, MultipleRevisionSources)
 
25
from bzrlib.tests import TestCaseWithTransport
26
26
from bzrlib.trace import mutter
27
 
from bzrlib.errors import NoSuchRevision
 
27
from bzrlib.workingtree import WorkingTree
28
28
 
29
29
# XXX: Make this a method of a merge base case
30
30
def make_branches(self):
62
62
    tree2.commit("Commit five", rev_id="b@u-0-4")
63
63
    revisions_2 = br2.revision_history()
64
64
    
65
 
    fetch(from_branch=br2, to_branch=br1)
 
65
    br1.fetch(br2)
66
66
    tree1.add_pending_merge(revisions_2[4])
67
67
    self.assertEquals(revisions_2[4], 'b@u-0-4')
68
68
    tree1.commit("Commit six", rev_id="a@u-0-3")
69
69
    tree1.commit("Commit seven", rev_id="a@u-0-4")
70
70
    tree2.commit("Commit eight", rev_id="b@u-0-5")
71
71
    
72
 
    fetch(from_branch=br2, to_branch=br1)
 
72
    br1.fetch(br2)
73
73
    tree1.add_pending_merge(br2.revision_history()[5])
74
74
    tree1.commit("Commit nine", rev_id="a@u-0-5")
75
75
    # DO NOT FETCH HERE - we WANT a GHOST.
76
 
    #fetch(from_branch=br1, to_branch=br2)
 
76
    # br2.fetch(br1)
77
77
    tree2.add_pending_merge(br1.revision_history()[4])
78
78
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
79
79
    
144
144
        from bzrlib.commit import commit
145
145
        TestCaseWithTransport.setUp(self)
146
146
        self.br1, self.br2 = make_branches(self)
147
 
 
148
 
        self.br2.working_tree().commit("Commit eleven", rev_id="b@u-0-7")
149
 
        self.br2.working_tree().commit("Commit twelve", rev_id="b@u-0-8")
150
 
        self.br2.working_tree().commit("Commit thirtteen", rev_id="b@u-0-9")
151
 
 
152
 
        fetch(from_branch=self.br2, to_branch=self.br1)
153
 
        self.br1.working_tree().add_pending_merge(self.br2.revision_history()[6])
154
 
        self.br1.working_tree().commit("Commit fourtten", rev_id="a@u-0-6")
155
 
 
156
 
        fetch(from_branch=self.br1, to_branch=self.br2)
157
 
        self.br2.working_tree().add_pending_merge(self.br1.revision_history()[6])
158
 
        self.br2.working_tree().commit("Commit fifteen", rev_id="b@u-0-10")
 
147
        wt1 = self.br1.bzrdir.open_workingtree()
 
148
        wt2 = self.br2.bzrdir.open_workingtree()
 
149
        wt2.commit("Commit eleven", rev_id="b@u-0-7")
 
150
        wt2.commit("Commit twelve", rev_id="b@u-0-8")
 
151
        wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
 
152
 
 
153
        self.br1.fetch(self.br2)
 
154
        wt1.add_pending_merge(self.br2.revision_history()[6])
 
155
        wt1.commit("Commit fourtten", rev_id="a@u-0-6")
 
156
 
 
157
        self.br2.fetch(self.br1)
 
158
        wt2.add_pending_merge(self.br1.revision_history()[6])
 
159
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
159
160
 
160
161
        from bzrlib.revision import MultipleRevisionSources
161
162
        self.sources = MultipleRevisionSources(self.br1.repository,
210
211
class TestCommonAncestor(TestCaseWithTransport):
211
212
    """Test checking whether a revision is an ancestor of another revision"""
212
213
 
213
 
    def test_old_common_ancestor(self):
214
 
        """Pick a resonable merge base using the old functionality"""
215
 
        from bzrlib.revision import old_common_ancestor as common_ancestor
216
 
        br1, br2 = make_branches(self)
217
 
        revisions = br1.revision_history()
218
 
        revisions_2 = br2.revision_history()
219
 
        sources = br1.repository
220
 
 
221
 
        expected_ancestors_list = {revisions[3]:(0, 0), 
222
 
                                   revisions[2]:(1, 1),
223
 
                                   revisions_2[4]:(2, 1), 
224
 
                                   revisions[1]:(3, 2),
225
 
                                   revisions_2[3]:(4, 2),
226
 
                                   revisions[0]:(5, 3) }
227
 
        ancestors_list = find_present_ancestors(revisions[3], sources)
228
 
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
229
 
        for key, value in expected_ancestors_list.iteritems():
230
 
            self.assertEqual(ancestors_list[key], value, 
231
 
                              "key %r, %r != %r" % (key, ancestors_list[key],
232
 
                                                    value))
233
 
 
234
 
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
235
 
                          revisions[0])
236
 
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
237
 
                          revisions[1])
238
 
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
239
 
                          revisions[1])
240
 
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
241
 
                          revisions[2])
242
 
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
243
 
                          revisions_2[4])
244
 
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
245
 
                          revisions_2[4])
246
 
        fetch(from_branch=br2, to_branch=br1)
247
 
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
248
 
                          revisions[4]) # revisions_2[5] is equally valid
249
 
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
250
 
                          revisions_2[5])
251
 
 
252
214
    def test_common_ancestor(self):
253
215
        """Pick a reasonable merge base"""
254
216
        from bzrlib.revision import common_ancestor
280
242
                          revisions_2[4])
281
243
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
282
244
                          revisions_2[4])
283
 
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
284
 
                          revisions[4]) # revisions_2[5] is equally valid
285
 
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
286
 
                          revisions[4]) # revisions_2[5] is equally valid
 
245
        self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
 
246
                        (revisions[4], revisions_2[5]))
 
247
        self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
 
248
                        (revisions[4], revisions_2[5]))
 
249
        self.assertEqual(None, common_ancestor(None, revisions[5], sources))
287
250
 
288
251
    def test_combined(self):
289
252
        """combined_graph
299
262
        self.assertEquals(combined_1[2], combined_2[2])
300
263
        self.assertEquals(combined_1[3], combined_2[3])
301
264
        self.assertEquals(combined_1, combined_2)
 
265
 
 
266
    def test_get_history(self):
 
267
        # TODO: test ghosts on the left hand branch's impact
 
268
        # TODO: test ghosts on all parents, we should get some
 
269
        # indicator. i.e. NULL_REVISION
 
270
        # RBC 20060608
 
271
        tree = self.make_branch_and_tree('.')
 
272
        tree.commit('1', rev_id = '1', allow_pointless=True)
 
273
        tree.commit('2', rev_id = '2', allow_pointless=True)
 
274
        tree.commit('3', rev_id = '3', allow_pointless=True)
 
275
        rev = tree.branch.repository.get_revision('1')
 
276
        history = rev.get_history(tree.branch.repository)
 
277
        self.assertEqual([None, '1'], history)
 
278
        rev = tree.branch.repository.get_revision('2')
 
279
        history = rev.get_history(tree.branch.repository)
 
280
        self.assertEqual([None, '1', '2'], history)
 
281
        rev = tree.branch.repository.get_revision('3')
 
282
        history = rev.get_history(tree.branch.repository)
 
283
        self.assertEqual([None, '1', '2' ,'3'], history)