/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2005 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1263 by Martin Pool
- clean up imports
17
18
import os
1685.1.67 by Martin Pool
Suppress warning from test of deprecated method
19
import warnings
1263 by Martin Pool
- clean up imports
20
1911.2.1 by John Arbash Meinel
Cache encode/decode operations, saves memory and time. Especially when committing a new kernel tree with 7.7M new lines to annotate
21
from bzrlib import (
22
    revision,
23
    )
1263 by Martin Pool
- clean up imports
24
from bzrlib.branch import Branch
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
25
from bzrlib.errors import NoSuchRevision
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
26
from bzrlib.deprecated_graph import Graph
1390 by Robert Collins
pair programming worx... merge integration and weave
27
from bzrlib.revision import (find_present_ancestors, combined_graph,
1607.1.12 by Robert Collins
Fix common_ancestor to still calculate a common ancestor when ghosts are
28
                             common_ancestor,
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
29
                             is_ancestor, MultipleRevisionSources,
30
                             NULL_REVISION)
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
31
from bzrlib.symbol_versioning import one_zero
1911.2.1 by John Arbash Meinel
Cache encode/decode operations, saves memory and time. Especially when committing a new kernel tree with 7.7M new lines to annotate
32
from bzrlib.tests import TestCase, TestCaseWithTransport
1270 by Martin Pool
- fix recording of merged ancestry lines
33
from bzrlib.trace import mutter
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
34
from bzrlib.workingtree import WorkingTree
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
35
1685.1.67 by Martin Pool
Suppress warning from test of deprecated method
36
# We're allowed to test deprecated interfaces
37
warnings.filterwarnings('ignore',
38
        '.*get_intervening_revisions was deprecated',
39
        DeprecationWarning,
40
        r'bzrlib\.tests\.test_revision')
41
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
42
# XXX: Make this a method of a merge base case
2696.3.3 by Martin Pool
Start setting the default format to dirstate-tags
43
def make_branches(self, format=None):
1392 by Robert Collins
reinstate testfetch test case
44
    """Create two branches
45
46
    branch 1 has 6 commits, branch 2 has 3 commits
1607.1.12 by Robert Collins
Fix common_ancestor to still calculate a common ancestor when ghosts are
47
    commit 10 is a ghosted merge merge from branch 1
1392 by Robert Collins
reinstate testfetch test case
48
49
    the object graph is
50
    B:     A:
51
    a..0   a..0 
52
    a..1   a..1
53
    a..2   a..2
54
    b..3   a..3 merges b..4
55
    b..4   a..4
56
    b..5   a..5 merges b..5
1092.2.26 by Robert Collins
fetch should work with ghosts
57
    b..6 merges a4
1392 by Robert Collins
reinstate testfetch test case
58
59
    so A is missing b6 at the start
60
    and B is missing a3, a4, a5
61
    """
2696.3.3 by Martin Pool
Start setting the default format to dirstate-tags
62
    tree1 = self.make_branch_and_tree("branch1", format=format)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
63
    br1 = tree1.branch
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
64
    
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
65
    tree1.commit("Commit one", rev_id="a@u-0-0")
66
    tree1.commit("Commit two", rev_id="a@u-0-1")
67
    tree1.commit("Commit three", rev_id="a@u-0-2")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
68
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
69
    tree2 = tree1.bzrdir.clone("branch2").open_workingtree()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
70
    br2 = tree2.branch
71
    tree2.commit("Commit four", rev_id="b@u-0-3")
72
    tree2.commit("Commit five", rev_id="b@u-0-4")
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
73
    revisions_2 = br2.revision_history()
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
74
    self.assertEquals(revisions_2[-1], 'b@u-0-4')
1263 by Martin Pool
- clean up imports
75
    
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
76
    tree1.merge_from_branch(br2)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
77
    tree1.commit("Commit six", rev_id="a@u-0-3")
78
    tree1.commit("Commit seven", rev_id="a@u-0-4")
79
    tree2.commit("Commit eight", rev_id="b@u-0-5")
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
80
    self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
81
    
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
82
    tree1.merge_from_branch(br2)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
83
    tree1.commit("Commit nine", rev_id="a@u-0-5")
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
84
    # DO NOT MERGE HERE - we WANT a GHOST.
85
    tree2.add_parent_tree_id(br1.revision_history()[4])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
86
    tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
1266 by Martin Pool
- fix up testrevision to fetch revisions before marking them merged
87
    
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
88
    return br1, br2
89
90
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
91
class TestIsAncestor(TestCaseWithTransport):
92
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
93
    def test_recorded_ancestry(self):
94
        """Test that commit records all ancestors"""
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
95
        br1, br2 = make_branches(self)
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
96
        d = [('a@u-0-0', ['a@u-0-0']),
97
             ('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
98
             ('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
99
             ('b@u-0-3', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3']),
1270 by Martin Pool
- fix recording of merged ancestry lines
100
             ('b@u-0-4', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3',
101
                          'b@u-0-4']),
102
             ('a@u-0-3', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
103
                          'a@u-0-3']),
1271 by Martin Pool
- more commit ancestry tests
104
             ('a@u-0-4', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
105
                          'a@u-0-3', 'a@u-0-4']),
106
             ('b@u-0-5', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
107
                          'b@u-0-5']),
108
             ('a@u-0-5', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
109
                          'b@u-0-3', 'b@u-0-4',
110
                          'b@u-0-5', 'a@u-0-5']),
1392 by Robert Collins
reinstate testfetch test case
111
             ('b@u-0-6', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2',
1271 by Martin Pool
- more commit ancestry tests
112
                          'b@u-0-3', 'b@u-0-4',
113
                          'b@u-0-5', 'b@u-0-6']),
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
114
             ]
1392 by Robert Collins
reinstate testfetch test case
115
        br1_only = ('a@u-0-3', 'a@u-0-4', 'a@u-0-5')
116
        br2_only = ('b@u-0-6',)
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
117
        for branch in br1, br2:
118
            for rev_id, anc in d:
1392 by Robert Collins
reinstate testfetch test case
119
                if rev_id in br1_only and not branch is br1:
120
                    continue
121
                if rev_id in br2_only and not branch is br2:
122
                    continue
1270 by Martin Pool
- fix recording of merged ancestry lines
123
                mutter('ancestry of {%s}: %r',
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
124
                       rev_id, branch.repository.get_ancestry(rev_id))
125
                result = sorted(branch.repository.get_ancestry(rev_id))
126
                self.assertEquals(result, [None] + sorted(anc))
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
127
    
128
    
1272 by Martin Pool
- enable and disable more ancestry tests
129
    def test_is_ancestor(self):
1102 by Martin Pool
- merge test refactoring from robertc
130
        """Test checking whether a revision is an ancestor of another revision"""
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
131
        br1, br2 = make_branches(self)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
132
        revisions = br1.revision_history()
133
        revisions_2 = br2.revision_history()
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
134
        sources = br1
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
135
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
136
        br1.lock_read()
3053.3.2 by Martin Pool
(merge) Support pulling from knits to packs
137
        br2.lock_read()
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
138
        self.addCleanup(br1.unlock)
139
        br2.lock_read()
140
        self.addCleanup(br2.unlock)
141
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
142
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
143
                        is_ancestor, revisions[0], revisions[0], br1))
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
144
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
145
                        is_ancestor, revisions[1], revisions[0], sources))
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
146
        self.assertFalse(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
147
                         is_ancestor, revisions[0], revisions[1], sources))
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
148
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
149
                        is_ancestor, revisions_2[3], revisions[0], sources))
1390 by Robert Collins
pair programming worx... merge integration and weave
150
        # disabled mbp 20050914, doesn't seem to happen anymore
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
151
        ## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
152
        ##                  revisions[0], br1)
153
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
154
                        is_ancestor, revisions[3], revisions_2[4], sources))
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
155
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
156
                        is_ancestor, revisions[3], revisions_2[4], br1))
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
157
        self.assertTrue(self.applyDeprecated(one_zero,
3052.1.5 by John Arbash Meinel
Fix up the is_ancestor checks in test_revision.py
158
                        is_ancestor, revisions[3], revisions_2[3], sources))
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
159
        ## self.assert_(not is_ancestor(revisions[3], revisions_2[3], br1))
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
160
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
161
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
162
class TestIntermediateRevisions(TestCaseWithTransport):
1092.3.2 by Robert Collins
merge from baz2bzr
163
164
    def setUp(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
165
        TestCaseWithTransport.setUp(self)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
166
        self.br1, self.br2 = make_branches(self)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
167
        wt1 = self.br1.bzrdir.open_workingtree()
168
        wt2 = self.br2.bzrdir.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
169
        wt2.commit("Commit eleven", rev_id="b@u-0-7")
170
        wt2.commit("Commit twelve", rev_id="b@u-0-8")
171
        wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
172
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
173
        wt1.merge_from_branch(self.br2)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
174
        wt1.commit("Commit fourtten", rev_id="a@u-0-6")
1268 by Martin Pool
- is_ancestor now works by looking at the Branch's stored ancestry
175
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
176
        wt2.merge_from_branch(self.br1)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
177
        wt2.commit("Commit fifteen", rev_id="b@u-0-10")
1092.3.2 by Robert Collins
merge from baz2bzr
178
179
        from bzrlib.revision import MultipleRevisionSources
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
180
        self.sources = MultipleRevisionSources(self.br1.repository,
181
                                               self.br2.repository)
1092.3.2 by Robert Collins
merge from baz2bzr
182
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
183
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
184
1607.1.12 by Robert Collins
Fix common_ancestor to still calculate a common ancestor when ghosts are
185
class MockRevisionSource(object):
186
    """A RevisionSource that takes a pregenerated graph.
187
188
    This is useful for testing revision graph algorithms where
189
    the actual branch existing is irrelevant.
190
    """
191
192
    def __init__(self, full_graph):
193
        self._full_graph = full_graph
194
195
    def get_revision_graph_with_ghosts(self, revision_ids):
196
        # This is mocked out to just return a constant graph.
197
        return self._full_graph
198
199
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
200
class TestCommonAncestor(TestCaseWithTransport):
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
201
    """Test checking whether a revision is an ancestor of another revision"""
1092.1.39 by Robert Collins
merge from mpool
202
203
    def test_common_ancestor(self):
974.1.65 by Aaron Bentley
Cleanup and test-fixing
204
        """Pick a reasonable merge base"""
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
205
        br1, br2 = make_branches(self)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
206
        revisions = br1.revision_history()
207
        revisions_2 = br2.revision_history()
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
208
        sources = MultipleRevisionSources(br1.repository, br2.repository)
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
209
        expected_ancestors_list = {revisions[3]:(0, 0), 
210
                                   revisions[2]:(1, 1),
211
                                   revisions_2[4]:(2, 1), 
212
                                   revisions[1]:(3, 2),
213
                                   revisions_2[3]:(4, 2),
214
                                   revisions[0]:(5, 3) }
215
        ancestors_list = find_present_ancestors(revisions[3], sources)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
216
        self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
974.1.35 by aaron.bentley at utoronto
Added revision-based common-ancestor checking
217
        for key, value in expected_ancestors_list.iteritems():
218
            self.assertEqual(ancestors_list[key], value, 
219
                              "key %r, %r != %r" % (key, ancestors_list[key],
220
                                                    value))
221
        self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
222
                          revisions[0])
223
        self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
224
                          revisions[1])
225
        self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
226
                          revisions[1])
227
        self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
228
                          revisions[2])
229
        self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
230
                          revisions_2[4])
231
        self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
232
                          revisions_2[4])
1590.1.1 by Robert Collins
Improve common_ancestor performance.
233
        self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
234
                        (revisions[4], revisions_2[5]))
235
        self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
236
                        (revisions[4], revisions_2[5]))
1587.1.11 by Robert Collins
Local commits appear to be working properly.
237
        self.assertEqual(None, common_ancestor(None, revisions[5], sources))
1836.3.1 by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION.
238
        self.assertEqual(NULL_REVISION,
239
            common_ancestor(NULL_REVISION, NULL_REVISION, sources))
240
        self.assertEqual(NULL_REVISION,
241
            common_ancestor(revisions[0], NULL_REVISION, sources))
242
        self.assertEqual(NULL_REVISION,
243
            common_ancestor(NULL_REVISION, revisions[0], sources))
974.1.65 by Aaron Bentley
Cleanup and test-fixing
244
1185.8.1 by Aaron Bentley
Ensured combined_graph is order-insensitive
245
    def test_combined(self):
246
        """combined_graph
247
        Ensure it's not order-sensitive
248
        """
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
249
        br1, br2 = make_branches(self)
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
250
        source = MultipleRevisionSources(br1.repository, br2.repository)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
251
        combined_1 = combined_graph(br1.last_revision(),
1390 by Robert Collins
pair programming worx... merge integration and weave
252
                                    br2.last_revision(), source)
253
        combined_2 = combined_graph(br2.last_revision(),
254
                                    br1.last_revision(), source)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
255
        self.assertEquals(combined_1[1], combined_2[1])
256
        self.assertEquals(combined_1[2], combined_2[2])
257
        self.assertEquals(combined_1[3], combined_2[3])
258
        self.assertEquals(combined_1, combined_2)
1534.4.49 by Robert Collins
Provide a revision.get_history(repository) method for generating a synthetic revision history.
259
260
    def test_get_history(self):
261
        # TODO: test ghosts on the left hand branch's impact
262
        # TODO: test ghosts on all parents, we should get some
263
        # indicator. i.e. NULL_REVISION
264
        # RBC 20060608
265
        tree = self.make_branch_and_tree('.')
266
        tree.commit('1', rev_id = '1', allow_pointless=True)
267
        tree.commit('2', rev_id = '2', allow_pointless=True)
268
        tree.commit('3', rev_id = '3', allow_pointless=True)
269
        rev = tree.branch.repository.get_revision('1')
270
        history = rev.get_history(tree.branch.repository)
271
        self.assertEqual([None, '1'], history)
272
        rev = tree.branch.repository.get_revision('2')
273
        history = rev.get_history(tree.branch.repository)
274
        self.assertEqual([None, '1', '2'], history)
275
        rev = tree.branch.repository.get_revision('3')
276
        history = rev.get_history(tree.branch.repository)
277
        self.assertEqual([None, '1', '2' ,'3'], history)
1594.2.3 by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits.
278
1607.1.12 by Robert Collins
Fix common_ancestor to still calculate a common ancestor when ghosts are
279
    def test_common_ancestor_rootless_graph(self):
280
        # common_ancestor on a graph with no reachable roots - only
281
        # ghosts - should still return a useful value.
282
        graph = Graph()
283
        # add a ghost node which would be a root if it wasn't a ghost.
284
        graph.add_ghost('a_ghost')
285
        # add a normal commit on top of that
286
        graph.add_node('rev1', ['a_ghost'])
287
        # add a left-branch revision
288
        graph.add_node('left', ['rev1'])
289
        # add a right-branch revision
290
        graph.add_node('right', ['rev1'])
291
        source = MockRevisionSource(graph)
292
        self.assertEqual('rev1', common_ancestor('left', 'right', source))
293
1594.2.3 by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits.
294
295
class TestMultipleRevisionSources(TestCaseWithTransport):
296
    """Tests for the MultipleRevisionSources adapter."""
297
298
    def test_get_revision_graph_merges_ghosts(self):
299
        # when we ask for the revision graph for B, which
300
        # is in repo 1 with a ghost of A, and which is not
301
        # in repo 2, which has A, the revision_graph()
302
        # should return A and B both.
303
        tree_1 = self.make_branch_and_tree('1')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
304
        tree_1.set_parent_ids(['A'], allow_leftmost_as_ghost=True)
1594.2.3 by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits.
305
        tree_1.commit('foo', rev_id='B', allow_pointless=True)
306
        tree_2 = self.make_branch_and_tree('2')
307
        tree_2.commit('bar', rev_id='A', allow_pointless=True)
308
        source = MultipleRevisionSources(tree_1.branch.repository,
309
                                         tree_2.branch.repository)
310
        self.assertEqual({'B':['A'],
311
                          'A':[]},
312
                         source.get_revision_graph('B'))
2229.2.3 by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY
313
314
315
class TestReservedId(TestCase):
316
317
    def test_is_reserved_id(self):
318
        self.assertEqual(True, revision.is_reserved_id(NULL_REVISION))
319
        self.assertEqual(True, revision.is_reserved_id(
320
            revision.CURRENT_REVISION))
321
        self.assertEqual(True, revision.is_reserved_id('arch:'))
322
        self.assertEqual(False, revision.is_reserved_id('null'))
323
        self.assertEqual(False, revision.is_reserved_id(
324
            'arch:a@example.com/c--b--v--r'))
325
        self.assertEqual(False, revision.is_reserved_id(None))
2671.5.1 by Lukáš Lalinsky
Strip leading whitespace from the commit message before using the first line as a commit summary.
326
327
328
class TestRevisionMethods(TestCase):
329
330
    def test_get_summary(self):
331
        r = revision.Revision('1')
332
        r.message = 'a'
333
        self.assertEqual('a', r.get_summary())
334
        r.message = 'a\nb'
335
        self.assertEqual('a', r.get_summary())
336
        r.message = '\na\nb'
337
        self.assertEqual('a', r.get_summary())
2671.5.2 by Lukáš Lalinsky
Add Revision.get_author to return the author's name, either from the property 'author' or the name of the committer.
338
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
339
    def test_get_apparent_author(self):
2671.5.2 by Lukáš Lalinsky
Add Revision.get_author to return the author's name, either from the property 'author' or the name of the committer.
340
        r = revision.Revision('1')
341
        r.committer = 'A'
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
342
        self.assertEqual('A', r.get_apparent_author())
2671.5.2 by Lukáš Lalinsky
Add Revision.get_author to return the author's name, either from the property 'author' or the name of the committer.
343
        r.properties['author'] = 'B'
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
344
        self.assertEqual('B', r.get_apparent_author())