~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: Wouter van Heyst
  • Date: 2006-06-07 16:05:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060607160527-2b3649154d0e2e84
more code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
#
 
1
# (C) 2005 Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
import os
19
19
import warnings
20
20
 
21
 
from bzrlib import (
22
 
    revision,
23
 
    )
24
21
from bzrlib.branch import Branch
25
22
from bzrlib.errors import NoSuchRevision
26
 
from bzrlib.deprecated_graph import Graph
 
23
from bzrlib.commit import commit
 
24
from bzrlib.graph import Graph
27
25
from bzrlib.revision import (find_present_ancestors, combined_graph,
28
26
                             common_ancestor,
29
 
                             is_ancestor, MultipleRevisionSources,
30
 
                             NULL_REVISION)
31
 
from bzrlib.tests import TestCase, TestCaseWithTransport
 
27
                             is_ancestor, MultipleRevisionSources)
 
28
from bzrlib.tests import TestCaseWithTransport
32
29
from bzrlib.trace import mutter
33
30
from bzrlib.workingtree import WorkingTree
34
31
 
70
67
    tree2.commit("Commit four", rev_id="b@u-0-3")
71
68
    tree2.commit("Commit five", rev_id="b@u-0-4")
72
69
    revisions_2 = br2.revision_history()
73
 
    self.assertEquals(revisions_2[-1], 'b@u-0-4')
74
70
    
75
 
    tree1.merge_from_branch(br2)
 
71
    br1.fetch(br2)
 
72
    tree1.add_pending_merge(revisions_2[4])
 
73
    self.assertEquals(revisions_2[4], 'b@u-0-4')
76
74
    tree1.commit("Commit six", rev_id="a@u-0-3")
77
75
    tree1.commit("Commit seven", rev_id="a@u-0-4")
78
76
    tree2.commit("Commit eight", rev_id="b@u-0-5")
79
 
    self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
80
77
    
81
 
    tree1.merge_from_branch(br2)
 
78
    br1.fetch(br2)
 
79
    tree1.add_pending_merge(br2.revision_history()[5])
82
80
    tree1.commit("Commit nine", rev_id="a@u-0-5")
83
 
    # DO NOT MERGE HERE - we WANT a GHOST.
84
 
    tree2.add_parent_tree_id(br1.revision_history()[4])
 
81
    # DO NOT FETCH HERE - we WANT a GHOST.
 
82
    # br2.fetch(br1)
 
83
    tree2.add_pending_merge(br1.revision_history()[4])
85
84
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
86
85
    
87
86
    return br1, br2
148
147
class TestIntermediateRevisions(TestCaseWithTransport):
149
148
 
150
149
    def setUp(self):
 
150
        from bzrlib.commit import commit
151
151
        TestCaseWithTransport.setUp(self)
152
152
        self.br1, self.br2 = make_branches(self)
153
153
        wt1 = self.br1.bzrdir.open_workingtree()
156
156
        wt2.commit("Commit twelve", rev_id="b@u-0-8")
157
157
        wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
158
158
 
159
 
        wt1.merge_from_branch(self.br2)
 
159
        self.br1.fetch(self.br2)
 
160
        wt1.add_pending_merge(self.br2.revision_history()[6])
160
161
        wt1.commit("Commit fourtten", rev_id="a@u-0-6")
161
162
 
162
 
        wt2.merge_from_branch(self.br1)
 
163
        self.br2.fetch(self.br1)
 
164
        wt2.add_pending_merge(self.br1.revision_history()[6])
163
165
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
164
166
 
165
167
        from bzrlib.revision import MultipleRevisionSources
221
223
        self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
222
224
                        (revisions[4], revisions_2[5]))
223
225
        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))
230
226
 
231
227
    def test_combined(self):
232
228
        """combined_graph
234
230
        """
235
231
        br1, br2 = make_branches(self)
236
232
        source = MultipleRevisionSources(br1.repository, br2.repository)
237
 
        combined_1 = combined_graph(br1.last_revision(),
 
233
        combined_1 = combined_graph(br1.last_revision(), 
238
234
                                    br2.last_revision(), source)
239
235
        combined_2 = combined_graph(br2.last_revision(),
240
236
                                    br1.last_revision(), source)
287
283
        # in repo 2, which has A, the revision_graph()
288
284
        # should return A and B both.
289
285
        tree_1 = self.make_branch_and_tree('1')
290
 
        tree_1.set_parent_ids(['A'], allow_leftmost_as_ghost=True)
 
286
        tree_1.add_pending_merge('A')
291
287
        tree_1.commit('foo', rev_id='B', allow_pointless=True)
292
288
        tree_2 = self.make_branch_and_tree('2')
293
289
        tree_2.commit('bar', rev_id='A', allow_pointless=True)
296
292
        self.assertEqual({'B':['A'],
297
293
                          'A':[]},
298
294
                         source.get_revision_graph('B'))
299
 
 
300
 
 
301
 
class TestReservedId(TestCase):
302
 
 
303
 
    def test_is_reserved_id(self):
304
 
        self.assertEqual(True, revision.is_reserved_id(NULL_REVISION))
305
 
        self.assertEqual(True, revision.is_reserved_id(
306
 
            revision.CURRENT_REVISION))
307
 
        self.assertEqual(True, revision.is_reserved_id('arch:'))
308
 
        self.assertEqual(False, revision.is_reserved_id('null'))
309
 
        self.assertEqual(False, revision.is_reserved_id(
310
 
            'arch:a@example.com/c--b--v--r'))
311
 
        self.assertEqual(False, revision.is_reserved_id(None))