~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testrevision.py

  • Committer: Robert Collins
  • Date: 2005-09-27 07:24:40 UTC
  • mfrom: (1185.1.41)
  • Revision ID: robertc@robertcollins.net-20050927072440-1bf4d99c3e1db5b3
pair programming worx... merge integration and weave

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.branch import Branch
22
22
from bzrlib.commit import commit
23
23
from bzrlib.fetch import fetch
24
 
from bzrlib.revision import (find_present_ancestors, common_ancestor,
25
 
                             is_ancestor)
 
24
from bzrlib.revision import (find_present_ancestors, combined_graph,
 
25
                             is_ancestor, MultipleRevisionSources)
26
26
from bzrlib.trace import mutter
27
27
from bzrlib.errors import NoSuchRevision
28
28
 
29
29
def make_branches():
30
30
    os.mkdir("branch1")
31
 
    br1 = Branch("branch1", init=True)
 
31
    br1 = Branch.initialize("branch1")
32
32
    
33
33
    commit(br1, "Commit one", rev_id="a@u-0-0")
34
34
    commit(br1, "Commit two", rev_id="a@u-0-1")
35
35
    commit(br1, "Commit three", rev_id="a@u-0-2")
36
36
 
37
37
    os.mkdir("branch2")
38
 
    br2 = Branch("branch2", init=True)
 
38
    br2 = Branch.initialize("branch2")
39
39
    br2.update_revisions(br1)
40
40
    commit(br2, "Commit four", rev_id="b@u-0-3")
41
41
    commit(br2, "Commit five", rev_id="b@u-0-4")
89
89
                mutter('ancestry of {%s}: %r',
90
90
                       rev_id, branch.get_ancestry(rev_id))
91
91
                self.assertEquals(sorted(branch.get_ancestry(rev_id)),
92
 
                                  sorted(anc))
 
92
                                  [None] + sorted(anc))
93
93
    
94
94
    
95
95
    def test_is_ancestor(self):
103
103
        assert is_ancestor(revisions[1], revisions[0], sources)
104
104
        assert not is_ancestor(revisions[0], revisions[1], sources)
105
105
        assert is_ancestor(revisions_2[3], revisions[0], sources)
106
 
        # disabled mbp 20050914, doesn't seem to happen anymore
 
106
        # disabled mbp 20050914, doesn't seem to happen anymore
107
107
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
108
108
        ##                  revisions[0], br1)        
109
109
        assert is_ancestor(revisions[3], revisions_2[4], sources)
124
124
        self.br2.commit("Commit twelve", rev_id="b@u-0-8")
125
125
        self.br2.commit("Commit thirtteen", rev_id="b@u-0-9")
126
126
 
127
 
        fetch(from_branch=self.br2, to_branch=self.br1)
 
127
        fetch(from_branch=self.br2, to_branch=self.br1)
128
128
        self.br1.add_pending_merge(self.br2.revision_history()[6])
129
129
        self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
130
130
 
131
 
        fetch(from_branch=self.br1, to_branch=self.br2)
 
131
        fetch(from_branch=self.br1, to_branch=self.br2)
132
132
        self.br2.add_pending_merge(self.br1.revision_history()[6])
133
133
        self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
134
134
 
184
184
class TestCommonAncestor(TestCaseInTempDir):
185
185
    """Test checking whether a revision is an ancestor of another revision"""
186
186
 
 
187
    def test_old_common_ancestor(self):
 
188
        """Pick a resonable merge base using the old functionality"""
 
189
        from bzrlib.revision import old_common_ancestor as common_ancestor
 
190
        br1, br2 = make_branches()
 
191
        revisions = br1.revision_history()
 
192
        revisions_2 = br2.revision_history()
 
193
        sources = br1
 
194
 
 
195
        expected_ancestors_list = {revisions[3]:(0, 0), 
 
196
                                   revisions[2]:(1, 1),
 
197
                                   revisions_2[4]:(2, 1), 
 
198
                                   revisions[1]:(3, 2),
 
199
                                   revisions_2[3]:(4, 2),
 
200
                                   revisions[0]:(5, 3) }
 
201
        ancestors_list = find_present_ancestors(revisions[3], sources)
 
202
        assert len(expected_ancestors_list) == len(ancestors_list)
 
203
        for key, value in expected_ancestors_list.iteritems():
 
204
            self.assertEqual(ancestors_list[key], value, 
 
205
                              "key %r, %r != %r" % (key, ancestors_list[key],
 
206
                                                    value))
 
207
 
 
208
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
 
209
                          revisions[0])
 
210
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
 
211
                          revisions[1])
 
212
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
 
213
                          revisions[1])
 
214
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
 
215
                          revisions[2])
 
216
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
 
217
                          revisions_2[4])
 
218
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
 
219
                          revisions_2[4])
 
220
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
 
221
                          revisions[4])
 
222
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
 
223
                          revisions_2[5])
 
224
 
187
225
    def test_common_ancestor(self):
 
226
        """Pick a reasonable merge base"""
 
227
        from bzrlib.revision import common_ancestor
188
228
        br1, br2 = make_branches()
189
229
        revisions = br1.revision_history()
190
230
        revisions_2 = br2.revision_history()
191
 
        sources = br1
 
231
        sources = MultipleRevisionSources(br1, br2)
192
232
 
193
233
        expected_ancestors_list = {revisions[3]:(0, 0), 
194
234
                                   revisions[2]:(1, 1),
218
258
        self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
219
259
                          revisions[4])
220
260
        self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
221
 
                          revisions_2[5])
222
 
 
223
 
 
224
 
if __name__ == '__main__':
225
 
    import unittest, sys
226
 
    unittest.main()
227
 
    
 
261
                          revisions[4])
 
262
 
 
263
    def test_combined(self):
 
264
        """combined_graph
 
265
        Ensure it's not order-sensitive
 
266
        """
 
267
        br1, br2 = make_branches()
 
268
        source = MultipleRevisionSources(br1, br2)
 
269
        combined_1 = combined_graph(br1.last_revision(), 
 
270
                                    br2.last_revision(), source)
 
271
        combined_2 = combined_graph(br2.last_revision(),
 
272
                                    br1.last_revision(), source)
 
273
        assert combined_1[1] == combined_2[1]
 
274
        assert combined_1[2] == combined_2[2]
 
275
        assert combined_1[3] == combined_2[3]
 
276
        assert combined_1 == combined_2