~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-01-29 07:18:57 UTC
  • mfrom: (3970.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090129071857-l3ikkrm6b1rx96bx
log -n/--levels (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
410
410
        rev = revspec.in_history(wtb)
411
411
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
412
412
        self.assertEqualDiff("""\
413
 
1.1.1 Joe Foo\t2005-11-22
414
 
      rev-merged
 
413
      1.1.1 Joe Foo\t2005-11-22
 
414
            rev-merged
 
415
 
 
416
""",
 
417
                             logfile.getvalue())
 
418
 
 
419
 
 
420
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
421
 
 
422
    def test_short_merge_revs_log_with_merges(self):
 
423
        wt = self.make_branch_and_memory_tree('.')
 
424
        wt.lock_write()
 
425
        self.addCleanup(wt.unlock)
 
426
        wt.add('')
 
427
        wt.commit('rev-1', rev_id='rev-1',
 
428
                  timestamp=1132586655, timezone=36000,
 
429
                  committer='Joe Foo <joe@foo.com>')
 
430
        wt.commit('rev-merged', rev_id='rev-2a',
 
431
                  timestamp=1132586700, timezone=36000,
 
432
                  committer='Joe Foo <joe@foo.com>')
 
433
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
434
        wt.branch.set_last_revision_info(1, 'rev-1')
 
435
        wt.commit('rev-2', rev_id='rev-2b',
 
436
                  timestamp=1132586800, timezone=36000,
 
437
                  committer='Joe Foo <joe@foo.com>')
 
438
        logfile = self.make_utf8_encoded_stringio()
 
439
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
440
        log.show_log(wt.branch, formatter)
 
441
        # Note that the 1.1.1 indenting is in fact correct given that
 
442
        # the revision numbers are right justified within 5 characters
 
443
        # for mainline revnos and 9 characters for dotted revnos.
 
444
        self.assertEqualDiff("""\
 
445
    2 Joe Foo\t2005-11-22 [merge]
 
446
      rev-2
 
447
 
 
448
          1.1.1 Joe Foo\t2005-11-22
 
449
                rev-merged
 
450
 
 
451
    1 Joe Foo\t2005-11-22
 
452
      rev-1
 
453
 
 
454
""",
 
455
                             logfile.getvalue())
 
456
 
 
457
    def test_short_merge_revs_log_single_merge_revision(self):
 
458
        wt = self.make_branch_and_memory_tree('.')
 
459
        wt.lock_write()
 
460
        self.addCleanup(wt.unlock)
 
461
        wt.add('')
 
462
        wt.commit('rev-1', rev_id='rev-1',
 
463
                  timestamp=1132586655, timezone=36000,
 
464
                  committer='Joe Foo <joe@foo.com>')
 
465
        wt.commit('rev-merged', rev_id='rev-2a',
 
466
                  timestamp=1132586700, timezone=36000,
 
467
                  committer='Joe Foo <joe@foo.com>')
 
468
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
469
        wt.branch.set_last_revision_info(1, 'rev-1')
 
470
        wt.commit('rev-2', rev_id='rev-2b',
 
471
                  timestamp=1132586800, timezone=36000,
 
472
                  committer='Joe Foo <joe@foo.com>')
 
473
        logfile = self.make_utf8_encoded_stringio()
 
474
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
475
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
 
476
        wtb = wt.branch
 
477
        rev = revspec.in_history(wtb)
 
478
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
479
        self.assertEqualDiff("""\
 
480
      1.1.1 Joe Foo\t2005-11-22
 
481
            rev-merged
415
482
 
416
483
""",
417
484
                             logfile.getvalue())
731
798
                'bad_argument_prop_handler')
732
799
 
733
800
 
 
801
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
 
802
 
 
803
    def test_long_verbose_log(self):
 
804
        """Verbose log includes changed files
 
805
        
 
806
        bug #4676
 
807
        """
 
808
        wt = self.make_branch_and_tree('.')
 
809
        b = wt.branch
 
810
        self.build_tree(['a'])
 
811
        wt.add('a')
 
812
        # XXX: why does a longer nick show up?
 
813
        b.nick = 'test_verbose_log'
 
814
        wt.commit(message='add a',
 
815
                  timestamp=1132711707,
 
816
                  timezone=36000,
 
817
                  committer='Lorem Ipsum <test@example.com>')
 
818
        logfile = file('out.tmp', 'w+')
 
819
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
 
820
        log.show_log(b, formatter, verbose=True)
 
821
        logfile.flush()
 
822
        logfile.seek(0)
 
823
        log_contents = logfile.read()
 
824
        self.assertEqualDiff('''\
 
825
------------------------------------------------------------
 
826
revno: 1
 
827
committer: Lorem Ipsum <test@example.com>
 
828
branch nick: test_verbose_log
 
829
timestamp: Wed 2005-11-23 12:08:27 +1000
 
830
message:
 
831
  add a
 
832
added:
 
833
  a
 
834
''',
 
835
                             log_contents)
 
836
 
 
837
    def test_long_verbose_contain_deltas(self):
 
838
        wt = self.make_branch_and_tree('parent')
 
839
        self.build_tree(['parent/f1', 'parent/f2'])
 
840
        wt.add(['f1','f2'])
 
841
        wt.commit('first post')
 
842
        self.run_bzr('branch parent child')
 
843
        os.unlink('child/f1')
 
844
        file('child/f2', 'wb').write('hello\n')
 
845
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
 
846
            'child'])
 
847
        os.chdir('parent')
 
848
        self.run_bzr('merge ../child')
 
849
        wt.commit('merge branch 1')
 
850
        b = wt.branch
 
851
        sio = self.make_utf8_encoded_stringio()
 
852
        lf = log.LongLogFormatter(to_file=sio, levels=1)
 
853
        log.show_log(b, lf, verbose=True)
 
854
        the_log = normalize_log(sio.getvalue())
 
855
        self.assertEqualDiff("""\
 
856
------------------------------------------------------------
 
857
revno: 2
 
858
committer: Lorem Ipsum <test@example.com>
 
859
branch nick: parent
 
860
timestamp: Just now
 
861
message:
 
862
  merge branch 1
 
863
removed:
 
864
  f1
 
865
modified:
 
866
  f2
 
867
------------------------------------------------------------
 
868
revno: 1
 
869
committer: Lorem Ipsum <test@example.com>
 
870
branch nick: parent
 
871
timestamp: Just now
 
872
message:
 
873
  first post
 
874
added:
 
875
  f1
 
876
  f2
 
877
""",
 
878
                             the_log)
 
879
 
 
880
    def test_long_trailing_newlines(self):
 
881
        wt = self.make_branch_and_tree('.')
 
882
        b = make_commits_with_trailing_newlines(wt)
 
883
        sio = self.make_utf8_encoded_stringio()
 
884
        lf = log.LongLogFormatter(to_file=sio, levels=1)
 
885
        log.show_log(b, lf)
 
886
        self.assertEqualDiff("""\
 
887
------------------------------------------------------------
 
888
revno: 3
 
889
committer: Joe Foo <joe@foo.com>
 
890
branch nick: test
 
891
timestamp: Mon 2005-11-21 09:32:56 -0600
 
892
message:
 
893
  single line with trailing newline
 
894
------------------------------------------------------------
 
895
revno: 2
 
896
author: Joe Bar <joe@bar.com>
 
897
committer: Joe Foo <joe@foo.com>
 
898
branch nick: test
 
899
timestamp: Mon 2005-11-21 09:27:22 -0600
 
900
message:
 
901
  multiline
 
902
  log
 
903
  message
 
904
------------------------------------------------------------
 
905
revno: 1
 
906
committer: Joe Foo <joe@foo.com>
 
907
branch nick: test
 
908
timestamp: Mon 2005-11-21 09:24:15 -0600
 
909
message:
 
910
  simple log message
 
911
""",
 
912
                             sio.getvalue())
 
913
 
 
914
    def test_long_author_in_log(self):
 
915
        """Log includes the author name if it's set in
 
916
        the revision properties
 
917
        """
 
918
        wt = self.make_branch_and_tree('.')
 
919
        b = wt.branch
 
920
        self.build_tree(['a'])
 
921
        wt.add('a')
 
922
        b.nick = 'test_author_log'
 
923
        wt.commit(message='add a',
 
924
                  timestamp=1132711707,
 
925
                  timezone=36000,
 
926
                  committer='Lorem Ipsum <test@example.com>',
 
927
                  author='John Doe <jdoe@example.com>')
 
928
        sio = StringIO()
 
929
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
 
930
        log.show_log(b, formatter)
 
931
        self.assertEqualDiff('''\
 
932
------------------------------------------------------------
 
933
revno: 1
 
934
author: John Doe <jdoe@example.com>
 
935
committer: Lorem Ipsum <test@example.com>
 
936
branch nick: test_author_log
 
937
timestamp: Wed 2005-11-23 12:08:27 +1000
 
938
message:
 
939
  add a
 
940
''',
 
941
                             sio.getvalue())
 
942
 
 
943
    def test_long_properties_in_log(self):
 
944
        """Log includes the custom properties returned by the registered 
 
945
        handlers.
 
946
        """
 
947
        wt = self.make_branch_and_tree('.')
 
948
        b = wt.branch
 
949
        self.build_tree(['a'])
 
950
        wt.add('a')
 
951
        b.nick = 'test_properties_in_log'
 
952
        wt.commit(message='add a',
 
953
                  timestamp=1132711707,
 
954
                  timezone=36000,
 
955
                  committer='Lorem Ipsum <test@example.com>',
 
956
                  author='John Doe <jdoe@example.com>')
 
957
        sio = StringIO()
 
958
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
 
959
        try:
 
960
            def trivial_custom_prop_handler(revision):
 
961
                return {'test_prop':'test_value'}
 
962
 
 
963
            log.properties_handler_registry.register(
 
964
                'trivial_custom_prop_handler',
 
965
                trivial_custom_prop_handler)
 
966
            log.show_log(b, formatter)
 
967
        finally:
 
968
            log.properties_handler_registry.remove(
 
969
                'trivial_custom_prop_handler')
 
970
            self.assertEqualDiff('''\
 
971
------------------------------------------------------------
 
972
revno: 1
 
973
test_prop: test_value
 
974
author: John Doe <jdoe@example.com>
 
975
committer: Lorem Ipsum <test@example.com>
 
976
branch nick: test_properties_in_log
 
977
timestamp: Wed 2005-11-23 12:08:27 +1000
 
978
message:
 
979
  add a
 
980
''',
 
981
                                 sio.getvalue())
 
982
 
 
983
 
734
984
class TestLineLogFormatter(tests.TestCaseWithTransport):
735
985
 
736
986
    def test_line_log(self):
820
1070
""",
821
1071
                             logfile.getvalue())
822
1072
 
 
1073
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
1074
 
 
1075
    def test_line_merge_revs_log(self):
 
1076
        """Line log should show revno
 
1077
        
 
1078
        bug #5162
 
1079
        """
 
1080
        wt = self.make_branch_and_tree('.')
 
1081
        b = wt.branch
 
1082
        self.build_tree(['a'])
 
1083
        wt.add('a')
 
1084
        b.nick = 'test-line-log'
 
1085
        wt.commit(message='add a',
 
1086
                  timestamp=1132711707,
 
1087
                  timezone=36000,
 
1088
                  committer='Line-Log-Formatter Tester <test@line.log>')
 
1089
        logfile = file('out.tmp', 'w+')
 
1090
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
1091
        log.show_log(b, formatter)
 
1092
        logfile.flush()
 
1093
        logfile.seek(0)
 
1094
        log_contents = logfile.read()
 
1095
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
 
1096
                             log_contents)
 
1097
 
 
1098
    def test_line_merge_revs_log_single_merge_revision(self):
 
1099
        wt = self.make_branch_and_memory_tree('.')
 
1100
        wt.lock_write()
 
1101
        self.addCleanup(wt.unlock)
 
1102
        wt.add('')
 
1103
        wt.commit('rev-1', rev_id='rev-1',
 
1104
                  timestamp=1132586655, timezone=36000,
 
1105
                  committer='Joe Foo <joe@foo.com>')
 
1106
        wt.commit('rev-merged', rev_id='rev-2a',
 
1107
                  timestamp=1132586700, timezone=36000,
 
1108
                  committer='Joe Foo <joe@foo.com>')
 
1109
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
1110
        wt.branch.set_last_revision_info(1, 'rev-1')
 
1111
        wt.commit('rev-2', rev_id='rev-2b',
 
1112
                  timestamp=1132586800, timezone=36000,
 
1113
                  committer='Joe Foo <joe@foo.com>')
 
1114
        logfile = self.make_utf8_encoded_stringio()
 
1115
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
1116
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
 
1117
        wtb = wt.branch
 
1118
        rev = revspec.in_history(wtb)
 
1119
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
1120
        self.assertEqualDiff("""\
 
1121
1.1.1: Joe Foo 2005-11-22 rev-merged
 
1122
""",
 
1123
                             logfile.getvalue())
 
1124
 
 
1125
    def test_line_merge_revs_log_with_merges(self):
 
1126
        wt = self.make_branch_and_memory_tree('.')
 
1127
        wt.lock_write()
 
1128
        self.addCleanup(wt.unlock)
 
1129
        wt.add('')
 
1130
        wt.commit('rev-1', rev_id='rev-1',
 
1131
                  timestamp=1132586655, timezone=36000,
 
1132
                  committer='Joe Foo <joe@foo.com>')
 
1133
        wt.commit('rev-merged', rev_id='rev-2a',
 
1134
                  timestamp=1132586700, timezone=36000,
 
1135
                  committer='Joe Foo <joe@foo.com>')
 
1136
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
1137
        wt.branch.set_last_revision_info(1, 'rev-1')
 
1138
        wt.commit('rev-2', rev_id='rev-2b',
 
1139
                  timestamp=1132586800, timezone=36000,
 
1140
                  committer='Joe Foo <joe@foo.com>')
 
1141
        logfile = self.make_utf8_encoded_stringio()
 
1142
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
1143
        log.show_log(wt.branch, formatter)
 
1144
        self.assertEqualDiff("""\
 
1145
2: Joe Foo 2005-11-22 rev-2
 
1146
  1.1.1: Joe Foo 2005-11-22 rev-merged
 
1147
1: Joe Foo 2005-11-22 rev-1
 
1148
""",
 
1149
                             logfile.getvalue())
823
1150
 
824
1151
class TestGetViewRevisions(tests.TestCaseWithTransport):
825
1152