~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: 2007-10-24 12:49:17 UTC
  • mfrom: (2935.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071024124917-xb75eckyxx6vkrlg
Makefile fixes - hooks.html generation & allow python to be overridden (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
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
23
23
    )
24
24
from bzrlib.branch import Branch
25
25
from bzrlib.errors import NoSuchRevision
26
 
from bzrlib.graph import Graph
 
26
from bzrlib.deprecated_graph import Graph
27
27
from bzrlib.revision import (find_present_ancestors, combined_graph,
28
28
                             common_ancestor,
29
29
                             is_ancestor, MultipleRevisionSources,
39
39
        r'bzrlib\.tests\.test_revision')
40
40
 
41
41
# XXX: Make this a method of a merge base case
42
 
def make_branches(self):
 
42
def make_branches(self, format=None):
43
43
    """Create two branches
44
44
 
45
45
    branch 1 has 6 commits, branch 2 has 3 commits
58
58
    so A is missing b6 at the start
59
59
    and B is missing a3, a4, a5
60
60
    """
61
 
    tree1 = self.make_branch_and_tree("branch1")
 
61
    tree1 = self.make_branch_and_tree("branch1", format=format)
62
62
    br1 = tree1.branch
63
63
    
64
64
    tree1.commit("Commit one", rev_id="a@u-0-0")
70
70
    tree2.commit("Commit four", rev_id="b@u-0-3")
71
71
    tree2.commit("Commit five", rev_id="b@u-0-4")
72
72
    revisions_2 = br2.revision_history()
 
73
    self.assertEquals(revisions_2[-1], 'b@u-0-4')
73
74
    
74
 
    br1.fetch(br2)
75
 
    tree1.add_pending_merge(revisions_2[4])
76
 
    self.assertEquals(revisions_2[4], 'b@u-0-4')
 
75
    tree1.merge_from_branch(br2)
77
76
    tree1.commit("Commit six", rev_id="a@u-0-3")
78
77
    tree1.commit("Commit seven", rev_id="a@u-0-4")
79
78
    tree2.commit("Commit eight", rev_id="b@u-0-5")
 
79
    self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
80
80
    
81
 
    br1.fetch(br2)
82
 
    tree1.add_pending_merge(br2.revision_history()[5])
 
81
    tree1.merge_from_branch(br2)
83
82
    tree1.commit("Commit nine", rev_id="a@u-0-5")
84
 
    # DO NOT FETCH HERE - we WANT a GHOST.
85
 
    # br2.fetch(br1)
86
 
    tree2.add_pending_merge(br1.revision_history()[4])
 
83
    # DO NOT MERGE HERE - we WANT a GHOST.
 
84
    tree2.add_parent_tree_id(br1.revision_history()[4])
87
85
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
88
86
    
89
87
    return br1, br2
158
156
        wt2.commit("Commit twelve", rev_id="b@u-0-8")
159
157
        wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
160
158
 
161
 
        self.br1.fetch(self.br2)
162
 
        wt1.add_pending_merge(self.br2.revision_history()[6])
 
159
        wt1.merge_from_branch(self.br2)
163
160
        wt1.commit("Commit fourtten", rev_id="a@u-0-6")
164
161
 
165
 
        self.br2.fetch(self.br1)
166
 
        wt2.add_pending_merge(self.br1.revision_history()[6])
 
162
        wt2.merge_from_branch(self.br1)
167
163
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
168
164
 
169
165
        from bzrlib.revision import MultipleRevisionSources
238
234
        """
239
235
        br1, br2 = make_branches(self)
240
236
        source = MultipleRevisionSources(br1.repository, br2.repository)
241
 
        combined_1 = combined_graph(br1.last_revision(), 
 
237
        combined_1 = combined_graph(br1.last_revision(),
242
238
                                    br2.last_revision(), source)
243
239
        combined_2 = combined_graph(br2.last_revision(),
244
240
                                    br1.last_revision(), source)
291
287
        # in repo 2, which has A, the revision_graph()
292
288
        # should return A and B both.
293
289
        tree_1 = self.make_branch_and_tree('1')
294
 
        tree_1.add_pending_merge('A')
 
290
        tree_1.set_parent_ids(['A'], allow_leftmost_as_ghost=True)
295
291
        tree_1.commit('foo', rev_id='B', allow_pointless=True)
296
292
        tree_2 = self.make_branch_and_tree('2')
297
293
        tree_2.commit('bar', rev_id='A', allow_pointless=True)
300
296
        self.assertEqual({'B':['A'],
301
297
                          'A':[]},
302
298
                         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))
 
312
 
 
313
 
 
314
class TestRevisionMethods(TestCase):
 
315
 
 
316
    def test_get_summary(self):
 
317
        r = revision.Revision('1')
 
318
        r.message = 'a'
 
319
        self.assertEqual('a', r.get_summary())
 
320
        r.message = 'a\nb'
 
321
        self.assertEqual('a', r.get_summary())
 
322
        r.message = '\na\nb'
 
323
        self.assertEqual('a', r.get_summary())
 
324
 
 
325
    def test_get_apparent_author(self):
 
326
        r = revision.Revision('1')
 
327
        r.committer = 'A'
 
328
        self.assertEqual('A', r.get_apparent_author())
 
329
        r.properties['author'] = 'B'
 
330
        self.assertEqual('B', r.get_apparent_author())