~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revision.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011, 2016 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
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
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
import os
18
19
import warnings
19
20
 
20
21
from bzrlib import (
21
 
    bugtracker,
22
22
    revision,
23
 
    )
24
 
from bzrlib.errors import (
25
 
    InvalidBugStatus,
26
 
    InvalidLineInBugsProperty,
27
 
    )
28
 
from bzrlib.revision import NULL_REVISION
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.errors import NoSuchRevision
 
27
from bzrlib.deprecated_graph import Graph
 
28
from bzrlib.revision import (find_present_ancestors,
 
29
                             NULL_REVISION)
 
30
from bzrlib.symbol_versioning import one_three
29
31
from bzrlib.tests import TestCase, TestCaseWithTransport
30
 
from bzrlib.tests.matchers import MatchesAncestry
 
32
from bzrlib.trace import mutter
 
33
from bzrlib.workingtree import WorkingTree
31
34
 
32
35
# We're allowed to test deprecated interfaces
33
36
warnings.filterwarnings('ignore',
44
47
 
45
48
    the object graph is
46
49
    B:     A:
47
 
    a..0   a..0
 
50
    a..0   a..0 
48
51
    a..1   a..1
49
52
    a..2   a..2
50
53
    b..3   a..3 merges b..4
57
60
    """
58
61
    tree1 = self.make_branch_and_tree("branch1", format=format)
59
62
    br1 = tree1.branch
60
 
 
 
63
    
61
64
    tree1.commit("Commit one", rev_id="a@u-0-0")
62
65
    tree1.commit("Commit two", rev_id="a@u-0-1")
63
66
    tree1.commit("Commit three", rev_id="a@u-0-2")
64
67
 
65
 
    tree2 = tree1.bzrdir.sprout("branch2").open_workingtree()
 
68
    tree2 = tree1.bzrdir.clone("branch2").open_workingtree()
66
69
    br2 = tree2.branch
67
70
    tree2.commit("Commit four", rev_id="b@u-0-3")
68
71
    tree2.commit("Commit five", rev_id="b@u-0-4")
69
 
    self.assertEqual(br2.last_revision(), 'b@u-0-4')
70
 
 
 
72
    revisions_2 = br2.revision_history()
 
73
    self.assertEquals(revisions_2[-1], 'b@u-0-4')
 
74
    
71
75
    tree1.merge_from_branch(br2)
72
76
    tree1.commit("Commit six", rev_id="a@u-0-3")
73
77
    tree1.commit("Commit seven", rev_id="a@u-0-4")
74
78
    tree2.commit("Commit eight", rev_id="b@u-0-5")
75
 
    self.assertEqual(br2.last_revision(), 'b@u-0-5')
76
 
 
 
79
    self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
 
80
    
77
81
    tree1.merge_from_branch(br2)
78
82
    tree1.commit("Commit nine", rev_id="a@u-0-5")
79
83
    # DO NOT MERGE HERE - we WANT a GHOST.
80
 
    br1.lock_read()
81
 
    try:
82
 
        graph = br1.repository.get_graph()
83
 
        revhistory = list(graph.iter_lefthand_ancestry(br1.last_revision(),
84
 
            [revision.NULL_REVISION]))
85
 
        revhistory.reverse()
86
 
    finally:
87
 
        br1.unlock()
88
 
    tree2.add_parent_tree_id(revhistory[4])
 
84
    tree2.add_parent_tree_id(br1.revision_history()[4])
89
85
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
90
 
 
 
86
    
91
87
    return br1, br2
92
88
 
93
89
 
111
107
             ('a@u-0-5', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
112
108
                          'b@u-0-3', 'b@u-0-4',
113
109
                          'b@u-0-5', 'a@u-0-5']),
114
 
             ('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-4',
 
110
             ('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2',
115
111
                          'b@u-0-3', 'b@u-0-4',
116
112
                          'b@u-0-5', 'b@u-0-6']),
117
113
             ]
123
119
                    continue
124
120
                if rev_id in br2_only and not branch is br2:
125
121
                    continue
126
 
                self.assertThat(anc,
127
 
                    MatchesAncestry(branch.repository, rev_id))
128
 
 
 
122
                mutter('ancestry of {%s}: %r',
 
123
                       rev_id, branch.repository.get_ancestry(rev_id))
 
124
                result = sorted(branch.repository.get_ancestry(rev_id))
 
125
                self.assertEquals(result, [None] + sorted(anc))
 
126
    
129
127
 
130
128
class TestIntermediateRevisions(TestCaseWithTransport):
131
129
 
144
142
        wt2.merge_from_branch(self.br1)
145
143
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
146
144
 
 
145
        from bzrlib.revision import MultipleRevisionSources
 
146
        self.sources = self.applyDeprecated(one_three,
 
147
                        MultipleRevisionSources, self.br1.repository,
 
148
                                                 self.br2.repository)
 
149
 
 
150
 
147
151
 
148
152
class MockRevisionSource(object):
149
153
    """A RevisionSource that takes a pregenerated graph.
206
210
        self.assertEqual('a', r.get_summary())
207
211
        r.message = '\na\nb'
208
212
        self.assertEqual('a', r.get_summary())
209
 
        r.message = None
210
 
        self.assertEqual('', r.get_summary())
211
213
 
212
 
    def test_get_apparent_authors(self):
 
214
    def test_get_apparent_author(self):
213
215
        r = revision.Revision('1')
214
216
        r.committer = 'A'
215
 
        self.assertEqual(['A'], r.get_apparent_authors())
 
217
        self.assertEqual('A', r.get_apparent_author())
216
218
        r.properties['author'] = 'B'
217
 
        self.assertEqual(['B'], r.get_apparent_authors())
218
 
        r.properties['authors'] = 'C\nD'
219
 
        self.assertEqual(['C', 'D'], r.get_apparent_authors())
220
 
 
221
 
    def test_get_apparent_authors_no_committer(self):
222
 
        r = revision.Revision('1')
223
 
        self.assertEqual([], r.get_apparent_authors())
224
 
 
225
 
 
226
 
class TestRevisionBugs(TestCase):
227
 
    """Tests for getting the bugs that a revision is linked to."""
228
 
 
229
 
    def test_no_bugs(self):
230
 
        r = revision.Revision('1')
231
 
        self.assertEqual([], list(r.iter_bugs()))
232
 
 
233
 
    def test_some_bugs(self):
234
 
        r = revision.Revision(
235
 
            '1', properties={
236
 
                'bugs': bugtracker.encode_fixes_bug_urls(
237
 
                    ['http://example.com/bugs/1',
238
 
                     'http://launchpad.net/bugs/1234'])})
239
 
        self.assertEqual(
240
 
            [('http://example.com/bugs/1', bugtracker.FIXED),
241
 
             ('http://launchpad.net/bugs/1234', bugtracker.FIXED)],
242
 
            list(r.iter_bugs()))
243
 
 
244
 
    def test_no_status(self):
245
 
        r = revision.Revision(
246
 
            '1', properties={'bugs': 'http://example.com/bugs/1'})
247
 
        self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
248
 
 
249
 
    def test_too_much_information(self):
250
 
        r = revision.Revision(
251
 
            '1', properties={'bugs': 'http://example.com/bugs/1 fixed bar'})
252
 
        self.assertRaises(InvalidLineInBugsProperty, list, r.iter_bugs())
253
 
 
254
 
    def test_invalid_status(self):
255
 
        r = revision.Revision(
256
 
            '1', properties={'bugs': 'http://example.com/bugs/1 faxed'})
257
 
        self.assertRaises(InvalidBugStatus, list, r.iter_bugs())
 
219
        self.assertEqual('B', r.get_apparent_author())