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