/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2009, 2011 Canonical Ltd
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
2
#
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.
7
#
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.
12
#
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
16
17
"""Whitebox tests for annotate functionality."""
18
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
19
import codecs
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from .. import (
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
22
    annotate,
23
    tests,
24
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
25
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
26
    BytesIO,
27
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
28
from .ui_testing import StringIOWithEncoding
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
29
30
1551.9.19 by Aaron Bentley
Merge from bzr.dev
31
def annotation(text):
32
    return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
33
34
35
parent_1 = annotation("""\
36
rev1 a
37
rev2 b
38
rev3 c
39
rev4 d
40
rev5 e
41
""")
42
43
44
parent_2 = annotation("""\
45
rev1 a
46
rev3 c
47
rev4 d
48
rev6 f
49
rev7 e
50
rev8 h
51
""")
52
53
54
expected_2_1 = annotation("""\
55
rev1 a
56
blahblah b
57
rev3 c
58
rev4 d
59
rev7 e
60
""")
61
62
63
# a: in both, same value, kept
64
# b: in 1, kept
65
# c: in both, same value, kept
66
# d: in both, same value, kept
67
# e: 1 and 2 disagree, so it goes to blahblah
68
# f: in 2, but not in new, so ignored
69
# g: not in 1 or 2, so it goes to blahblah
70
# h: only in parent 2, so 2 gets it
71
expected_1_2_2 = annotation("""\
72
rev1 a
73
rev2 b
74
rev3 c
75
rev4 d
76
blahblah e
77
blahblah g
78
rev8 h
79
""")
80
81
82
new_1 = """\
83
a
84
b
85
c
86
d
87
e
88
""".splitlines(True)
89
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
90
expected_1 = annotation("""\
91
blahblah a
92
blahblah b
93
blahblah c
94
blahblah d
95
blahblah e
96
""")
97
1551.9.19 by Aaron Bentley
Merge from bzr.dev
98
99
new_2 = """\
100
a
101
b
102
c
103
d
104
e
105
g
106
h
107
""".splitlines(True)
108
109
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
110
# For the 'duplicate' series, both sides introduce the same change, which then
111
# gets merged around. The last-modified should properly reflect this.
112
# We always change the fourth line so that the file is properly tracked as
113
# being modified in each revision. In reality, this probably would happen over
114
# many revisions, and it would be a different line that changes.
115
# BASE
116
#  |\
117
#  A B  # line should be annotated as new for A and B
118
#  |\|
3588.3.1 by John Arbash Meinel
Simple patch to the annotate logic to handle bug #232188
119
#  C D  # line should 'converge' and say A
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
120
#  |/
121
#  E    # D should supersede A and stay as D (not become E because C references
122
#         A)
123
duplicate_base = annotation("""\
124
rev-base first
125
rev-base second
126
rev-base third
127
rev-base fourth-base
128
""")
129
130
duplicate_A = annotation("""\
131
rev-base first
132
rev-A alt-second
133
rev-base third
134
rev-A fourth-A
135
""")
136
137
duplicate_B = annotation("""\
138
rev-base first
139
rev-B alt-second
140
rev-base third
141
rev-B fourth-B
142
""")
143
144
duplicate_C = annotation("""\
145
rev-base first
146
rev-A alt-second
147
rev-base third
148
rev-C fourth-C
149
""")
150
151
duplicate_D = annotation("""\
152
rev-base first
3588.3.1 by John Arbash Meinel
Simple patch to the annotate logic to handle bug #232188
153
rev-A alt-second
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
154
rev-base third
155
rev-D fourth-D
156
""")
157
158
duplicate_E = annotation("""\
159
rev-base first
3588.3.1 by John Arbash Meinel
Simple patch to the annotate logic to handle bug #232188
160
rev-A alt-second
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
161
rev-base third
162
rev-E fourth-E
163
""")
164
165
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
166
class TestAnnotate(tests.TestCaseWithTransport):
167
168
    def create_merged_trees(self):
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
169
        """create 2 trees with merges between them.
170
171
        rev-1 --+
172
         |      |
173
        rev-2  rev-1_1_1
174
         |      |
175
         +------+
176
         |
177
        rev-3
178
        """
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
179
        builder = self.make_branch_builder('branch')
180
        builder.start_series()
181
        self.addCleanup(builder.finish_series)
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
182
        builder.build_snapshot(None, [
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
183
            ('add', ('', 'root-id', 'directory', None)),
184
            ('add', ('a', 'a-id', 'file', 'first\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
185
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
186
            revision_id=b'rev-1')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
187
        builder.build_snapshot(['rev-1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
188
            ('modify', ('a', 'first\nsecond\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
189
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
190
            revision_id=b'rev-2')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
191
        builder.build_snapshot(['rev-1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
192
            ('modify', ('a', 'first\nthird\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
193
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
194
            revision_id=b'rev-1_1_1')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
195
        builder.build_snapshot(['rev-2', 'rev-1_1_1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
196
            ('modify', ('a', 'first\nsecond\nthird\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
197
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
198
            revision_id=b'rev-3')
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
199
        return builder
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
200
201
    def create_deeply_merged_trees(self):
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
202
        """Create some trees with a more complex merge history.
203
204
        rev-1 --+
205
         |      |
206
        rev-2  rev-1_1_1 --+
207
         |      |          |
208
         +------+          |
209
         |      |          |
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
210
        rev-3  rev-1_1_2  rev-1_2_1 ------+
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
211
         |      |          |              |
212
         +------+          |              |
213
         |                 |              |
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
214
        rev-4             rev-1_2_2  rev-1_3_1
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
215
         |                 |              |
216
         +-----------------+              |
217
         |                                |
218
        rev-5                             |
219
         |                                |
220
         +--------------------------------+
221
         |
222
        rev-6
223
        """
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
224
        builder = self.create_merged_trees()
6973.5.2 by Jelmer Vernooij
Add more bees.
225
        builder.build_snapshot(['rev-1_1_1'], [], revision_id=b'rev-1_1_2')
226
        builder.build_snapshot(['rev-3', 'rev-1_1_2'], [], revision_id=b'rev-4')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
227
        builder.build_snapshot(['rev-1_1_1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
228
            ('modify', ('a', 'first\nthird\nfourth\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
229
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
230
            revision_id=b'rev-1_2_1')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
231
        builder.build_snapshot(['rev-1_2_1'], [],
232
            timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
233
            revision_id=b'rev-1_2_2')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
234
        builder.build_snapshot(['rev-4', 'rev-1_2_2'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
235
            ('modify', ('a', 'first\nsecond\nthird\nfourth\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
236
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
237
            revision_id=b'rev-5')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
238
        builder.build_snapshot(['rev-1_2_1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
239
            ('modify', ('a', 'first\nthird\nfourth\nfifth\nsixth\n')),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
240
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com",
6973.5.2 by Jelmer Vernooij
Add more bees.
241
            revision_id=b'rev-1_3_1')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
242
        builder.build_snapshot(['rev-5', 'rev-1_3_1'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
243
            ('modify', ('a',
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
244
                        'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
245
            ], revision_id=b'rev-6')
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
246
        return builder
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
247
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
248
    def create_duplicate_lines_tree(self):
4454.3.25 by John Arbash Meinel
Use BranchBuilder for duplicate_lines_tree
249
        builder = self.make_branch_builder('branch')
250
        builder.start_series()
251
        self.addCleanup(builder.finish_series)
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
252
        base_text = ''.join(l for r, l in duplicate_base)
253
        a_text = ''.join(l for r, l in duplicate_A)
254
        b_text = ''.join(l for r, l in duplicate_B)
255
        c_text = ''.join(l for r, l in duplicate_C)
256
        d_text = ''.join(l for r, l in duplicate_D)
257
        e_text = ''.join(l for r, l in duplicate_E)
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
258
        builder.build_snapshot(None, [
4454.3.25 by John Arbash Meinel
Use BranchBuilder for duplicate_lines_tree
259
            ('add', ('', 'root-id', 'directory', None)),
260
            ('add', ('file', 'file-id', 'file', base_text)),
6973.5.2 by Jelmer Vernooij
Add more bees.
261
            ], revision_id=b'rev-base')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
262
        builder.build_snapshot(['rev-base'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
263
            ('modify', ('file', a_text))],
6973.5.2 by Jelmer Vernooij
Add more bees.
264
            revision_id=b'rev-A')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
265
        builder.build_snapshot(['rev-base'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
266
            ('modify', ('file', b_text))],
6973.5.2 by Jelmer Vernooij
Add more bees.
267
            revision_id=b'rev-B')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
268
        builder.build_snapshot(['rev-A'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
269
            ('modify', ('file', c_text))],
6973.5.2 by Jelmer Vernooij
Add more bees.
270
            revision_id=b'rev-C')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
271
        builder.build_snapshot(['rev-B', 'rev-A'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
272
            ('modify', ('file', d_text))],
6973.5.2 by Jelmer Vernooij
Add more bees.
273
            revision_id=b'rev-D')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
274
        builder.build_snapshot(['rev-C', 'rev-D'], [
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
275
            ('modify', ('file', e_text))],
6973.5.2 by Jelmer Vernooij
Add more bees.
276
            revision_id=b'rev-E')
4454.3.25 by John Arbash Meinel
Use BranchBuilder for duplicate_lines_tree
277
        return builder
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
278
5815.3.7 by Jelmer Vernooij
Factor out assertAnnotateEqualDiff.
279
    def assertAnnotateEqualDiff(self, actual, expected):
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
280
        if actual != expected:
281
            # Create an easier to understand diff when the lines don't actually
282
            # match
283
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
284
                                 ''.join('\t'.join(l) for l in actual))
285
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
286
    def assertBranchAnnotate(self, expected, branch, path, revision_id,
5815.3.8 by Jelmer Vernooij
Add convenience method for testing annotate_file_revision_tree.
287
            verbose=False, full=False, show_ids=False):
288
        tree = branch.repository.revision_tree(revision_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
289
        to_file = BytesIO()
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
290
        annotate.annotate_file_tree(tree, path, to_file,
5815.3.8 by Jelmer Vernooij
Add convenience method for testing annotate_file_revision_tree.
291
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
292
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
293
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
294
    def assertRepoAnnotate(self, expected, repo, path, revision_id):
5815.3.7 by Jelmer Vernooij
Factor out assertAnnotateEqualDiff.
295
        """Assert that the revision is properly annotated."""
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
296
        actual = list(repo.revision_tree(revision_id).annotate_iter(path))
5815.3.7 by Jelmer Vernooij
Factor out assertAnnotateEqualDiff.
297
        self.assertAnnotateEqualDiff(actual, expected)
298
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
299
    def test_annotate_duplicate_lines(self):
3689.1.4 by John Arbash Meinel
Doc strings that reference repository_implementations
300
        # XXX: Should this be a per_repository test?
4454.3.25 by John Arbash Meinel
Use BranchBuilder for duplicate_lines_tree
301
        builder = self.create_duplicate_lines_tree()
302
        repo = builder.get_branch().repository
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
303
        repo.lock_read()
304
        self.addCleanup(repo.unlock)
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
305
        self.assertRepoAnnotate(duplicate_base, repo, 'file', 'rev-base')
306
        self.assertRepoAnnotate(duplicate_A, repo, 'file', 'rev-A')
307
        self.assertRepoAnnotate(duplicate_B, repo, 'file', 'rev-B')
308
        self.assertRepoAnnotate(duplicate_C, repo, 'file', 'rev-C')
309
        self.assertRepoAnnotate(duplicate_D, repo, 'file', 'rev-D')
310
        self.assertRepoAnnotate(duplicate_E, repo, 'file', 'rev-E')
3224.1.4 by John Arbash Meinel
Add a *failing* test to expose why we need better handling when a line is introduced on two sides of a merge.
311
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
312
    def test_annotate_shows_dotted_revnos(self):
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
313
        builder = self.create_merged_trees()
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
314
5815.3.8 by Jelmer Vernooij
Add convenience method for testing annotate_file_revision_tree.
315
        self.assertBranchAnnotate('1     joe@foo | first\n'
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
316
                                  '2     joe@foo | second\n'
317
                                  '1.1.1 barry@f | third\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
318
                                  builder.get_branch(), 'a', 'rev-3')
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
319
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
320
    def test_annotate_limits_dotted_revnos(self):
321
        """Annotate should limit dotted revnos to a depth of 12"""
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
322
        builder = self.create_deeply_merged_trees()
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
323
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
324
        self.assertBranchAnnotate('1     joe@foo | first\n'
325
                                  '2     joe@foo | second\n'
326
                                  '1.1.1 barry@f | third\n'
327
                                  '1.2.1 jerry@f | fourth\n'
328
                                  '1.3.1 george@ | fifth\n'
329
                                  '              | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
330
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
331
                                  verbose=False, full=False)
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
332
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
333
        self.assertBranchAnnotate('1     joe@foo | first\n'
334
                                  '2     joe@foo | second\n'
335
                                  '1.1.1 barry@f | third\n'
336
                                  '1.2.1 jerry@f | fourth\n'
337
                                  '1.3.1 george@ | fifth\n'
338
                                  '1.3.1 george@ | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
339
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
340
                                  verbose=False, full=True)
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
341
342
        # verbose=True shows everything, the full revno, user id, and date
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
343
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
344
                                  '2     joe@foo.com    20061213 | second\n'
345
                                  '1.1.1 barry@foo.com  20061213 | third\n'
346
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
347
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
348
                                  '                              | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
349
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
350
                                  verbose=True, full=False)
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
351
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
352
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
353
                                  '2     joe@foo.com    20061213 | second\n'
354
                                  '1.1.1 barry@foo.com  20061213 | third\n'
355
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
356
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
357
                                  '1.3.1 george@foo.com 20061213 | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
358
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
359
                                  verbose=True, full=True)
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
360
361
    def test_annotate_uses_branch_context(self):
362
        """Dotted revnos should use the Branch context.
363
364
        When annotating a non-mainline revision, the annotation should still
365
        use dotted revnos from the mainline.
366
        """
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
367
        builder = self.create_deeply_merged_trees()
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
368
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
369
        self.assertBranchAnnotate('1     joe@foo | first\n'
370
                                  '1.1.1 barry@f | third\n'
371
                                  '1.2.1 jerry@f | fourth\n'
372
                                  '1.3.1 george@ | fifth\n'
373
                                  '              | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
374
                                  builder.get_branch(), 'a', 'rev-1_3_1',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
375
                                  verbose=False, full=False)
2245.3.1 by John Arbash Meinel
bzr annotate should use Branch's dotted revnos.
376
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
377
    def test_annotate_show_ids(self):
4454.3.24 by John Arbash Meinel
update BranchBuilder to support 'committer'
378
        builder = self.create_deeply_merged_trees()
2182.3.4 by John Arbash Meinel
add show-ids and test that nearby areas are collapsed without full
379
380
        # It looks better with real revision ids :)
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
381
        self.assertBranchAnnotate('    rev-1 | first\n'
382
                                  '    rev-2 | second\n'
383
                                  'rev-1_1_1 | third\n'
384
                                  'rev-1_2_1 | fourth\n'
385
                                  'rev-1_3_1 | fifth\n'
386
                                  '          | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
387
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
388
                                  show_ids=True, full=False)
389
390
        self.assertBranchAnnotate('    rev-1 | first\n'
391
                                  '    rev-2 | second\n'
392
                                  'rev-1_1_1 | third\n'
393
                                  'rev-1_2_1 | fourth\n'
394
                                  'rev-1_3_1 | fifth\n'
395
                                  'rev-1_3_1 | sixth\n',
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
396
                                  builder.get_branch(), 'a', 'rev-6',
5815.3.9 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
397
                                  show_ids=True, full=True)
1551.9.19 by Aaron Bentley
Merge from bzr.dev
398
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
399
    def test_annotate_unicode_author(self):
400
        tree1 = self.make_branch_and_tree('tree1')
401
6855.4.1 by Jelmer Vernooij
Yet more bees.
402
        self.build_tree_contents([('tree1/a', b'adi\xc3\xb3s')])
403
        tree1.add(['a'], [b'a-id'])
404
        tree1.commit('a', rev_id=b'rev-1',
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
405
                     committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
406
                     timestamp=1166046000.00, timezone=0)
407
6855.4.1 by Jelmer Vernooij
Yet more bees.
408
        self.build_tree_contents([('tree1/b', b'bye')])
409
        tree1.add(['b'], [b'b-id'])
410
        tree1.commit('b', rev_id=b'rev-2',
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
411
                     committer=u'p\xe9rez',
412
                     timestamp=1166046000.00, timezone=0)
413
3010.1.1 by Robert Collins
Lock the tree's used to test annotate_file, and add a docstring for annotate_file explaining its needs.
414
        tree1.lock_read()
415
        self.addCleanup(tree1.unlock)
5815.3.10 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
416
6973.5.2 by Jelmer Vernooij
Add more bees.
417
        revtree_1 = tree1.branch.repository.revision_tree(b'rev-1')
418
        revtree_2 = tree1.branch.repository.revision_tree(b'rev-2')
5815.3.10 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
419
2593.1.2 by Adeodato Simó
Improve tests a bit, actually checking for the replace encoding.
420
        # this passes if no exception is raised
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
421
        to_file = BytesIO()
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
422
        annotate.annotate_file_tree(revtree_1, 'a',
5815.3.10 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
423
            to_file=to_file, branch=tree1.branch)
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
424
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
425
        sio = BytesIO()
426
        to_file = codecs.getwriter('ascii')(sio, 'replace')
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
427
        annotate.annotate_file_tree(revtree_2, 'b',
5815.3.10 by Jelmer Vernooij
Convert more tests to use annotate_file_revision_tree.
428
            to_file=to_file, branch=tree1.branch)
2593.1.2 by Adeodato Simó
Improve tests a bit, actually checking for the replace encoding.
429
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
2593.1.1 by Adeodato Simó
Improve annotate to prevent unicode exceptions in certain situations.
430
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
431
        # test now with unicode file-like
432
        to_file = StringIOWithEncoding()
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
433
        annotate.annotate_file_tree(revtree_2, 'b',
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
434
            to_file=to_file, branch=tree1.branch)
435
        self.assertContainsRe(u'2   p\xe9rez   | bye\n', to_file.getvalue())
2593.1.3 by Adeodato Simó
Cope with to_file.encoding being None or not present.
436
2671.5.3 by Lukáš Lalinsky
Use the author name in annotate.
437
    def test_annotate_author_or_committer(self):
438
        tree1 = self.make_branch_and_tree('tree1')
439
6855.4.1 by Jelmer Vernooij
Yet more bees.
440
        self.build_tree_contents([('tree1/a', b'hello')])
441
        tree1.add(['a'], [b'a-id'])
442
        tree1.commit('a', rev_id=b'rev-1',
2671.5.3 by Lukáš Lalinsky
Use the author name in annotate.
443
                     committer='Committer <committer@example.com>',
444
                     timestamp=1166046000.00, timezone=0)
445
6855.4.1 by Jelmer Vernooij
Yet more bees.
446
        self.build_tree_contents([('tree1/b', b'bye')])
447
        tree1.add(['b'], [b'b-id'])
448
        tree1.commit('b', rev_id=b'rev-2',
2671.5.3 by Lukáš Lalinsky
Use the author name in annotate.
449
                     committer='Committer <committer@example.com>',
4056.2.1 by James Westby
Allow specifying multiple authors for a revision.
450
                     authors=['Author <author@example.com>'],
2671.5.3 by Lukáš Lalinsky
Use the author name in annotate.
451
                     timestamp=1166046000.00, timezone=0)
452
3010.1.1 by Robert Collins
Lock the tree's used to test annotate_file, and add a docstring for annotate_file explaining its needs.
453
        tree1.lock_read()
454
        self.addCleanup(tree1.unlock)
5815.3.11 by Jelmer Vernooij
Remove last use of deprecated method.
455
456
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
457
            'a', 'rev-1')
5815.3.11 by Jelmer Vernooij
Remove last use of deprecated method.
458
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
459
        to_file = BytesIO()
5815.3.11 by Jelmer Vernooij
Remove last use of deprecated method.
460
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
461
            'b', 'rev-2')
2671.5.3 by Lukáš Lalinsky
Use the author name in annotate.
462
1551.9.19 by Aaron Bentley
Merge from bzr.dev
463
464
class TestReannotate(tests.TestCase):
465
2770.1.5 by Aaron Bentley
Clean up docs, test matching blocks for reannotate
466
    def annotateEqual(self, expected, parents, newlines, revision_id,
467
                      blocks=None):
1551.9.19 by Aaron Bentley
Merge from bzr.dev
468
        annotate_list = list(annotate.reannotate(parents, newlines,
2770.1.5 by Aaron Bentley
Clean up docs, test matching blocks for reannotate
469
                             revision_id, blocks))
1551.9.19 by Aaron Bentley
Merge from bzr.dev
470
        self.assertEqual(len(expected), len(annotate_list))
471
        for e, a in zip(expected, annotate_list):
472
            self.assertEqual(e, a)
473
474
    def test_reannotate(self):
475
        self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
476
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
477
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,
1551.9.19 by Aaron Bentley
Merge from bzr.dev
478
                           'blahblah')
2770.1.1 by Aaron Bentley
Initial implmentation of plain knit annotation
479
480
    def test_reannotate_no_parents(self):
481
        self.annotateEqual(expected_1, [], new_1, 'blahblah')
2770.1.5 by Aaron Bentley
Clean up docs, test matching blocks for reannotate
482
483
    def test_reannotate_left_matching_blocks(self):
484
        """Ensure that left_matching_blocks has an impact.
485
486
        In this case, the annotation is ambiguous, so the hint isn't actually
487
        lying.
488
        """
489
        parent = [('rev1', 'a\n')]
490
        new_text = ['a\n', 'a\n']
491
        blocks = [(0, 0, 1), (1, 2, 0)]
492
        self.annotateEqual([('rev1', 'a\n'), ('rev2', 'a\n')], [parent],
493
                           new_text, 'rev2', blocks)
494
        blocks = [(0, 1, 1), (1, 2, 0)]
495
        self.annotateEqual([('rev2', 'a\n'), ('rev1', 'a\n')], [parent],
496
                           new_text, 'rev2', blocks)