~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_log.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 17:25:29 UTC
  • mfrom: (6499 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6501.
  • Revision ID: v.ladeuil+lp@free.fr-20120313172529-i0suyjnepsor25i7
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from itertools import izip
21
21
import os
22
 
import re
23
22
 
24
23
from bzrlib import (
25
24
    branchbuilder,
29
28
    tests,
30
29
    )
31
30
from bzrlib.tests import (
32
 
    script,
33
31
    test_log,
 
32
    features,
34
33
    )
 
34
from bzrlib.tests.matchers import ContainsNoVfsCalls
35
35
 
36
36
 
37
37
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
77
77
                self.log_catcher = test_log.LogCatcher(*args, **kwargs)
78
78
                # Always return our own log formatter
79
79
                return self.log_catcher
 
80
        # Break cycle with closure over self on cleanup by removing method
 
81
        self.addCleanup(setattr, MyLogFormatter, "__new__", None)
80
82
 
81
83
        def getme(branch):
82
84
                # Always return our own log formatter class hijacking the
88
90
    def get_captured_revisions(self):
89
91
        return self.log_catcher.revisions
90
92
 
91
 
    def assertLogRevnos(self, args, expected_revnos, working_dir='.'):
92
 
        self.run_bzr(['log'] + args, working_dir=working_dir)
 
93
    def assertLogRevnos(self, args, expected_revnos, working_dir='.',
 
94
                        out='', err=''):
 
95
        actual_out, actual_err = self.run_bzr(['log'] + args,
 
96
                                              working_dir=working_dir)
 
97
        self.assertEqual(out, actual_out)
 
98
        self.assertEqual(err, actual_err)
93
99
        self.assertEqual(expected_revnos,
94
100
                         [r.revno for r in self.get_captured_revisions()])
95
101
 
199
205
        # 4  1.1.4
200
206
        # | /
201
207
        # 5
 
208
        # | \
 
209
        # | 5.1.1
 
210
        # | /
 
211
        # 6
202
212
 
203
213
        # mainline
204
214
        builder.build_snapshot('1', None, [
217
227
        builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
218
228
        # merge branch into mainline
219
229
        builder.build_snapshot('5', ['4', '1.1.4'], [])
 
230
        builder.build_snapshot('5.1.1', ['5'], [])
 
231
        builder.build_snapshot('6', ['5', '5.1.1'], [])
220
232
        builder.finish_series()
221
233
 
222
234
    def test_n0(self):
235
247
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
236
248
                             ['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
237
249
 
 
250
    def test_fallback_when_end_rev_is_not_on_mainline(self):
 
251
        self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
 
252
                             # We don't get 1.1.1 because we say -n1
 
253
                             ['5.1.1', '5', '4', '3'])
 
254
 
238
255
 
239
256
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
240
257
 
252
269
        # The graph below may look a bit complicated (and it may be but I've
253
270
        # banged my head enough on it) but the bug requires at least dotted
254
271
        # revnos *and* merged revisions below that.
 
272
        # 1
 
273
        # | \
 
274
        # 2  1.1.1
 
275
        # | X
 
276
        # 3  2.1.1
 
277
        # |   |    \
 
278
        # |  2.1.2  2.2.1
 
279
        # |   |    X
 
280
        # |  2.1.3  \
 
281
        # | /       /
 
282
        # 4        /
 
283
        # |       /
 
284
        # 5 -----/
255
285
        builder.build_snapshot('1', None, [
256
286
            ('add', ('', 'root-id', 'directory', ''))])
257
287
        builder.build_snapshot('2', ['1'], [])
376
406
    def test_log_reversed_dotted_revspecs(self):
377
407
        self.make_merged_branch()
378
408
        self.run_bzr_error(('bzr: ERROR: Start revision not found in '
379
 
                            'left-hand history of end revision.\n',),
 
409
                            'history of end revision.\n',),
380
410
                           "log -r 1.1.1..1")
381
411
 
382
412
    def test_log_bad_message_re(self):
442
472
        self.assertContainsRe(log, r'tags: tag1')
443
473
 
444
474
 
 
475
class TestLogSignatures(TestLog):
 
476
 
 
477
    def test_log_with_signatures(self):
 
478
        self.requireFeature(features.gpgme)
 
479
 
 
480
        tree = self.make_linear_branch(format='dirstate-tags')
 
481
 
 
482
        log = self.run_bzr("log --signatures")[0]
 
483
        self.assertTrue('signature: no signature' in log)
 
484
 
 
485
    def test_log_without_signatures(self):
 
486
        self.requireFeature(features.gpgme)
 
487
 
 
488
        tree = self.make_linear_branch(format='dirstate-tags')
 
489
 
 
490
        log = self.run_bzr("log")[0]
 
491
        self.assertFalse('signature: no signature' in log)
 
492
 
 
493
 
445
494
class TestLogVerbose(TestLog):
446
495
 
447
496
    def setUp(self):
463
512
    def test_log_short_verbose(self):
464
513
        self.assertUseShortDeltaFormat(['log', '--short', '-v'])
465
514
 
 
515
    def test_log_s_verbose(self):
 
516
        self.assertUseShortDeltaFormat(['log', '-S', '-v'])
 
517
 
466
518
    def test_log_short_verbose_verbose(self):
467
519
        self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
468
520
 
513
565
 
514
566
    def test_include_merges(self):
515
567
        # Confirm --include-merges gives the same output as -n0
516
 
        self.assertLogRevnos(['--include-merges'],
517
 
                             ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
518
 
                             working_dir='level0')
519
 
        self.assertLogRevnos(['--include-merges'],
520
 
                             ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
521
 
                             working_dir='level0')
 
568
        msg = ("The option '--include-merges' to 'bzr log' "
 
569
               "has been deprecated in bzr 2.5. "
 
570
               "Please use '--include-merged' instead.\n")
 
571
        self.assertLogRevnos(['--include-merges'],
 
572
                             ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
 
573
                             working_dir='level0', err=msg)
 
574
        self.assertLogRevnos(['--include-merges'],
 
575
                             ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
 
576
                             working_dir='level0', err=msg)
522
577
        out_im, err_im = self.run_bzr('log --include-merges',
523
578
                                      working_dir='level0')
524
579
        out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
525
 
        self.assertEqual('', err_im)
 
580
        self.assertEqual(msg, err_im)
526
581
        self.assertEqual('', err_n0)
527
582
        self.assertEqual(out_im, out_n0)
528
583
 
 
584
    def test_include_merged(self):
 
585
        # Confirm --include-merged gives the same output as -n0
 
586
        expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
 
587
        self.assertLogRevnos(['--include-merged'],
 
588
                             expected, working_dir='level0')
 
589
        self.assertLogRevnos(['--include-merged'],
 
590
                             expected, working_dir='level0')
 
591
 
529
592
    def test_force_merge_revisions_N(self):
530
593
        self.assertLogRevnos(['-n2'],
531
594
                             ['2', '1.1.2', '1.1.1', '1'],
549
612
                [('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
550
613
                working_dir='level0')
551
614
 
 
615
    def test_omit_merges_with_sidelines(self):
 
616
        self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
 
617
                             working_dir='level0')
 
618
 
 
619
    def test_omit_merges_without_sidelines(self):
 
620
        self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
 
621
                             working_dir='level0')
 
622
 
552
623
 
553
624
class TestLogDiff(TestLogWithLogCatcher):
554
625
 
924
995
        self.prepare_tree()
925
996
        os.chdir("dir1")
926
997
        self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
 
998
 
 
999
 
 
1000
class MainlineGhostTests(TestLogWithLogCatcher):
 
1001
 
 
1002
    def setUp(self):
 
1003
        super(MainlineGhostTests, self).setUp()
 
1004
        tree = self.make_branch_and_tree('')
 
1005
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
 
1006
        tree.add('')
 
1007
        tree.commit('msg1', rev_id='rev1')
 
1008
        tree.commit('msg2', rev_id='rev2')
 
1009
 
 
1010
    def test_log_range(self):
 
1011
        self.assertLogRevnos(["-r1..2"], ["2", "1"])
 
1012
 
 
1013
    def test_log_norange(self):
 
1014
        self.assertLogRevnos([], ["2", "1"])
 
1015
 
 
1016
    def test_log_range_open_begin(self):
 
1017
        self.knownFailure("log with ghosts fails. bug #726466")
 
1018
        (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
 
1019
        self.assertEqual(["2", "1"],
 
1020
                         [r.revno for r in self.get_captured_revisions()])
 
1021
        self.assertEquals("bzr: ERROR: Further revision history missing.", stderr)
 
1022
 
 
1023
    def test_log_range_open_end(self):
 
1024
        self.assertLogRevnos(["-r1.."], ["2", "1"])
 
1025
 
 
1026
class TestLogMatch(TestLogWithLogCatcher):
 
1027
    def prepare_tree(self):
 
1028
        tree = self.make_branch_and_tree('')
 
1029
        self.build_tree(
 
1030
            ['/hello.txt', '/goodbye.txt'])
 
1031
        tree.add('hello.txt')
 
1032
        tree.commit(message='message1', committer='committer1', authors=['author1'])
 
1033
        tree.add('goodbye.txt')
 
1034
        tree.commit(message='message2', committer='committer2', authors=['author2'])
 
1035
    
 
1036
    def test_message(self):
 
1037
        self.prepare_tree()
 
1038
        self.assertLogRevnos(["-m", "message1"], ["1"])
 
1039
        self.assertLogRevnos(["-m", "message2"], ["2"])
 
1040
        self.assertLogRevnos(["-m", "message"], ["2", "1"])
 
1041
        self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
 
1042
        self.assertLogRevnos(["--match-message", "message1"], ["1"])
 
1043
        self.assertLogRevnos(["--match-message", "message2"], ["2"])
 
1044
        self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
 
1045
        self.assertLogRevnos(["--match-message", "message1", 
 
1046
                              "--match-message", "message2"], ["2", "1"])
 
1047
        self.assertLogRevnos(["--message", "message1"], ["1"])
 
1048
        self.assertLogRevnos(["--message", "message2"], ["2"])
 
1049
        self.assertLogRevnos(["--message", "message"], ["2", "1"])
 
1050
        self.assertLogRevnos(["--match-message", "message1", 
 
1051
                              "--message", "message2"], ["2", "1"])
 
1052
        self.assertLogRevnos(["--message", "message1", 
 
1053
                              "--match-message", "message2"], ["2", "1"])
 
1054
 
 
1055
    def test_committer(self):
 
1056
        self.prepare_tree()
 
1057
        self.assertLogRevnos(["-m", "committer1"], ["1"])
 
1058
        self.assertLogRevnos(["-m", "committer2"], ["2"])
 
1059
        self.assertLogRevnos(["-m", "committer"], ["2", "1"])
 
1060
        self.assertLogRevnos(["-m", "committer1", "-m", "committer2"], 
 
1061
                             ["2", "1"])
 
1062
        self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
 
1063
        self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
 
1064
        self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
 
1065
        self.assertLogRevnos(["--match-committer", "committer1", 
 
1066
                              "--match-committer", "committer2"], ["2", "1"])
 
1067
 
 
1068
    def test_author(self):
 
1069
        self.prepare_tree()
 
1070
        self.assertLogRevnos(["-m", "author1"], ["1"])
 
1071
        self.assertLogRevnos(["-m", "author2"], ["2"])
 
1072
        self.assertLogRevnos(["-m", "author"], ["2", "1"])
 
1073
        self.assertLogRevnos(["-m", "author1", "-m", "author2"], 
 
1074
                             ["2", "1"])
 
1075
        self.assertLogRevnos(["--match-author", "author1"], ["1"])
 
1076
        self.assertLogRevnos(["--match-author", "author2"], ["2"])
 
1077
        self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
 
1078
        self.assertLogRevnos(["--match-author", "author1", 
 
1079
                              "--match-author", "author2"], ["2", "1"])
 
1080
 
 
1081
 
 
1082
class TestSmartServerLog(tests.TestCaseWithTransport):
 
1083
 
 
1084
    def test_standard_log(self):
 
1085
        self.setup_smart_server_with_call_log()
 
1086
        t = self.make_branch_and_tree('branch')
 
1087
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1088
        t.add("foo")
 
1089
        t.commit("message")
 
1090
        self.reset_smart_call_log()
 
1091
        out, err = self.run_bzr(['log', self.get_url('branch')])
 
1092
        # This figure represent the amount of work to perform this use case. It
 
1093
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1094
        # being too low. If rpc_count increases, more network roundtrips have
 
1095
        # become necessary for this use case. Please do not adjust this number
 
1096
        # upwards without agreement from bzr's network support maintainers.
 
1097
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1098
        self.assertLength(1, self.hpss_connections)
 
1099
        self.assertLength(9, self.hpss_calls)
 
1100
 
 
1101
    def test_verbose_log(self):
 
1102
        self.setup_smart_server_with_call_log()
 
1103
        t = self.make_branch_and_tree('branch')
 
1104
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1105
        t.add("foo")
 
1106
        t.commit("message")
 
1107
        self.reset_smart_call_log()
 
1108
        out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
 
1109
        # This figure represent the amount of work to perform this use case. It
 
1110
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1111
        # being too low. If rpc_count increases, more network roundtrips have
 
1112
        # become necessary for this use case. Please do not adjust this number
 
1113
        # upwards without agreement from bzr's network support maintainers.
 
1114
        self.assertLength(10, self.hpss_calls)
 
1115
        self.assertLength(1, self.hpss_connections)
 
1116
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1117
 
 
1118
    def test_per_file(self):
 
1119
        self.setup_smart_server_with_call_log()
 
1120
        t = self.make_branch_and_tree('branch')
 
1121
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1122
        t.add("foo")
 
1123
        t.commit("message")
 
1124
        self.reset_smart_call_log()
 
1125
        out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
 
1126
        # This figure represent the amount of work to perform this use case. It
 
1127
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1128
        # being too low. If rpc_count increases, more network roundtrips have
 
1129
        # become necessary for this use case. Please do not adjust this number
 
1130
        # upwards without agreement from bzr's network support maintainers.
 
1131
        self.assertLength(14, self.hpss_calls)
 
1132
        self.assertLength(1, self.hpss_connections)
 
1133
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)