~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Gordon Tyler
  • Date: 2010-01-14 15:24:04 UTC
  • mto: (5037.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5046.
  • Revision ID: gordon@doxxx.net-20100114152404-d64ik2afl96lcml0
Reverted changes to test_rules since the original should work now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    )
28
28
 
29
29
 
30
 
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
 
30
class TestCaseForLogFormatter(tests.TestCaseWithTransport):
31
31
 
32
32
    def setUp(self):
33
 
        super(TestCaseWithoutPropsHandler, self).setUp()
 
33
        super(TestCaseForLogFormatter, self).setUp()
34
34
        # keep a reference to the "current" custom prop. handler registry
35
35
        self.properties_handler_registry = log.properties_handler_registry
36
36
        # Use a clean registry for log
40
40
            log.properties_handler_registry = self.properties_handler_registry
41
41
        self.addCleanup(restore)
42
42
 
 
43
    def assertFormatterResult(self, result, branch, formatter_class,
 
44
                              formatter_kwargs=None, show_log_kwargs=None,
 
45
                              normalize=False):
 
46
        logfile = self.make_utf8_encoded_stringio()
 
47
        if formatter_kwargs is None:
 
48
            formatter_kwargs = {}
 
49
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
 
50
        if show_log_kwargs is None:
 
51
            show_log_kwargs = {}
 
52
        log.show_log(branch, formatter, **show_log_kwargs)
 
53
        log_content = logfile.getvalue()
 
54
        if normalize:
 
55
            log_content = normalize_log(log_content)
 
56
        self.assertEqualDiff(result, log_content)
 
57
 
 
58
    def make_standard_commit(self, branch_nick, **kwargs):
 
59
        wt = self.make_branch_and_tree('.')
 
60
        wt.lock_write()
 
61
        self.addCleanup(wt.unlock)
 
62
        self.build_tree(['a'])
 
63
        wt.add(['a'])
 
64
        wt.branch.nick = branch_nick
 
65
        kwargs = dict(kwargs)
 
66
        kwargs.setdefault('message', 'add a')
 
67
        kwargs.setdefault('timestamp', 1132711707)
 
68
        kwargs.setdefault('timezone', 36000)
 
69
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
 
70
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
 
71
        wt.commit(**kwargs)
 
72
        return wt
 
73
 
 
74
    def _prepare_tree_with_merges(self, with_tags=False):
 
75
        wt = self.make_branch_and_memory_tree('.')
 
76
        wt.lock_write()
 
77
        self.addCleanup(wt.unlock)
 
78
        wt.add('')
 
79
        wt.commit('rev-1', rev_id='rev-1',
 
80
                  timestamp=1132586655, timezone=36000,
 
81
                  committer='Joe Foo <joe@foo.com>')
 
82
        wt.commit('rev-merged', rev_id='rev-2a',
 
83
                  timestamp=1132586700, timezone=36000,
 
84
                  committer='Joe Foo <joe@foo.com>')
 
85
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
86
        wt.branch.set_last_revision_info(1, 'rev-1')
 
87
        wt.commit('rev-2', rev_id='rev-2b',
 
88
                  timestamp=1132586800, timezone=36000,
 
89
                  committer='Joe Foo <joe@foo.com>')
 
90
        if with_tags:
 
91
            branch = wt.branch
 
92
            branch.tags.set_tag('v0.2', 'rev-2b')
 
93
            wt.commit('rev-3', rev_id='rev-3',
 
94
                      timestamp=1132586900, timezone=36000,
 
95
                      committer='Jane Foo <jane@foo.com>')
 
96
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
97
            branch.tags.set_tag('v1.0', 'rev-3')
 
98
        return wt
 
99
 
 
100
        
 
101
 
43
102
 
44
103
class LogCatcher(log.LogFormatter):
45
104
    """Pull log messages into a list rather than displaying them.
242
301
    return ''.join(lines)
243
302
 
244
303
 
245
 
class TestShortLogFormatter(tests.TestCaseWithTransport):
 
304
class TestShortLogFormatter(TestCaseForLogFormatter):
246
305
 
247
306
    def test_trailing_newlines(self):
248
307
        wt = self.make_branch_and_tree('.')
249
308
        b = make_commits_with_trailing_newlines(wt)
250
 
        sio = self.make_utf8_encoded_stringio()
251
 
        lf = log.ShortLogFormatter(to_file=sio)
252
 
        log.show_log(b, lf)
253
 
        self.assertEqualDiff("""\
 
309
        self.assertFormatterResult("""\
254
310
    3 Joe Foo\t2005-11-21
255
311
      single line with trailing newline
256
312
 
263
319
      simple log message
264
320
 
265
321
""",
266
 
                             sio.getvalue())
267
 
 
268
 
    def _prepare_tree_with_merges(self, with_tags=False):
269
 
        wt = self.make_branch_and_memory_tree('.')
270
 
        wt.lock_write()
271
 
        self.addCleanup(wt.unlock)
272
 
        wt.add('')
273
 
        wt.commit('rev-1', rev_id='rev-1',
274
 
                  timestamp=1132586655, timezone=36000,
275
 
                  committer='Joe Foo <joe@foo.com>')
276
 
        wt.commit('rev-merged', rev_id='rev-2a',
277
 
                  timestamp=1132586700, timezone=36000,
278
 
                  committer='Joe Foo <joe@foo.com>')
279
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
280
 
        wt.branch.set_last_revision_info(1, 'rev-1')
281
 
        wt.commit('rev-2', rev_id='rev-2b',
282
 
                  timestamp=1132586800, timezone=36000,
283
 
                  committer='Joe Foo <joe@foo.com>')
284
 
        if with_tags:
285
 
            branch = wt.branch
286
 
            branch.tags.set_tag('v0.2', 'rev-2b')
287
 
            wt.commit('rev-3', rev_id='rev-3',
288
 
                      timestamp=1132586900, timezone=36000,
289
 
                      committer='Jane Foo <jane@foo.com>')
290
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
291
 
            branch.tags.set_tag('v1.0', 'rev-3')
292
 
        return wt
 
322
            b, log.ShortLogFormatter)
293
323
 
294
324
    def test_short_log_with_merges(self):
295
325
        wt = self._prepare_tree_with_merges()
296
 
        logfile = self.make_utf8_encoded_stringio()
297
 
        formatter = log.ShortLogFormatter(to_file=logfile)
298
 
        log.show_log(wt.branch, formatter)
299
 
        self.assertEqualDiff("""\
 
326
        self.assertFormatterResult("""\
300
327
    2 Joe Foo\t2005-11-22 [merge]
301
328
      rev-2
302
329
 
304
331
      rev-1
305
332
 
306
333
""",
307
 
                             logfile.getvalue())
 
334
            wt.branch, log.ShortLogFormatter)
308
335
 
309
336
    def test_short_log_with_merges_and_advice(self):
310
337
        wt = self._prepare_tree_with_merges()
311
 
        logfile = self.make_utf8_encoded_stringio()
312
 
        formatter = log.ShortLogFormatter(to_file=logfile,
313
 
            show_advice=True)
314
 
        log.show_log(wt.branch, formatter)
315
 
        self.assertEqualDiff("""\
 
338
        self.assertFormatterResult("""\
316
339
    2 Joe Foo\t2005-11-22 [merge]
317
340
      rev-2
318
341
 
321
344
 
322
345
Use --include-merges or -n0 to see merged revisions.
323
346
""",
324
 
                             logfile.getvalue())
 
347
            wt.branch, log.ShortLogFormatter,
 
348
            formatter_kwargs=dict(show_advice=True))
325
349
 
326
350
    def test_short_log_with_merges_and_range(self):
327
351
        wt = self.make_branch_and_memory_tree('.')
347
371
        wt.commit('rev-3b', rev_id='rev-3b',
348
372
                  timestamp=1132586800, timezone=36000,
349
373
                  committer='Joe Foo <joe@foo.com>')
350
 
        logfile = self.make_utf8_encoded_stringio()
351
 
        formatter = log.ShortLogFormatter(to_file=logfile)
352
 
        log.show_log(wt.branch, formatter,
353
 
            start_revision=2, end_revision=3)
354
 
        self.assertEqualDiff("""\
 
374
        self.assertFormatterResult("""\
355
375
    3 Joe Foo\t2005-11-22 [merge]
356
376
      rev-3b
357
377
 
359
379
      rev-2b
360
380
 
361
381
""",
362
 
                             logfile.getvalue())
 
382
            wt.branch, log.ShortLogFormatter,
 
383
            show_log_kwargs=dict(start_revision=2, end_revision=3))
363
384
 
364
385
    def test_short_log_with_tags(self):
365
386
        wt = self._prepare_tree_with_merges(with_tags=True)
366
 
        logfile = self.make_utf8_encoded_stringio()
367
 
        formatter = log.ShortLogFormatter(to_file=logfile)
368
 
        log.show_log(wt.branch, formatter)
369
 
        self.assertEqualDiff("""\
 
387
        self.assertFormatterResult("""\
370
388
    3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
371
389
      rev-3
372
390
 
377
395
      rev-1
378
396
 
379
397
""",
380
 
                             logfile.getvalue())
 
398
            wt.branch, log.ShortLogFormatter)
381
399
 
382
400
    def test_short_log_single_merge_revision(self):
383
401
        wt = self.make_branch_and_memory_tree('.')
395
413
        wt.commit('rev-2', rev_id='rev-2b',
396
414
                  timestamp=1132586800, timezone=36000,
397
415
                  committer='Joe Foo <joe@foo.com>')
398
 
        logfile = self.make_utf8_encoded_stringio()
399
 
        formatter = log.ShortLogFormatter(to_file=logfile)
400
416
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
401
 
        wtb = wt.branch
402
 
        rev = revspec.in_history(wtb)
403
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
404
 
        self.assertEqualDiff("""\
 
417
        rev = revspec.in_history(wt.branch)
 
418
        self.assertFormatterResult("""\
405
419
      1.1.1 Joe Foo\t2005-11-22
406
420
            rev-merged
407
421
 
408
422
""",
409
 
                             logfile.getvalue())
410
 
 
411
 
 
412
 
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
423
            wt.branch, log.ShortLogFormatter,
 
424
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
425
 
 
426
 
 
427
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
413
428
 
414
429
    def test_short_merge_revs_log_with_merges(self):
415
430
        wt = self.make_branch_and_memory_tree('.')
427
442
        wt.commit('rev-2', rev_id='rev-2b',
428
443
                  timestamp=1132586800, timezone=36000,
429
444
                  committer='Joe Foo <joe@foo.com>')
430
 
        logfile = self.make_utf8_encoded_stringio()
431
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
432
 
        log.show_log(wt.branch, formatter)
433
445
        # Note that the 1.1.1 indenting is in fact correct given that
434
446
        # the revision numbers are right justified within 5 characters
435
447
        # for mainline revnos and 9 characters for dotted revnos.
436
 
        self.assertEqualDiff("""\
 
448
        self.assertFormatterResult("""\
437
449
    2 Joe Foo\t2005-11-22 [merge]
438
450
      rev-2
439
451
 
444
456
      rev-1
445
457
 
446
458
""",
447
 
                             logfile.getvalue())
 
459
            wt.branch, log.ShortLogFormatter,
 
460
            formatter_kwargs=dict(levels=0))
448
461
 
449
462
    def test_short_merge_revs_log_single_merge_revision(self):
450
463
        wt = self.make_branch_and_memory_tree('.')
462
475
        wt.commit('rev-2', rev_id='rev-2b',
463
476
                  timestamp=1132586800, timezone=36000,
464
477
                  committer='Joe Foo <joe@foo.com>')
465
 
        logfile = self.make_utf8_encoded_stringio()
466
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
467
478
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
468
 
        wtb = wt.branch
469
 
        rev = revspec.in_history(wtb)
470
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
471
 
        self.assertEqualDiff("""\
 
479
        rev = revspec.in_history(wt.branch)
 
480
        self.assertFormatterResult("""\
472
481
      1.1.1 Joe Foo\t2005-11-22
473
482
            rev-merged
474
483
 
475
484
""",
476
 
                             logfile.getvalue())
477
 
 
478
 
 
479
 
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
 
485
            wt.branch, log.ShortLogFormatter,
 
486
            formatter_kwargs=dict(levels=0),
 
487
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
488
 
 
489
 
 
490
class TestLongLogFormatter(TestCaseForLogFormatter):
480
491
 
481
492
    def test_verbose_log(self):
482
493
        """Verbose log includes changed files
483
494
 
484
495
        bug #4676
485
496
        """
486
 
        wt = self.make_branch_and_tree('.')
487
 
        b = wt.branch
488
 
        self.build_tree(['a'])
489
 
        wt.add('a')
490
 
        # XXX: why does a longer nick show up?
491
 
        b.nick = 'test_verbose_log'
492
 
        wt.commit(message='add a',
493
 
                  timestamp=1132711707,
494
 
                  timezone=36000,
495
 
                  committer='Lorem Ipsum <test@example.com>')
496
 
        logfile = file('out.tmp', 'w+')
497
 
        formatter = log.LongLogFormatter(to_file=logfile)
498
 
        log.show_log(b, formatter, verbose=True)
499
 
        logfile.flush()
500
 
        logfile.seek(0)
501
 
        log_contents = logfile.read()
502
 
        self.assertEqualDiff('''\
 
497
        wt = self.make_standard_commit('test_verbose_log', authors=[])
 
498
        self.assertFormatterResult('''\
503
499
------------------------------------------------------------
504
500
revno: 1
505
501
committer: Lorem Ipsum <test@example.com>
510
506
added:
511
507
  a
512
508
''',
513
 
                             log_contents)
 
509
            wt.branch, log.LongLogFormatter,
 
510
            show_log_kwargs=dict(verbose=True))
514
511
 
515
512
    def test_merges_are_indented_by_level(self):
516
513
        wt = self.make_branch_and_tree('parent')
526
523
        os.chdir('../parent')
527
524
        self.run_bzr('merge ../child')
528
525
        wt.commit('merge branch 1')
529
 
        b = wt.branch
530
 
        sio = self.make_utf8_encoded_stringio()
531
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
532
 
        log.show_log(b, lf, verbose=True)
533
 
        the_log = normalize_log(sio.getvalue())
534
 
        self.assertEqualDiff("""\
 
526
        self.assertFormatterResult("""\
535
527
------------------------------------------------------------
536
528
revno: 2 [merge]
537
529
committer: Lorem Ipsum <test@example.com>
568
560
message:
569
561
  first post
570
562
""",
571
 
                             the_log)
 
563
            wt.branch, log.LongLogFormatter,
 
564
            formatter_kwargs=dict(levels=0),
 
565
            show_log_kwargs=dict(verbose=True),
 
566
            normalize=True)
572
567
 
573
568
    def test_verbose_merge_revisions_contain_deltas(self):
574
569
        wt = self.make_branch_and_tree('parent')
583
578
        os.chdir('parent')
584
579
        self.run_bzr('merge ../child')
585
580
        wt.commit('merge branch 1')
586
 
        b = wt.branch
587
 
        sio = self.make_utf8_encoded_stringio()
588
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
589
 
        log.show_log(b, lf, verbose=True)
590
 
        the_log = normalize_log(sio.getvalue())
591
 
        self.assertEqualDiff("""\
 
581
        self.assertFormatterResult("""\
592
582
------------------------------------------------------------
593
583
revno: 2 [merge]
594
584
committer: Lorem Ipsum <test@example.com>
622
612
  f1
623
613
  f2
624
614
""",
625
 
                             the_log)
 
615
            wt.branch, log.LongLogFormatter,
 
616
            formatter_kwargs=dict(levels=0),
 
617
            show_log_kwargs=dict(verbose=True),
 
618
            normalize=True)
626
619
 
627
620
    def test_trailing_newlines(self):
628
621
        wt = self.make_branch_and_tree('.')
629
622
        b = make_commits_with_trailing_newlines(wt)
630
 
        sio = self.make_utf8_encoded_stringio()
631
 
        lf = log.LongLogFormatter(to_file=sio)
632
 
        log.show_log(b, lf)
633
 
        self.assertEqualDiff("""\
 
623
        self.assertFormatterResult("""\
634
624
------------------------------------------------------------
635
625
revno: 3
636
626
committer: Joe Foo <joe@foo.com>
656
646
message:
657
647
  simple log message
658
648
""",
659
 
                             sio.getvalue())
 
649
        b, log.LongLogFormatter)
660
650
 
661
651
    def test_author_in_log(self):
662
652
        """Log includes the author name if it's set in
663
653
        the revision properties
664
654
        """
665
 
        wt = self.make_branch_and_tree('.')
666
 
        b = wt.branch
667
 
        self.build_tree(['a'])
668
 
        wt.add('a')
669
 
        b.nick = 'test_author_log'
670
 
        wt.commit(message='add a',
671
 
                  timestamp=1132711707,
672
 
                  timezone=36000,
673
 
                  committer='Lorem Ipsum <test@example.com>',
674
 
                  authors=['John Doe <jdoe@example.com>',
675
 
                           'Jane Rey <jrey@example.com>'])
676
 
        sio = StringIO()
677
 
        formatter = log.LongLogFormatter(to_file=sio)
678
 
        log.show_log(b, formatter)
679
 
        self.assertEqualDiff('''\
 
655
        wt = self.make_standard_commit('test_author_log',
 
656
            authors=['John Doe <jdoe@example.com>',
 
657
                     'Jane Rey <jrey@example.com>'])
 
658
        self.assertFormatterResult("""\
680
659
------------------------------------------------------------
681
660
revno: 1
682
661
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
685
664
timestamp: Wed 2005-11-23 12:08:27 +1000
686
665
message:
687
666
  add a
688
 
''',
689
 
                             sio.getvalue())
 
667
""",
 
668
        wt.branch, log.LongLogFormatter)
690
669
 
691
670
    def test_properties_in_log(self):
692
671
        """Log includes the custom properties returned by the registered
693
672
        handlers.
694
673
        """
695
 
        wt = self.make_branch_and_tree('.')
696
 
        b = wt.branch
697
 
        self.build_tree(['a'])
698
 
        wt.add('a')
699
 
        b.nick = 'test_properties_in_log'
700
 
        wt.commit(message='add a',
701
 
                  timestamp=1132711707,
702
 
                  timezone=36000,
703
 
                  committer='Lorem Ipsum <test@example.com>',
704
 
                  authors=['John Doe <jdoe@example.com>'])
705
 
        sio = StringIO()
706
 
        formatter = log.LongLogFormatter(to_file=sio)
707
 
        try:
708
 
            def trivial_custom_prop_handler(revision):
709
 
                return {'test_prop':'test_value'}
 
674
        wt = self.make_standard_commit('test_properties_in_log')
 
675
        def trivial_custom_prop_handler(revision):
 
676
            return {'test_prop':'test_value'}
710
677
 
711
 
            log.properties_handler_registry.register(
712
 
                'trivial_custom_prop_handler',
713
 
                trivial_custom_prop_handler)
714
 
            log.show_log(b, formatter)
715
 
        finally:
716
 
            log.properties_handler_registry.remove(
717
 
                'trivial_custom_prop_handler')
718
 
            self.assertEqualDiff('''\
 
678
        # Cleaned up in setUp()
 
679
        log.properties_handler_registry.register(
 
680
            'trivial_custom_prop_handler',
 
681
            trivial_custom_prop_handler)
 
682
        self.assertFormatterResult("""\
719
683
------------------------------------------------------------
720
684
revno: 1
721
685
test_prop: test_value
725
689
timestamp: Wed 2005-11-23 12:08:27 +1000
726
690
message:
727
691
  add a
728
 
''',
729
 
                                 sio.getvalue())
 
692
""",
 
693
            wt.branch, log.LongLogFormatter)
730
694
 
731
695
    def test_properties_in_short_log(self):
732
696
        """Log includes the custom properties returned by the registered
733
697
        handlers.
734
698
        """
735
 
        wt = self.make_branch_and_tree('.')
736
 
        b = wt.branch
737
 
        self.build_tree(['a'])
738
 
        wt.add('a')
739
 
        b.nick = 'test_properties_in_short_log'
740
 
        wt.commit(message='add a',
741
 
                  timestamp=1132711707,
742
 
                  timezone=36000,
743
 
                  committer='Lorem Ipsum <test@example.com>',
744
 
                  authors=['John Doe <jdoe@example.com>'])
745
 
        sio = StringIO()
746
 
        formatter = log.ShortLogFormatter(to_file=sio)
747
 
        try:
748
 
            def trivial_custom_prop_handler(revision):
749
 
                return {'test_prop':'test_value'}
 
699
        wt = self.make_standard_commit('test_properties_in_short_log')
 
700
        def trivial_custom_prop_handler(revision):
 
701
            return {'test_prop':'test_value'}
750
702
 
751
 
            log.properties_handler_registry.register(
752
 
                'trivial_custom_prop_handler',
753
 
                trivial_custom_prop_handler)
754
 
            log.show_log(b, formatter)
755
 
        finally:
756
 
            log.properties_handler_registry.remove(
757
 
                'trivial_custom_prop_handler')
758
 
            self.assertEqualDiff('''\
 
703
        log.properties_handler_registry.register(
 
704
            'trivial_custom_prop_handler',
 
705
            trivial_custom_prop_handler)
 
706
        self.assertFormatterResult("""\
759
707
    1 John Doe\t2005-11-23
760
708
      test_prop: test_value
761
709
      add a
762
710
 
763
 
''',
764
 
                                 sio.getvalue())
 
711
""",
 
712
            wt.branch, log.ShortLogFormatter)
765
713
 
766
714
    def test_error_in_properties_handler(self):
767
715
        """Log includes the custom properties returned by the registered
768
716
        handlers.
769
717
        """
770
 
        wt = self.make_branch_and_tree('.')
771
 
        b = wt.branch
772
 
        self.build_tree(['a'])
773
 
        wt.add('a')
774
 
        b.nick = 'test_author_log'
775
 
        wt.commit(message='add a',
776
 
                  timestamp=1132711707,
777
 
                  timezone=36000,
778
 
                  committer='Lorem Ipsum <test@example.com>',
779
 
                  authors=['John Doe <jdoe@example.com>'],
780
 
                  revprops={'first_prop':'first_value'})
781
 
        sio = StringIO()
 
718
        wt = self.make_standard_commit('error_in_properties_handler',
 
719
            revprops={'first_prop':'first_value'})
 
720
        sio = self.make_utf8_encoded_stringio()
782
721
        formatter = log.LongLogFormatter(to_file=sio)
783
 
        try:
784
 
            def trivial_custom_prop_handler(revision):
785
 
                raise StandardError("a test error")
 
722
        def trivial_custom_prop_handler(revision):
 
723
            raise StandardError("a test error")
786
724
 
787
 
            log.properties_handler_registry.register(
788
 
                'trivial_custom_prop_handler',
789
 
                trivial_custom_prop_handler)
790
 
            self.assertRaises(StandardError, log.show_log, b, formatter,)
791
 
        finally:
792
 
            log.properties_handler_registry.remove(
793
 
                'trivial_custom_prop_handler')
 
725
        log.properties_handler_registry.register(
 
726
            'trivial_custom_prop_handler',
 
727
            trivial_custom_prop_handler)
 
728
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
794
729
 
795
730
    def test_properties_handler_bad_argument(self):
796
 
        wt = self.make_branch_and_tree('.')
797
 
        b = wt.branch
798
 
        self.build_tree(['a'])
799
 
        wt.add('a')
800
 
        b.nick = 'test_author_log'
801
 
        wt.commit(message='add a',
802
 
                  timestamp=1132711707,
803
 
                  timezone=36000,
804
 
                  committer='Lorem Ipsum <test@example.com>',
805
 
                  authors=['John Doe <jdoe@example.com>'],
806
 
                  revprops={'a_prop':'test_value'})
807
 
        sio = StringIO()
 
731
        wt = self.make_standard_commit('bad_argument',
 
732
              revprops={'a_prop':'test_value'})
 
733
        sio = self.make_utf8_encoded_stringio()
808
734
        formatter = log.LongLogFormatter(to_file=sio)
809
 
        try:
810
 
            def bad_argument_prop_handler(revision):
811
 
                return {'custom_prop_name':revision.properties['a_prop']}
812
 
 
813
 
            log.properties_handler_registry.register(
814
 
                'bad_argument_prop_handler',
815
 
                bad_argument_prop_handler)
816
 
 
817
 
            self.assertRaises(AttributeError, formatter.show_properties,
818
 
                              'a revision', '')
819
 
 
820
 
            revision = b.repository.get_revision(b.last_revision())
821
 
            formatter.show_properties(revision, '')
822
 
            self.assertEqualDiff('''custom_prop_name: test_value\n''',
823
 
                                 sio.getvalue())
824
 
        finally:
825
 
            log.properties_handler_registry.remove(
826
 
                'bad_argument_prop_handler')
827
 
 
828
 
 
829
 
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
 
735
        def bad_argument_prop_handler(revision):
 
736
            return {'custom_prop_name':revision.properties['a_prop']}
 
737
 
 
738
        log.properties_handler_registry.register(
 
739
            'bad_argument_prop_handler',
 
740
            bad_argument_prop_handler)
 
741
 
 
742
        self.assertRaises(AttributeError, formatter.show_properties,
 
743
                          'a revision', '')
 
744
 
 
745
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
 
746
        formatter.show_properties(revision, '')
 
747
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
 
748
                             sio.getvalue())
 
749
 
 
750
 
 
751
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
830
752
 
831
753
    def test_long_verbose_log(self):
832
754
        """Verbose log includes changed files
833
755
 
834
756
        bug #4676
835
757
        """
836
 
        wt = self.make_branch_and_tree('.')
837
 
        b = wt.branch
838
 
        self.build_tree(['a'])
839
 
        wt.add('a')
840
 
        # XXX: why does a longer nick show up?
841
 
        b.nick = 'test_verbose_log'
842
 
        wt.commit(message='add a',
843
 
                  timestamp=1132711707,
844
 
                  timezone=36000,
845
 
                  committer='Lorem Ipsum <test@example.com>')
846
 
        logfile = file('out.tmp', 'w+')
847
 
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
848
 
        log.show_log(b, formatter, verbose=True)
849
 
        logfile.flush()
850
 
        logfile.seek(0)
851
 
        log_contents = logfile.read()
852
 
        self.assertEqualDiff('''\
 
758
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
 
759
        self.assertFormatterResult("""\
853
760
------------------------------------------------------------
854
761
revno: 1
855
762
committer: Lorem Ipsum <test@example.com>
856
 
branch nick: test_verbose_log
 
763
branch nick: test_long_verbose_log
857
764
timestamp: Wed 2005-11-23 12:08:27 +1000
858
765
message:
859
766
  add a
860
767
added:
861
768
  a
862
 
''',
863
 
                             log_contents)
 
769
""",
 
770
            wt.branch, log.LongLogFormatter,
 
771
            formatter_kwargs=dict(levels=1),
 
772
            show_log_kwargs=dict(verbose=True))
864
773
 
865
774
    def test_long_verbose_contain_deltas(self):
866
775
        wt = self.make_branch_and_tree('parent')
867
776
        self.build_tree(['parent/f1', 'parent/f2'])
868
777
        wt.add(['f1','f2'])
869
778
        wt.commit('first post')
870
 
        self.run_bzr('branch parent child')
 
779
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
871
780
        os.unlink('child/f1')
872
 
        file('child/f2', 'wb').write('hello\n')
873
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
874
 
            'child'])
875
 
        os.chdir('parent')
876
 
        self.run_bzr('merge ../child')
 
781
        self.build_tree_contents([('child/f2', 'hello\n')])
 
782
        child_wt.commit('removed f1 and modified f2')
 
783
        wt.merge_from_branch(child_wt.branch)
877
784
        wt.commit('merge branch 1')
878
 
        b = wt.branch
879
 
        sio = self.make_utf8_encoded_stringio()
880
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
881
 
        log.show_log(b, lf, verbose=True)
882
 
        the_log = normalize_log(sio.getvalue())
883
 
        self.assertEqualDiff("""\
 
785
        self.assertFormatterResult("""\
884
786
------------------------------------------------------------
885
787
revno: 2 [merge]
886
788
committer: Lorem Ipsum <test@example.com>
903
805
  f1
904
806
  f2
905
807
""",
906
 
                             the_log)
 
808
            wt.branch, log.LongLogFormatter,
 
809
            formatter_kwargs=dict(levels=1),
 
810
            show_log_kwargs=dict(verbose=True),
 
811
            normalize=True)
907
812
 
908
813
    def test_long_trailing_newlines(self):
909
814
        wt = self.make_branch_and_tree('.')
910
815
        b = make_commits_with_trailing_newlines(wt)
911
 
        sio = self.make_utf8_encoded_stringio()
912
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
913
 
        log.show_log(b, lf)
914
 
        self.assertEqualDiff("""\
 
816
        self.assertFormatterResult("""\
915
817
------------------------------------------------------------
916
818
revno: 3
917
819
committer: Joe Foo <joe@foo.com>
937
839
message:
938
840
  simple log message
939
841
""",
940
 
                             sio.getvalue())
 
842
        b, log.LongLogFormatter,
 
843
        formatter_kwargs=dict(levels=1))
941
844
 
942
845
    def test_long_author_in_log(self):
943
846
        """Log includes the author name if it's set in
944
847
        the revision properties
945
848
        """
946
 
        wt = self.make_branch_and_tree('.')
947
 
        b = wt.branch
948
 
        self.build_tree(['a'])
949
 
        wt.add('a')
950
 
        b.nick = 'test_author_log'
951
 
        wt.commit(message='add a',
952
 
                  timestamp=1132711707,
953
 
                  timezone=36000,
954
 
                  committer='Lorem Ipsum <test@example.com>',
955
 
                  authors=['John Doe <jdoe@example.com>'])
956
 
        sio = StringIO()
957
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
958
 
        log.show_log(b, formatter)
959
 
        self.assertEqualDiff('''\
 
849
        wt = self.make_standard_commit('test_author_log')
 
850
        self.assertFormatterResult("""\
960
851
------------------------------------------------------------
961
852
revno: 1
962
853
author: John Doe <jdoe@example.com>
965
856
timestamp: Wed 2005-11-23 12:08:27 +1000
966
857
message:
967
858
  add a
968
 
''',
969
 
                             sio.getvalue())
 
859
""",
 
860
            wt.branch, log.LongLogFormatter,
 
861
            formatter_kwargs=dict(levels=1))
970
862
 
971
863
    def test_long_properties_in_log(self):
972
864
        """Log includes the custom properties returned by the registered
973
865
        handlers.
974
866
        """
975
 
        wt = self.make_branch_and_tree('.')
976
 
        b = wt.branch
977
 
        self.build_tree(['a'])
978
 
        wt.add('a')
979
 
        b.nick = 'test_properties_in_log'
980
 
        wt.commit(message='add a',
981
 
                  timestamp=1132711707,
982
 
                  timezone=36000,
983
 
                  committer='Lorem Ipsum <test@example.com>',
984
 
                  authors=['John Doe <jdoe@example.com>'])
985
 
        sio = StringIO()
986
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
987
 
        try:
988
 
            def trivial_custom_prop_handler(revision):
989
 
                return {'test_prop':'test_value'}
 
867
        wt = self.make_standard_commit('test_properties_in_log')
 
868
        def trivial_custom_prop_handler(revision):
 
869
            return {'test_prop':'test_value'}
990
870
 
991
 
            log.properties_handler_registry.register(
992
 
                'trivial_custom_prop_handler',
993
 
                trivial_custom_prop_handler)
994
 
            log.show_log(b, formatter)
995
 
        finally:
996
 
            log.properties_handler_registry.remove(
997
 
                'trivial_custom_prop_handler')
998
 
            self.assertEqualDiff('''\
 
871
        log.properties_handler_registry.register(
 
872
            'trivial_custom_prop_handler',
 
873
            trivial_custom_prop_handler)
 
874
        self.assertFormatterResult("""\
999
875
------------------------------------------------------------
1000
876
revno: 1
1001
877
test_prop: test_value
1005
881
timestamp: Wed 2005-11-23 12:08:27 +1000
1006
882
message:
1007
883
  add a
1008
 
''',
1009
 
                                 sio.getvalue())
1010
 
 
1011
 
 
1012
 
class TestLineLogFormatter(tests.TestCaseWithTransport):
 
884
""",
 
885
            wt.branch, log.LongLogFormatter,
 
886
            formatter_kwargs=dict(levels=1))
 
887
 
 
888
 
 
889
class TestLineLogFormatter(TestCaseForLogFormatter):
1013
890
 
1014
891
    def test_line_log(self):
1015
892
        """Line log should show revno
1016
893
 
1017
894
        bug #5162
1018
895
        """
1019
 
        wt = self.make_branch_and_tree('.')
1020
 
        b = wt.branch
1021
 
        self.build_tree(['a'])
1022
 
        wt.add('a')
1023
 
        b.nick = 'test-line-log'
1024
 
        wt.commit(message='add a',
1025
 
                  timestamp=1132711707,
1026
 
                  timezone=36000,
1027
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1028
 
        logfile = file('out.tmp', 'w+')
1029
 
        formatter = log.LineLogFormatter(to_file=logfile)
1030
 
        log.show_log(b, formatter)
1031
 
        logfile.flush()
1032
 
        logfile.seek(0)
1033
 
        log_contents = logfile.read()
1034
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1035
 
                             log_contents)
 
896
        wt = self.make_standard_commit('test-line-log',
 
897
                committer='Line-Log-Formatter Tester <test@line.log>',
 
898
                authors=[])
 
899
        self.assertFormatterResult("""\
 
900
1: Line-Log-Formatte... 2005-11-23 add a
 
901
""",
 
902
            wt.branch, log.LineLogFormatter)
1036
903
 
1037
904
    def test_trailing_newlines(self):
1038
905
        wt = self.make_branch_and_tree('.')
1039
906
        b = make_commits_with_trailing_newlines(wt)
1040
 
        sio = self.make_utf8_encoded_stringio()
1041
 
        lf = log.LineLogFormatter(to_file=sio)
1042
 
        log.show_log(b, lf)
1043
 
        self.assertEqualDiff("""\
 
907
        self.assertFormatterResult("""\
1044
908
3: Joe Foo 2005-11-21 single line with trailing newline
1045
909
2: Joe Bar 2005-11-21 multiline
1046
910
1: Joe Foo 2005-11-21 simple log message
1047
911
""",
1048
 
                             sio.getvalue())
1049
 
 
1050
 
    def _prepare_tree_with_merges(self, with_tags=False):
1051
 
        wt = self.make_branch_and_memory_tree('.')
1052
 
        wt.lock_write()
1053
 
        self.addCleanup(wt.unlock)
1054
 
        wt.add('')
1055
 
        wt.commit('rev-1', rev_id='rev-1',
1056
 
                  timestamp=1132586655, timezone=36000,
1057
 
                  committer='Joe Foo <joe@foo.com>')
1058
 
        wt.commit('rev-merged', rev_id='rev-2a',
1059
 
                  timestamp=1132586700, timezone=36000,
1060
 
                  committer='Joe Foo <joe@foo.com>')
1061
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1062
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1063
 
        wt.commit('rev-2', rev_id='rev-2b',
1064
 
                  timestamp=1132586800, timezone=36000,
1065
 
                  committer='Joe Foo <joe@foo.com>')
1066
 
        if with_tags:
1067
 
            branch = wt.branch
1068
 
            branch.tags.set_tag('v0.2', 'rev-2b')
1069
 
            wt.commit('rev-3', rev_id='rev-3',
1070
 
                      timestamp=1132586900, timezone=36000,
1071
 
                      committer='Jane Foo <jane@foo.com>')
1072
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
1073
 
            branch.tags.set_tag('v1.0', 'rev-3')
1074
 
        return wt
 
912
            b, log.LineLogFormatter)
1075
913
 
1076
914
    def test_line_log_single_merge_revision(self):
1077
915
        wt = self._prepare_tree_with_merges()
1078
 
        logfile = self.make_utf8_encoded_stringio()
1079
 
        formatter = log.LineLogFormatter(to_file=logfile)
1080
916
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1081
 
        wtb = wt.branch
1082
 
        rev = revspec.in_history(wtb)
1083
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1084
 
        self.assertEqualDiff("""\
 
917
        rev = revspec.in_history(wt.branch)
 
918
        self.assertFormatterResult("""\
1085
919
1.1.1: Joe Foo 2005-11-22 rev-merged
1086
920
""",
1087
 
                             logfile.getvalue())
 
921
            wt.branch, log.LineLogFormatter,
 
922
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1088
923
 
1089
924
    def test_line_log_with_tags(self):
1090
925
        wt = self._prepare_tree_with_merges(with_tags=True)
1091
 
        logfile = self.make_utf8_encoded_stringio()
1092
 
        formatter = log.LineLogFormatter(to_file=logfile)
1093
 
        log.show_log(wt.branch, formatter)
1094
 
        self.assertEqualDiff("""\
 
926
        self.assertFormatterResult("""\
1095
927
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1096
928
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
1097
929
1: Joe Foo 2005-11-22 rev-1
1098
930
""",
1099
 
                             logfile.getvalue())
1100
 
 
1101
 
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
931
            wt.branch, log.LineLogFormatter)
 
932
 
 
933
 
 
934
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
1102
935
 
1103
936
    def test_line_merge_revs_log(self):
1104
937
        """Line log should show revno
1105
938
 
1106
939
        bug #5162
1107
940
        """
1108
 
        wt = self.make_branch_and_tree('.')
1109
 
        b = wt.branch
1110
 
        self.build_tree(['a'])
1111
 
        wt.add('a')
1112
 
        b.nick = 'test-line-log'
1113
 
        wt.commit(message='add a',
1114
 
                  timestamp=1132711707,
1115
 
                  timezone=36000,
1116
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1117
 
        logfile = file('out.tmp', 'w+')
1118
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1119
 
        log.show_log(b, formatter)
1120
 
        logfile.flush()
1121
 
        logfile.seek(0)
1122
 
        log_contents = logfile.read()
1123
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1124
 
                             log_contents)
 
941
        wt = self.make_standard_commit('test-line-log',
 
942
                committer='Line-Log-Formatter Tester <test@line.log>',
 
943
                authors=[])
 
944
        self.assertFormatterResult("""\
 
945
1: Line-Log-Formatte... 2005-11-23 add a
 
946
""",
 
947
            wt.branch, log.LineLogFormatter)
1125
948
 
1126
949
    def test_line_merge_revs_log_single_merge_revision(self):
1127
950
        wt = self.make_branch_and_memory_tree('.')
1139
962
        wt.commit('rev-2', rev_id='rev-2b',
1140
963
                  timestamp=1132586800, timezone=36000,
1141
964
                  committer='Joe Foo <joe@foo.com>')
1142
 
        logfile = self.make_utf8_encoded_stringio()
1143
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1144
965
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1145
 
        wtb = wt.branch
1146
 
        rev = revspec.in_history(wtb)
1147
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1148
 
        self.assertEqualDiff("""\
 
966
        rev = revspec.in_history(wt.branch)
 
967
        self.assertFormatterResult("""\
1149
968
1.1.1: Joe Foo 2005-11-22 rev-merged
1150
969
""",
1151
 
                             logfile.getvalue())
 
970
            wt.branch, log.LineLogFormatter,
 
971
            formatter_kwargs=dict(levels=0),
 
972
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1152
973
 
1153
974
    def test_line_merge_revs_log_with_merges(self):
1154
975
        wt = self.make_branch_and_memory_tree('.')
1166
987
        wt.commit('rev-2', rev_id='rev-2b',
1167
988
                  timestamp=1132586800, timezone=36000,
1168
989
                  committer='Joe Foo <joe@foo.com>')
1169
 
        logfile = self.make_utf8_encoded_stringio()
1170
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1171
 
        log.show_log(wt.branch, formatter)
1172
 
        self.assertEqualDiff("""\
 
990
        self.assertFormatterResult("""\
1173
991
2: Joe Foo 2005-11-22 [merge] rev-2
1174
992
  1.1.1: Joe Foo 2005-11-22 rev-merged
1175
993
1: Joe Foo 2005-11-22 rev-1
1176
994
""",
1177
 
                             logfile.getvalue())
 
995
            wt.branch, log.LineLogFormatter,
 
996
            formatter_kwargs=dict(levels=0))
 
997
 
1178
998
 
1179
999
class TestGetViewRevisions(tests.TestCaseWithTransport):
1180
1000