/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_annotate.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
19
19
import codecs
20
 
from cStringIO import StringIO
21
20
 
22
 
from bzrlib import (
 
21
from .. import (
23
22
    annotate,
24
 
    conflicts,
25
 
    errors,
26
23
    tests,
27
 
    trace,
28
 
    )
 
24
    )
 
25
from ..sixish import (
 
26
    BytesIO,
 
27
    )
 
28
from .ui_testing import StringIOWithEncoding
29
29
 
30
30
 
31
31
def annotation(text):
32
 
    return [tuple(l.split(' ', 1)) for l in text.splitlines(True)]
33
 
 
34
 
 
35
 
parent_1 = annotation("""\
 
32
    return [tuple(l.split(b' ', 1)) for l in text.splitlines(True)]
 
33
 
 
34
 
 
35
parent_1 = annotation(b"""\
36
36
rev1 a
37
37
rev2 b
38
38
rev3 c
41
41
""")
42
42
 
43
43
 
44
 
parent_2 = annotation("""\
 
44
parent_2 = annotation(b"""\
45
45
rev1 a
46
46
rev3 c
47
47
rev4 d
51
51
""")
52
52
 
53
53
 
54
 
expected_2_1 = annotation("""\
 
54
expected_2_1 = annotation(b"""\
55
55
rev1 a
56
56
blahblah b
57
57
rev3 c
68
68
# f: in 2, but not in new, so ignored
69
69
# g: not in 1 or 2, so it goes to blahblah
70
70
# h: only in parent 2, so 2 gets it
71
 
expected_1_2_2 = annotation("""\
 
71
expected_1_2_2 = annotation(b"""\
72
72
rev1 a
73
73
rev2 b
74
74
rev3 c
79
79
""")
80
80
 
81
81
 
82
 
new_1 = """\
 
82
new_1 = b"""\
83
83
a
84
84
b
85
85
c
87
87
e
88
88
""".splitlines(True)
89
89
 
90
 
expected_1 = annotation("""\
 
90
expected_1 = annotation(b"""\
91
91
blahblah a
92
92
blahblah b
93
93
blahblah c
96
96
""")
97
97
 
98
98
 
99
 
new_2 = """\
 
99
new_2 = b"""\
100
100
a
101
101
b
102
102
c
120
120
#  |/
121
121
#  E    # D should supersede A and stay as D (not become E because C references
122
122
#         A)
123
 
duplicate_base = annotation("""\
 
123
duplicate_base = annotation(b"""\
124
124
rev-base first
125
125
rev-base second
126
126
rev-base third
127
127
rev-base fourth-base
128
128
""")
129
129
 
130
 
duplicate_A = annotation("""\
 
130
duplicate_A = annotation(b"""\
131
131
rev-base first
132
132
rev-A alt-second
133
133
rev-base third
134
134
rev-A fourth-A
135
135
""")
136
136
 
137
 
duplicate_B = annotation("""\
 
137
duplicate_B = annotation(b"""\
138
138
rev-base first
139
139
rev-B alt-second
140
140
rev-base third
141
141
rev-B fourth-B
142
142
""")
143
143
 
144
 
duplicate_C = annotation("""\
 
144
duplicate_C = annotation(b"""\
145
145
rev-base first
146
146
rev-A alt-second
147
147
rev-base third
148
148
rev-C fourth-C
149
149
""")
150
150
 
151
 
duplicate_D = annotation("""\
 
151
duplicate_D = annotation(b"""\
152
152
rev-base first
153
153
rev-A alt-second
154
154
rev-base third
155
155
rev-D fourth-D
156
156
""")
157
157
 
158
 
duplicate_E = annotation("""\
 
158
duplicate_E = annotation(b"""\
159
159
rev-base first
160
160
rev-A alt-second
161
161
rev-base third
179
179
        builder = self.make_branch_builder('branch')
180
180
        builder.start_series()
181
181
        self.addCleanup(builder.finish_series)
182
 
        builder.build_snapshot('rev-1', None, [
183
 
            ('add', ('', 'root-id', 'directory', None)),
184
 
            ('add', ('a', 'a-id', 'file', 'first\n')),
185
 
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com")
186
 
        builder.build_snapshot('rev-2', ['rev-1'], [
187
 
            ('modify', ('a-id', 'first\nsecond\n')),
188
 
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com")
189
 
        builder.build_snapshot('rev-1_1_1', ['rev-1'], [
190
 
            ('modify', ('a-id', 'first\nthird\n')),
191
 
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com")
192
 
        builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
193
 
            ('modify', ('a-id', 'first\nsecond\nthird\n')),
194
 
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com")
 
182
        builder.build_snapshot(None, [
 
183
            ('add', ('', b'root-id', 'directory', None)),
 
184
            ('add', ('a', b'a-id', 'file', 'first\n')),
 
185
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com",
 
186
            revision_id=b'rev-1')
 
187
        builder.build_snapshot([b'rev-1'], [
 
188
            ('modify', ('a', b'first\nsecond\n')),
 
189
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com",
 
190
            revision_id=b'rev-2')
 
191
        builder.build_snapshot([b'rev-1'], [
 
192
            ('modify', ('a', b'first\nthird\n')),
 
193
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com",
 
194
            revision_id=b'rev-1_1_1')
 
195
        builder.build_snapshot([b'rev-2', b'rev-1_1_1'], [
 
196
            ('modify', ('a', b'first\nsecond\nthird\n')),
 
197
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com",
 
198
            revision_id=b'rev-3')
195
199
        return builder
196
200
 
197
201
    def create_deeply_merged_trees(self):
218
222
        rev-6
219
223
        """
220
224
        builder = self.create_merged_trees()
221
 
        builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
222
 
        builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
223
 
        builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
224
 
            ('modify', ('a-id', 'first\nthird\nfourth\n')),
225
 
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com")
226
 
        builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
227
 
            timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
228
 
        builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
229
 
            ('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
230
 
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
231
 
        builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
232
 
            ('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
233
 
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com")
234
 
        builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
235
 
            ('modify', ('a-id',
236
 
                        'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
237
 
            ])
 
225
        builder.build_snapshot([b'rev-1_1_1'], [], revision_id=b'rev-1_1_2')
 
226
        builder.build_snapshot([b'rev-3', b'rev-1_1_2'], [], revision_id=b'rev-4')
 
227
        builder.build_snapshot([b'rev-1_1_1'], [
 
228
            ('modify', ('a', b'first\nthird\nfourth\n')),
 
229
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com",
 
230
            revision_id=b'rev-1_2_1')
 
231
        builder.build_snapshot([b'rev-1_2_1'], [],
 
232
            timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
 
233
            revision_id=b'rev-1_2_2')
 
234
        builder.build_snapshot([b'rev-4', b'rev-1_2_2'], [
 
235
            ('modify', ('a', b'first\nsecond\nthird\nfourth\n')),
 
236
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com",
 
237
            revision_id=b'rev-5')
 
238
        builder.build_snapshot([b'rev-1_2_1'], [
 
239
            ('modify', ('a', b'first\nthird\nfourth\nfifth\nsixth\n')),
 
240
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com",
 
241
            revision_id=b'rev-1_3_1')
 
242
        builder.build_snapshot([b'rev-5', b'rev-1_3_1'], [
 
243
            ('modify', ('a',
 
244
                        b'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
 
245
            ], revision_id=b'rev-6')
238
246
        return builder
239
247
 
240
248
    def create_duplicate_lines_tree(self):
241
249
        builder = self.make_branch_builder('branch')
242
250
        builder.start_series()
243
251
        self.addCleanup(builder.finish_series)
244
 
        base_text = ''.join(l for r, l in duplicate_base)
245
 
        a_text = ''.join(l for r, l in duplicate_A)
246
 
        b_text = ''.join(l for r, l in duplicate_B)
247
 
        c_text = ''.join(l for r, l in duplicate_C)
248
 
        d_text = ''.join(l for r, l in duplicate_D)
249
 
        e_text = ''.join(l for r, l in duplicate_E)
250
 
        builder.build_snapshot('rev-base', None, [
251
 
            ('add', ('', 'root-id', 'directory', None)),
252
 
            ('add', ('file', 'file-id', 'file', base_text)),
253
 
            ])
254
 
        builder.build_snapshot('rev-A', ['rev-base'], [
255
 
            ('modify', ('file-id', a_text))])
256
 
        builder.build_snapshot('rev-B', ['rev-base'], [
257
 
            ('modify', ('file-id', b_text))])
258
 
        builder.build_snapshot('rev-C', ['rev-A'], [
259
 
            ('modify', ('file-id', c_text))])
260
 
        builder.build_snapshot('rev-D', ['rev-B', 'rev-A'], [
261
 
            ('modify', ('file-id', d_text))])
262
 
        builder.build_snapshot('rev-E', ['rev-C', 'rev-D'], [
263
 
            ('modify', ('file-id', e_text))])
 
252
        base_text = b''.join(l for r, l in duplicate_base)
 
253
        a_text = b''.join(l for r, l in duplicate_A)
 
254
        b_text = b''.join(l for r, l in duplicate_B)
 
255
        c_text = b''.join(l for r, l in duplicate_C)
 
256
        d_text = b''.join(l for r, l in duplicate_D)
 
257
        e_text = b''.join(l for r, l in duplicate_E)
 
258
        builder.build_snapshot(None, [
 
259
            ('add', ('', b'root-id', 'directory', None)),
 
260
            ('add', ('file', b'file-id', 'file', base_text)),
 
261
            ], revision_id=b'rev-base')
 
262
        builder.build_snapshot([b'rev-base'], [
 
263
            ('modify', ('file', a_text))],
 
264
            revision_id=b'rev-A')
 
265
        builder.build_snapshot([b'rev-base'], [
 
266
            ('modify', ('file', b_text))],
 
267
            revision_id=b'rev-B')
 
268
        builder.build_snapshot([b'rev-A'], [
 
269
            ('modify', ('file', c_text))],
 
270
            revision_id=b'rev-C')
 
271
        builder.build_snapshot([b'rev-B', b'rev-A'], [
 
272
            ('modify', ('file', d_text))],
 
273
            revision_id=b'rev-D')
 
274
        builder.build_snapshot([b'rev-C', b'rev-D'], [
 
275
            ('modify', ('file', e_text))],
 
276
            revision_id=b'rev-E')
264
277
        return builder
265
278
 
266
 
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
267
 
        """Assert that the revision is properly annotated."""
268
 
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
279
    def assertAnnotateEqualDiff(self, actual, expected):
269
280
        if actual != expected:
270
281
            # Create an easier to understand diff when the lines don't actually
271
282
            # match
272
 
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
273
 
                                 ''.join('\t'.join(l) for l in actual))
 
283
            self.assertEqualDiff(b''.join('\t'.join(l) for l in expected),
 
284
                                 b''.join('\t'.join(l) for l in actual))
 
285
 
 
286
    def assertBranchAnnotate(self, expected, branch, path, revision_id,
 
287
            verbose=False, full=False, show_ids=False):
 
288
        tree = branch.repository.revision_tree(revision_id)
 
289
        to_file = BytesIO()
 
290
        annotate.annotate_file_tree(tree, path, to_file,
 
291
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
292
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
 
293
 
 
294
    def assertRepoAnnotate(self, expected, repo, path, revision_id):
 
295
        """Assert that the revision is properly annotated."""
 
296
        actual = list(repo.revision_tree(revision_id).annotate_iter(path))
 
297
        self.assertAnnotateEqualDiff(actual, expected)
274
298
 
275
299
    def test_annotate_duplicate_lines(self):
276
300
        # XXX: Should this be a per_repository test?
278
302
        repo = builder.get_branch().repository
279
303
        repo.lock_read()
280
304
        self.addCleanup(repo.unlock)
281
 
        self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
282
 
        self.assertRepoAnnotate(duplicate_A, repo, 'file-id', 'rev-A')
283
 
        self.assertRepoAnnotate(duplicate_B, repo, 'file-id', 'rev-B')
284
 
        self.assertRepoAnnotate(duplicate_C, repo, 'file-id', 'rev-C')
285
 
        self.assertRepoAnnotate(duplicate_D, repo, 'file-id', 'rev-D')
286
 
        self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
 
305
        self.assertRepoAnnotate(duplicate_base, repo, 'file', b'rev-base')
 
306
        self.assertRepoAnnotate(duplicate_A, repo, 'file', b'rev-A')
 
307
        self.assertRepoAnnotate(duplicate_B, repo, 'file', b'rev-B')
 
308
        self.assertRepoAnnotate(duplicate_C, repo, 'file', b'rev-C')
 
309
        self.assertRepoAnnotate(duplicate_D, repo, 'file', b'rev-D')
 
310
        self.assertRepoAnnotate(duplicate_E, repo, 'file', b'rev-E')
287
311
 
288
312
    def test_annotate_shows_dotted_revnos(self):
289
313
        builder = self.create_merged_trees()
290
314
 
291
 
        sio = StringIO()
292
 
        annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
293
 
                               to_file=sio)
294
 
        self.assertEqualDiff('1     joe@foo | first\n'
295
 
                             '2     joe@foo | second\n'
296
 
                             '1.1.1 barry@f | third\n',
297
 
                             sio.getvalue())
 
315
        self.assertBranchAnnotate(b'1     joe@foo | first\n'
 
316
                                  b'2     joe@foo | second\n'
 
317
                                  b'1.1.1 barry@f | third\n',
 
318
                                  builder.get_branch(), 'a', b'rev-3')
298
319
 
299
320
    def test_annotate_limits_dotted_revnos(self):
300
321
        """Annotate should limit dotted revnos to a depth of 12"""
301
322
        builder = self.create_deeply_merged_trees()
302
323
 
303
 
        sio = StringIO()
304
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
305
 
                               to_file=sio, verbose=False, full=False)
306
 
        self.assertEqualDiff('1     joe@foo | first\n'
307
 
                             '2     joe@foo | second\n'
308
 
                             '1.1.1 barry@f | third\n'
309
 
                             '1.2.1 jerry@f | fourth\n'
310
 
                             '1.3.1 george@ | fifth\n'
311
 
                             '              | sixth\n',
312
 
                             sio.getvalue())
 
324
        self.assertBranchAnnotate(b'1     joe@foo | first\n'
 
325
                                  b'2     joe@foo | second\n'
 
326
                                  b'1.1.1 barry@f | third\n'
 
327
                                  b'1.2.1 jerry@f | fourth\n'
 
328
                                  b'1.3.1 george@ | fifth\n'
 
329
                                  b'              | sixth\n',
 
330
                                  builder.get_branch(), 'a', b'rev-6',
 
331
                                  verbose=False, full=False)
313
332
 
314
 
        sio = StringIO()
315
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
316
 
                               to_file=sio, verbose=False, full=True)
317
 
        self.assertEqualDiff('1     joe@foo | first\n'
318
 
                             '2     joe@foo | second\n'
319
 
                             '1.1.1 barry@f | third\n'
320
 
                             '1.2.1 jerry@f | fourth\n'
321
 
                             '1.3.1 george@ | fifth\n'
322
 
                             '1.3.1 george@ | sixth\n',
323
 
                             sio.getvalue())
 
333
        self.assertBranchAnnotate(b'1     joe@foo | first\n'
 
334
                                  b'2     joe@foo | second\n'
 
335
                                  b'1.1.1 barry@f | third\n'
 
336
                                  b'1.2.1 jerry@f | fourth\n'
 
337
                                  b'1.3.1 george@ | fifth\n'
 
338
                                  b'1.3.1 george@ | sixth\n',
 
339
                                  builder.get_branch(), 'a', b'rev-6',
 
340
                                  verbose=False, full=True)
324
341
 
325
342
        # verbose=True shows everything, the full revno, user id, and date
326
 
        sio = StringIO()
327
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
328
 
                               to_file=sio, verbose=True, full=False)
329
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
330
 
                             '2     joe@foo.com    20061213 | second\n'
331
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
332
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
333
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
334
 
                             '                              | sixth\n',
335
 
                             sio.getvalue())
 
343
        self.assertBranchAnnotate(b'1     joe@foo.com    20061213 | first\n'
 
344
                                  b'2     joe@foo.com    20061213 | second\n'
 
345
                                  b'1.1.1 barry@foo.com  20061213 | third\n'
 
346
                                  b'1.2.1 jerry@foo.com  20061213 | fourth\n'
 
347
                                  b'1.3.1 george@foo.com 20061213 | fifth\n'
 
348
                                  b'                              | sixth\n',
 
349
                                  builder.get_branch(), 'a', b'rev-6',
 
350
                                  verbose=True, full=False)
336
351
 
337
 
        sio = StringIO()
338
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
339
 
                               to_file=sio, verbose=True, full=True)
340
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
341
 
                             '2     joe@foo.com    20061213 | second\n'
342
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
343
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
344
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
345
 
                             '1.3.1 george@foo.com 20061213 | sixth\n',
346
 
                             sio.getvalue())
 
352
        self.assertBranchAnnotate(b'1     joe@foo.com    20061213 | first\n'
 
353
                                  b'2     joe@foo.com    20061213 | second\n'
 
354
                                  b'1.1.1 barry@foo.com  20061213 | third\n'
 
355
                                  b'1.2.1 jerry@foo.com  20061213 | fourth\n'
 
356
                                  b'1.3.1 george@foo.com 20061213 | fifth\n'
 
357
                                  b'1.3.1 george@foo.com 20061213 | sixth\n',
 
358
                                  builder.get_branch(), 'a', b'rev-6',
 
359
                                  verbose=True, full=True)
347
360
 
348
361
    def test_annotate_uses_branch_context(self):
349
362
        """Dotted revnos should use the Branch context.
353
366
        """
354
367
        builder = self.create_deeply_merged_trees()
355
368
 
356
 
        sio = StringIO()
357
 
        annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
358
 
                               to_file=sio, verbose=False, full=False)
359
 
        self.assertEqualDiff('1     joe@foo | first\n'
360
 
                             '1.1.1 barry@f | third\n'
361
 
                             '1.2.1 jerry@f | fourth\n'
362
 
                             '1.3.1 george@ | fifth\n'
363
 
                             '              | sixth\n',
364
 
                             sio.getvalue())
 
369
        self.assertBranchAnnotate(b'1     joe@foo | first\n'
 
370
                                  b'1.1.1 barry@f | third\n'
 
371
                                  b'1.2.1 jerry@f | fourth\n'
 
372
                                  b'1.3.1 george@ | fifth\n'
 
373
                                  b'              | sixth\n',
 
374
                                  builder.get_branch(), 'a', b'rev-1_3_1',
 
375
                                  verbose=False, full=False)
365
376
 
366
377
    def test_annotate_show_ids(self):
367
378
        builder = self.create_deeply_merged_trees()
368
379
 
369
 
        sio = StringIO()
370
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
371
 
                               to_file=sio, show_ids=True, full=False)
372
 
 
373
380
        # It looks better with real revision ids :)
374
 
        self.assertEqualDiff('    rev-1 | first\n'
375
 
                             '    rev-2 | second\n'
376
 
                             'rev-1_1_1 | third\n'
377
 
                             'rev-1_2_1 | fourth\n'
378
 
                             'rev-1_3_1 | fifth\n'
379
 
                             '          | sixth\n',
380
 
                             sio.getvalue())
381
 
 
382
 
        sio = StringIO()
383
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
384
 
                               to_file=sio, show_ids=True, full=True)
385
 
 
386
 
        self.assertEqualDiff('    rev-1 | first\n'
387
 
                             '    rev-2 | second\n'
388
 
                             'rev-1_1_1 | third\n'
389
 
                             'rev-1_2_1 | fourth\n'
390
 
                             'rev-1_3_1 | fifth\n'
391
 
                             'rev-1_3_1 | sixth\n',
392
 
                             sio.getvalue())
 
381
        self.assertBranchAnnotate(b'    rev-1 | first\n'
 
382
                                  b'    rev-2 | second\n'
 
383
                                  b'rev-1_1_1 | third\n'
 
384
                                  b'rev-1_2_1 | fourth\n'
 
385
                                  b'rev-1_3_1 | fifth\n'
 
386
                                  b'          | sixth\n',
 
387
                                  builder.get_branch(), 'a', b'rev-6',
 
388
                                  show_ids=True, full=False)
 
389
 
 
390
        self.assertBranchAnnotate(b'    rev-1 | first\n'
 
391
                                  b'    rev-2 | second\n'
 
392
                                  b'rev-1_1_1 | third\n'
 
393
                                  b'rev-1_2_1 | fourth\n'
 
394
                                  b'rev-1_3_1 | fifth\n'
 
395
                                  b'rev-1_3_1 | sixth\n',
 
396
                                  builder.get_branch(), 'a', b'rev-6',
 
397
                                  show_ids=True, full=True)
393
398
 
394
399
    def test_annotate_unicode_author(self):
395
400
        tree1 = self.make_branch_and_tree('tree1')
396
401
 
397
 
        self.build_tree_contents([('tree1/a', 'adi\xc3\xb3s')])
398
 
        tree1.add(['a'], ['a-id'])
399
 
        tree1.commit('a', rev_id='rev-1',
 
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',
400
405
                     committer=u'Pepe P\xe9rez <pperez@ejemplo.com>',
401
406
                     timestamp=1166046000.00, timezone=0)
402
407
 
403
 
        self.build_tree_contents([('tree1/b', 'bye')])
404
 
        tree1.add(['b'], ['b-id'])
405
 
        tree1.commit('b', rev_id='rev-2',
 
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',
406
411
                     committer=u'p\xe9rez',
407
412
                     timestamp=1166046000.00, timezone=0)
408
413
 
409
414
        tree1.lock_read()
410
415
        self.addCleanup(tree1.unlock)
 
416
 
 
417
        revtree_1 = tree1.branch.repository.revision_tree(b'rev-1')
 
418
        revtree_2 = tree1.branch.repository.revision_tree(b'rev-2')
 
419
 
411
420
        # this passes if no exception is raised
412
 
        to_file = StringIO()
413
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
414
 
 
415
 
        sio = StringIO()
416
 
        to_file = codecs.getwriter('ascii')(sio)
417
 
        to_file.encoding = 'ascii' # codecs does not set it
418
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
419
 
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
420
 
 
421
 
        # test now with to_file.encoding = None
422
 
        to_file = tests.StringIOWrapper()
423
 
        to_file.encoding = None
424
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
425
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
426
 
 
427
 
        # and when it does not exist
428
 
        to_file = StringIO()
429
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
430
 
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
 
421
        to_file = BytesIO()
 
422
        annotate.annotate_file_tree(revtree_1, 'a',
 
423
            to_file=to_file, branch=tree1.branch)
 
424
 
 
425
        sio = BytesIO()
 
426
        to_file = codecs.getwriter('ascii')(sio, 'replace')
 
427
        annotate.annotate_file_tree(revtree_2, 'b',
 
428
            to_file=to_file, branch=tree1.branch)
 
429
        self.assertEqualDiff(b'2   p?rez   | bye\n', sio.getvalue())
 
430
 
 
431
        # test now with unicode file-like
 
432
        to_file = StringIOWithEncoding()
 
433
        annotate.annotate_file_tree(revtree_2, 'b',
 
434
            to_file=to_file, branch=tree1.branch)
 
435
        self.assertContainsRe(u'2   p\xe9rez   | bye\n', to_file.getvalue())
431
436
 
432
437
    def test_annotate_author_or_committer(self):
433
438
        tree1 = self.make_branch_and_tree('tree1')
434
439
 
435
 
        self.build_tree_contents([('tree1/a', 'hello')])
436
 
        tree1.add(['a'], ['a-id'])
437
 
        tree1.commit('a', rev_id='rev-1',
 
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',
438
443
                     committer='Committer <committer@example.com>',
439
444
                     timestamp=1166046000.00, timezone=0)
440
445
 
441
 
        self.build_tree_contents([('tree1/b', 'bye')])
442
 
        tree1.add(['b'], ['b-id'])
443
 
        tree1.commit('b', rev_id='rev-2',
 
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',
444
449
                     committer='Committer <committer@example.com>',
445
450
                     authors=['Author <author@example.com>'],
446
451
                     timestamp=1166046000.00, timezone=0)
447
452
 
448
453
        tree1.lock_read()
449
454
        self.addCleanup(tree1.unlock)
450
 
        to_file = StringIO()
451
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
452
 
        self.assertEqual('1   committ | hello\n', to_file.getvalue())
453
 
 
454
 
        to_file = StringIO()
455
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
456
 
        self.assertEqual('2   author@ | bye\n', to_file.getvalue())
 
455
 
 
456
        self.assertBranchAnnotate(b'1   committ | hello\n', tree1.branch,
 
457
            'a', b'rev-1')
 
458
 
 
459
        to_file = BytesIO()
 
460
        self.assertBranchAnnotate(b'2   author@ | bye\n', tree1.branch,
 
461
            'b', b'rev-2')
457
462
 
458
463
 
459
464
class TestReannotate(tests.TestCase):
467
472
            self.assertEqual(e, a)
468
473
 
469
474
    def test_reannotate(self):
470
 
        self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
471
 
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
 
475
        self.annotateEqual(parent_1, [parent_1], new_1, b'blahblah')
 
476
        self.annotateEqual(expected_2_1, [parent_2], new_1, b'blahblah')
472
477
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,
473
 
                           'blahblah')
 
478
                           b'blahblah')
474
479
 
475
480
    def test_reannotate_no_parents(self):
476
 
        self.annotateEqual(expected_1, [], new_1, 'blahblah')
 
481
        self.annotateEqual(expected_1, [], new_1, b'blahblah')
477
482
 
478
483
    def test_reannotate_left_matching_blocks(self):
479
484
        """Ensure that left_matching_blocks has an impact.
481
486
        In this case, the annotation is ambiguous, so the hint isn't actually
482
487
        lying.
483
488
        """
484
 
        parent = [('rev1', 'a\n')]
485
 
        new_text = ['a\n', 'a\n']
 
489
        parent = [(b'rev1', b'a\n')]
 
490
        new_text = [b'a\n', b'a\n']
486
491
        blocks = [(0, 0, 1), (1, 2, 0)]
487
 
        self.annotateEqual([('rev1', 'a\n'), ('rev2', 'a\n')], [parent],
488
 
                           new_text, 'rev2', blocks)
 
492
        self.annotateEqual([(b'rev1', b'a\n'), (b'rev2', b'a\n')], [parent],
 
493
                           new_text, b'rev2', blocks)
489
494
        blocks = [(0, 1, 1), (1, 2, 0)]
490
 
        self.annotateEqual([('rev2', 'a\n'), ('rev1', 'a\n')], [parent],
491
 
                           new_text, 'rev2', blocks)
 
495
        self.annotateEqual([(b'rev2', b'a\n'), (b'rev1', b'a\n')], [parent],
 
496
                           new_text, b'rev2', blocks)