~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

resolve conflicts against trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    annotate,
 
24
    symbol_versioning,
24
25
    tests,
25
26
    )
26
27
 
260
261
            ('modify', ('file-id', e_text))])
261
262
        return builder
262
263
 
263
 
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
264
 
        """Assert that the revision is properly annotated."""
265
 
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
264
    def assertAnnotateEqualDiff(self, actual, expected):
266
265
        if actual != expected:
267
266
            # Create an easier to understand diff when the lines don't actually
268
267
            # match
269
268
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
270
269
                                 ''.join('\t'.join(l) for l in actual))
271
270
 
 
271
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
 
272
            verbose=False, full=False, show_ids=False):
 
273
        tree = branch.repository.revision_tree(revision_id)
 
274
        to_file = StringIO()
 
275
        annotate.annotate_file_tree(tree, file_id, to_file,
 
276
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
277
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
 
278
 
 
279
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
280
        """Assert that the revision is properly annotated."""
 
281
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
282
        self.assertAnnotateEqualDiff(actual, expected)
 
283
 
272
284
    def test_annotate_duplicate_lines(self):
273
285
        # XXX: Should this be a per_repository test?
274
286
        builder = self.create_duplicate_lines_tree()
285
297
    def test_annotate_shows_dotted_revnos(self):
286
298
        builder = self.create_merged_trees()
287
299
 
288
 
        sio = StringIO()
289
 
        annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
290
 
                               to_file=sio)
291
 
        self.assertEqualDiff('1     joe@foo | first\n'
292
 
                             '2     joe@foo | second\n'
293
 
                             '1.1.1 barry@f | third\n',
294
 
                             sio.getvalue())
 
300
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
301
                                  '2     joe@foo | second\n'
 
302
                                  '1.1.1 barry@f | third\n',
 
303
                                  builder.get_branch(), 'a-id', 'rev-3')
 
304
 
 
305
    def test_annotate_file(self):
 
306
        builder = self.create_merged_trees()
 
307
 
 
308
        to_file = StringIO()
 
309
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
310
            annotate.annotate_file, builder.get_branch(),
 
311
                'rev-3', 'a-id', to_file=to_file)
 
312
 
 
313
        self.assertAnnotateEqualDiff('1     joe@foo | first\n'
 
314
                                     '2     joe@foo | second\n'
 
315
                                     '1.1.1 barry@f | third\n',
 
316
                                     to_file.getvalue())
295
317
 
296
318
    def test_annotate_limits_dotted_revnos(self):
297
319
        """Annotate should limit dotted revnos to a depth of 12"""
298
320
        builder = self.create_deeply_merged_trees()
299
321
 
300
 
        sio = StringIO()
301
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
302
 
                               to_file=sio, verbose=False, full=False)
303
 
        self.assertEqualDiff('1     joe@foo | first\n'
304
 
                             '2     joe@foo | second\n'
305
 
                             '1.1.1 barry@f | third\n'
306
 
                             '1.2.1 jerry@f | fourth\n'
307
 
                             '1.3.1 george@ | fifth\n'
308
 
                             '              | sixth\n',
309
 
                             sio.getvalue())
 
322
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
323
                                  '2     joe@foo | second\n'
 
324
                                  '1.1.1 barry@f | third\n'
 
325
                                  '1.2.1 jerry@f | fourth\n'
 
326
                                  '1.3.1 george@ | fifth\n'
 
327
                                  '              | sixth\n',
 
328
                                  builder.get_branch(), 'a-id', 'rev-6',
 
329
                                  verbose=False, full=False)
310
330
 
311
 
        sio = StringIO()
312
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
313
 
                               to_file=sio, verbose=False, full=True)
314
 
        self.assertEqualDiff('1     joe@foo | first\n'
315
 
                             '2     joe@foo | second\n'
316
 
                             '1.1.1 barry@f | third\n'
317
 
                             '1.2.1 jerry@f | fourth\n'
318
 
                             '1.3.1 george@ | fifth\n'
319
 
                             '1.3.1 george@ | sixth\n',
320
 
                             sio.getvalue())
 
331
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
332
                                  '2     joe@foo | second\n'
 
333
                                  '1.1.1 barry@f | third\n'
 
334
                                  '1.2.1 jerry@f | fourth\n'
 
335
                                  '1.3.1 george@ | fifth\n'
 
336
                                  '1.3.1 george@ | sixth\n',
 
337
                                  builder.get_branch(), 'a-id', 'rev-6',
 
338
                                  verbose=False, full=True)
321
339
 
322
340
        # verbose=True shows everything, the full revno, user id, and date
323
 
        sio = StringIO()
324
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
325
 
                               to_file=sio, verbose=True, full=False)
326
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
327
 
                             '2     joe@foo.com    20061213 | second\n'
328
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
329
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
330
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
331
 
                             '                              | sixth\n',
332
 
                             sio.getvalue())
 
341
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
342
                                  '2     joe@foo.com    20061213 | second\n'
 
343
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
344
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
345
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
346
                                  '                              | sixth\n',
 
347
                                  builder.get_branch(), 'a-id', 'rev-6',
 
348
                                  verbose=True, full=False)
333
349
 
334
 
        sio = StringIO()
335
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
336
 
                               to_file=sio, verbose=True, full=True)
337
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
338
 
                             '2     joe@foo.com    20061213 | second\n'
339
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
340
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
341
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
342
 
                             '1.3.1 george@foo.com 20061213 | sixth\n',
343
 
                             sio.getvalue())
 
350
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
351
                                  '2     joe@foo.com    20061213 | second\n'
 
352
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
353
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
354
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
355
                                  '1.3.1 george@foo.com 20061213 | sixth\n',
 
356
                                  builder.get_branch(), 'a-id', 'rev-6',
 
357
                                  verbose=True, full=True)
344
358
 
345
359
    def test_annotate_uses_branch_context(self):
346
360
        """Dotted revnos should use the Branch context.
350
364
        """
351
365
        builder = self.create_deeply_merged_trees()
352
366
 
353
 
        sio = StringIO()
354
 
        annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
355
 
                               to_file=sio, verbose=False, full=False)
356
 
        self.assertEqualDiff('1     joe@foo | first\n'
357
 
                             '1.1.1 barry@f | third\n'
358
 
                             '1.2.1 jerry@f | fourth\n'
359
 
                             '1.3.1 george@ | fifth\n'
360
 
                             '              | sixth\n',
361
 
                             sio.getvalue())
 
367
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
368
                                  '1.1.1 barry@f | third\n'
 
369
                                  '1.2.1 jerry@f | fourth\n'
 
370
                                  '1.3.1 george@ | fifth\n'
 
371
                                  '              | sixth\n',
 
372
                                  builder.get_branch(), 'a-id', 'rev-1_3_1',
 
373
                                  verbose=False, full=False)
362
374
 
363
375
    def test_annotate_show_ids(self):
364
376
        builder = self.create_deeply_merged_trees()
365
377
 
366
 
        sio = StringIO()
367
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
368
 
                               to_file=sio, show_ids=True, full=False)
369
 
 
370
378
        # It looks better with real revision ids :)
371
 
        self.assertEqualDiff('    rev-1 | first\n'
372
 
                             '    rev-2 | second\n'
373
 
                             'rev-1_1_1 | third\n'
374
 
                             'rev-1_2_1 | fourth\n'
375
 
                             'rev-1_3_1 | fifth\n'
376
 
                             '          | sixth\n',
377
 
                             sio.getvalue())
378
 
 
379
 
        sio = StringIO()
380
 
        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
381
 
                               to_file=sio, show_ids=True, full=True)
382
 
 
383
 
        self.assertEqualDiff('    rev-1 | first\n'
384
 
                             '    rev-2 | second\n'
385
 
                             'rev-1_1_1 | third\n'
386
 
                             'rev-1_2_1 | fourth\n'
387
 
                             'rev-1_3_1 | fifth\n'
388
 
                             'rev-1_3_1 | sixth\n',
389
 
                             sio.getvalue())
 
379
        self.assertBranchAnnotate('    rev-1 | first\n'
 
380
                                  '    rev-2 | second\n'
 
381
                                  'rev-1_1_1 | third\n'
 
382
                                  'rev-1_2_1 | fourth\n'
 
383
                                  'rev-1_3_1 | fifth\n'
 
384
                                  '          | sixth\n',
 
385
                                  builder.get_branch(), 'a-id', 'rev-6',
 
386
                                  show_ids=True, full=False)
 
387
 
 
388
        self.assertBranchAnnotate('    rev-1 | first\n'
 
389
                                  '    rev-2 | second\n'
 
390
                                  'rev-1_1_1 | third\n'
 
391
                                  'rev-1_2_1 | fourth\n'
 
392
                                  'rev-1_3_1 | fifth\n'
 
393
                                  'rev-1_3_1 | sixth\n',
 
394
                                  builder.get_branch(), 'a-id', 'rev-6',
 
395
                                  show_ids=True, full=True)
390
396
 
391
397
    def test_annotate_unicode_author(self):
392
398
        tree1 = self.make_branch_and_tree('tree1')
405
411
 
406
412
        tree1.lock_read()
407
413
        self.addCleanup(tree1.unlock)
 
414
 
 
415
        revtree_1 = tree1.branch.repository.revision_tree('rev-1')
 
416
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
 
417
 
408
418
        # this passes if no exception is raised
409
419
        to_file = StringIO()
410
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
420
        annotate.annotate_file_tree(revtree_1, 'a-id',
 
421
            to_file=to_file, branch=tree1.branch)
411
422
 
412
423
        sio = StringIO()
413
424
        to_file = codecs.getwriter('ascii')(sio)
414
425
        to_file.encoding = 'ascii' # codecs does not set it
415
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
426
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
427
            to_file=to_file, branch=tree1.branch)
416
428
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
417
429
 
418
430
        # test now with to_file.encoding = None
419
431
        to_file = tests.StringIOWrapper()
420
432
        to_file.encoding = None
421
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
433
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
434
            to_file=to_file, branch=tree1.branch)
422
435
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
423
436
 
424
437
        # and when it does not exist
425
438
        to_file = StringIO()
426
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
439
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
440
            to_file=to_file, branch=tree1.branch)
427
441
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
428
442
 
429
443
    def test_annotate_author_or_committer(self):
444
458
 
445
459
        tree1.lock_read()
446
460
        self.addCleanup(tree1.unlock)
447
 
        to_file = StringIO()
448
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
449
 
        self.assertEqual('1   committ | hello\n', to_file.getvalue())
450
 
 
451
 
        to_file = StringIO()
452
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
453
 
        self.assertEqual('2   author@ | bye\n', to_file.getvalue())
 
461
 
 
462
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
 
463
            'a-id', 'rev-1')
 
464
 
 
465
        to_file = StringIO()
 
466
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
 
467
            'b-id', 'rev-2')
454
468
 
455
469
 
456
470
class TestReannotate(tests.TestCase):