/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

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