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