/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/blackbox/test_log.py

  • Committer: Martin
  • Date: 2018-11-16 19:10:17 UTC
  • mto: This revision was merged to the branch mainline in revision 7177.
  • Revision ID: gzlist@googlemail.com-20181116191017-kyedz1qck0ovon3h
Remove lazy_regexp reset in bt.test_source

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Black-box tests for brz log."""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
 
 
23
import os
 
24
 
 
25
from breezy import (
 
26
    branchbuilder,
 
27
    errors,
 
28
    log,
 
29
    osutils,
 
30
    tests,
 
31
    )
 
32
from breezy.sixish import PY3
 
33
from breezy.tests import (
 
34
    test_log,
 
35
    features,
 
36
    )
 
37
from breezy.tests.matchers import ContainsNoVfsCalls
 
38
 
 
39
 
 
40
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
 
41
 
 
42
    def make_minimal_branch(self, path='.', format=None):
 
43
        tree = self.make_branch_and_tree(path, format=format)
 
44
        self.build_tree([path + '/hello.txt'])
 
45
        tree.add('hello.txt')
 
46
        tree.commit(message='message1')
 
47
        return tree
 
48
 
 
49
    def make_linear_branch(self, path='.', format=None):
 
50
        tree = self.make_branch_and_tree(path, format=format)
 
51
        self.build_tree(
 
52
            [path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
 
53
        tree.add('hello.txt')
 
54
        tree.commit(message='message1')
 
55
        tree.add('goodbye.txt')
 
56
        tree.commit(message='message2')
 
57
        tree.add('meep.txt')
 
58
        tree.commit(message='message3')
 
59
        return tree
 
60
 
 
61
    def make_merged_branch(self, path='.', format=None):
 
62
        tree = self.make_linear_branch(path, format)
 
63
        tree2 = tree.controldir.sprout('tree2',
 
64
                                       revision_id=tree.branch.get_rev_id(1)).open_workingtree()
 
65
        tree2.commit(message='tree2 message2')
 
66
        tree2.commit(message='tree2 message3')
 
67
        tree.merge_from_branch(tree2.branch)
 
68
        tree.commit(message='merge')
 
69
        return tree
 
70
 
 
71
 
 
72
class TestLogWithLogCatcher(TestLog):
 
73
 
 
74
    def setUp(self):
 
75
        super(TestLogWithLogCatcher, self).setUp()
 
76
        # Capture log formatter creations
 
77
 
 
78
        class MyLogFormatter(test_log.LogCatcher):
 
79
 
 
80
            def __new__(klass, *args, **kwargs):
 
81
                self.log_catcher = test_log.LogCatcher(*args, **kwargs)
 
82
                # Always return our own log formatter
 
83
                return self.log_catcher
 
84
        # Break cycle with closure over self on cleanup by removing method
 
85
        self.addCleanup(setattr, MyLogFormatter, "__new__", None)
 
86
 
 
87
        def getme(branch):
 
88
                # Always return our own log formatter class hijacking the
 
89
                # default behavior (which requires setting up a config
 
90
                # variable)
 
91
            return MyLogFormatter
 
92
        self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
 
93
 
 
94
    def get_captured_revisions(self):
 
95
        return self.log_catcher.revisions
 
96
 
 
97
    def assertLogRevnos(self, args, expected_revnos, working_dir='.',
 
98
                        out='', err=''):
 
99
        actual_out, actual_err = self.run_bzr(['log'] + args,
 
100
                                              working_dir=working_dir)
 
101
        self.assertEqual(out, actual_out)
 
102
        self.assertEqual(err, actual_err)
 
103
        self.assertEqual(expected_revnos,
 
104
                         [r.revno for r in self.get_captured_revisions()])
 
105
 
 
106
    def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
 
107
                                 working_dir='.'):
 
108
        self.run_bzr(['log'] + args, working_dir=working_dir)
 
109
        self.assertEqual(expected_revnos_and_depths,
 
110
                         [(r.revno, r.merge_depth)
 
111
                          for r in self.get_captured_revisions()])
 
112
 
 
113
 
 
114
class TestLogRevSpecs(TestLogWithLogCatcher):
 
115
 
 
116
    def test_log_no_revspec(self):
 
117
        self.make_linear_branch()
 
118
        self.assertLogRevnos([], ['3', '2', '1'])
 
119
 
 
120
    def test_log_null_end_revspec(self):
 
121
        self.make_linear_branch()
 
122
        self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
 
123
 
 
124
    def test_log_null_begin_revspec(self):
 
125
        self.make_linear_branch()
 
126
        self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
 
127
 
 
128
    def test_log_null_both_revspecs(self):
 
129
        self.make_linear_branch()
 
130
        self.assertLogRevnos(['-r..'], ['3', '2', '1'])
 
131
 
 
132
    def test_log_negative_begin_revspec_full_log(self):
 
133
        self.make_linear_branch()
 
134
        self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
 
135
 
 
136
    def test_log_negative_both_revspec_full_log(self):
 
137
        self.make_linear_branch()
 
138
        self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
 
139
 
 
140
    def test_log_negative_both_revspec_partial(self):
 
141
        self.make_linear_branch()
 
142
        self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
 
143
 
 
144
    def test_log_negative_begin_revspec(self):
 
145
        self.make_linear_branch()
 
146
        self.assertLogRevnos(['-r-2..'], ['3', '2'])
 
147
 
 
148
    def test_log_positive_revspecs(self):
 
149
        self.make_linear_branch()
 
150
        self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
 
151
 
 
152
    def test_log_dotted_revspecs(self):
 
153
        self.make_merged_branch()
 
154
        self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
 
155
 
 
156
    def test_log_limit(self):
 
157
        tree = self.make_branch_and_tree('.')
 
158
        # We want more commits than our batch size starts at
 
159
        for pos in range(10):
 
160
            tree.commit("%s" % pos)
 
161
        self.assertLogRevnos(['--limit', '2'], ['10', '9'])
 
162
 
 
163
    def test_log_limit_short(self):
 
164
        self.make_linear_branch()
 
165
        self.assertLogRevnos(['-l', '2'], ['3', '2'])
 
166
 
 
167
    def test_log_change_revno(self):
 
168
        self.make_linear_branch()
 
169
        self.assertLogRevnos(['-c1'], ['1'])
 
170
 
 
171
    def test_branch_revspec(self):
 
172
        foo = self.make_branch_and_tree('foo')
 
173
        bar = self.make_branch_and_tree('bar')
 
174
        self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
 
175
        foo.add('foo.txt')
 
176
        bar.add('bar.txt')
 
177
        foo.commit(message='foo')
 
178
        bar.commit(message='bar')
 
179
        self.run_bzr('log -r branch:../bar', working_dir='foo')
 
180
        self.assertEqual([bar.branch.get_rev_id(1)],
 
181
                         [r.rev.revision_id
 
182
                          for r in self.get_captured_revisions()])
 
183
 
 
184
 
 
185
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
 
186
 
 
187
    def test_exclude_common_ancestry_simple_revnos(self):
 
188
        self.make_linear_branch()
 
189
        self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
 
190
                             ['3', '2'])
 
191
 
 
192
 
 
193
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
 
194
 
 
195
    def setUp(self):
 
196
        super(TestLogMergedLinearAncestry, self).setUp()
 
197
        # FIXME: Using a MemoryTree would be even better here (but until we
 
198
        # stop calling run_bzr, there is no point) --vila 100118.
 
199
        builder = branchbuilder.BranchBuilder(self.get_transport())
 
200
        builder.start_series()
 
201
        # 1
 
202
        # | \
 
203
        # 2  1.1.1
 
204
        # | / |
 
205
        # 3  1.1.2
 
206
        # |   |
 
207
        # |  1.1.3
 
208
        # | / |
 
209
        # 4  1.1.4
 
210
        # | /
 
211
        # 5
 
212
        # | \
 
213
        # | 5.1.1
 
214
        # | /
 
215
        # 6
 
216
 
 
217
        # mainline
 
218
        builder.build_snapshot(None, [
 
219
            ('add', ('', b'root-id', 'directory', ''))],
 
220
            revision_id=b'1')
 
221
        builder.build_snapshot([b'1'], [], revision_id=b'2')
 
222
        # branch
 
223
        builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
 
224
        # merge branch into mainline
 
225
        builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
 
226
        # new commits in branch
 
227
        builder.build_snapshot([b'1.1.1'], [], revision_id=b'1.1.2')
 
228
        builder.build_snapshot([b'1.1.2'], [], revision_id=b'1.1.3')
 
229
        # merge branch into mainline
 
230
        builder.build_snapshot([b'3', b'1.1.3'], [], revision_id=b'4')
 
231
        # merge mainline into branch
 
232
        builder.build_snapshot([b'1.1.3', b'4'], [], revision_id=b'1.1.4')
 
233
        # merge branch into mainline
 
234
        builder.build_snapshot([b'4', b'1.1.4'], [], revision_id=b'5')
 
235
        builder.build_snapshot([b'5'], [], revision_id=b'5.1.1')
 
236
        builder.build_snapshot([b'5', b'5.1.1'], [], revision_id=b'6')
 
237
        builder.finish_series()
 
238
 
 
239
    def test_n0(self):
 
240
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
 
241
                             ['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
 
242
 
 
243
    def test_n0_forward(self):
 
244
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
 
245
                             ['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
 
246
 
 
247
    def test_n1(self):
 
248
        # starting from 1.1.4 we follow the left-hand ancestry
 
249
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
 
250
                             ['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
 
251
 
 
252
    def test_n1_forward(self):
 
253
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
 
254
                             ['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
 
255
 
 
256
    def test_fallback_when_end_rev_is_not_on_mainline(self):
 
257
        self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
 
258
                             # We don't get 1.1.1 because we say -n1
 
259
                             ['5.1.1', '5', '4', '3'])
 
260
 
 
261
 
 
262
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
 
263
 
 
264
    def setUp(self):
 
265
        super(Test_GenerateAllRevisions, self).setUp()
 
266
        builder = self.make_branch_with_many_merges()
 
267
        b = builder.get_branch()
 
268
        b.lock_read()
 
269
        self.addCleanup(b.unlock)
 
270
        self.branch = b
 
271
 
 
272
    def make_branch_with_many_merges(self, path='.', format=None):
 
273
        builder = branchbuilder.BranchBuilder(self.get_transport())
 
274
        builder.start_series()
 
275
        # The graph below may look a bit complicated (and it may be but I've
 
276
        # banged my head enough on it) but the bug requires at least dotted
 
277
        # revnos *and* merged revisions below that.
 
278
        # 1
 
279
        # | \
 
280
        # 2  1.1.1
 
281
        # | X
 
282
        # 3  2.1.1
 
283
        # |   |    \
 
284
        # |  2.1.2  2.2.1
 
285
        # |   |    X
 
286
        # |  2.1.3  \
 
287
        # | /       /
 
288
        # 4        /
 
289
        # |       /
 
290
        # 5 -----/
 
291
        builder.build_snapshot(None, [
 
292
            ('add', ('', b'root-id', 'directory', ''))], revision_id=b'1')
 
293
        builder.build_snapshot([b'1'], [], revision_id=b'2')
 
294
        builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
 
295
        builder.build_snapshot([b'2'], [], revision_id=b'2.1.1')
 
296
        builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
 
297
        builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.1.2')
 
298
        builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.2.1')
 
299
        builder.build_snapshot([b'2.1.2', b'2.2.1'], [], revision_id=b'2.1.3')
 
300
        builder.build_snapshot([b'3', b'2.1.3'], [], revision_id=b'4')
 
301
        builder.build_snapshot([b'4', b'2.1.2'], [], revision_id=b'5')
 
302
        builder.finish_series()
 
303
        return builder
 
304
 
 
305
    def test_not_an_ancestor(self):
 
306
        self.assertRaises(errors.BzrCommandError,
 
307
                          log._generate_all_revisions,
 
308
                          self.branch, '1.1.1', '2.1.3', 'reverse',
 
309
                          delayed_graph_generation=True)
 
310
 
 
311
    def test_wrong_order(self):
 
312
        self.assertRaises(errors.BzrCommandError,
 
313
                          log._generate_all_revisions,
 
314
                          self.branch, '5', '2.1.3', 'reverse',
 
315
                          delayed_graph_generation=True)
 
316
 
 
317
    def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
 
318
        revs = log._generate_all_revisions(
 
319
            self.branch, None, '2.1.3',
 
320
            'reverse', delayed_graph_generation=True)
 
321
 
 
322
 
 
323
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
 
324
 
 
325
    def test_log_revno_n_path_wrong_namespace(self):
 
326
        self.make_linear_branch('branch1')
 
327
        self.make_linear_branch('branch2')
 
328
        # There is no guarantee that a path exist between two arbitrary
 
329
        # revisions.
 
330
        self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
 
331
 
 
332
    def test_log_revno_n_path_correct_order(self):
 
333
        self.make_linear_branch('branch2')
 
334
        self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
 
335
                             ['3', '2', '1'])
 
336
 
 
337
    def test_log_revno_n_path(self):
 
338
        self.make_linear_branch('branch2')
 
339
        self.assertLogRevnos(['-rrevno:1:branch2'],
 
340
                             ['1'])
 
341
        rev_props = self.log_catcher.revisions[0].rev.properties
 
342
        self.assertEqual('branch2', rev_props[u'branch-nick'])
 
343
 
 
344
 
 
345
class TestLogErrors(TestLog):
 
346
 
 
347
    def test_log_zero_revspec(self):
 
348
        self.make_minimal_branch()
 
349
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
 
350
                           ['log', '-r0'])
 
351
 
 
352
    def test_log_zero_begin_revspec(self):
 
353
        self.make_linear_branch()
 
354
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
 
355
                           ['log', '-r0..2'])
 
356
 
 
357
    def test_log_zero_end_revspec(self):
 
358
        self.make_linear_branch()
 
359
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
 
360
                           ['log', '-r-2..0'])
 
361
 
 
362
    def test_log_nonexistent_revno(self):
 
363
        self.make_minimal_branch()
 
364
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
 
365
                            "does not exist in branch:"],
 
366
                           ['log', '-r1234'])
 
367
 
 
368
    def test_log_nonexistent_dotted_revno(self):
 
369
        self.make_minimal_branch()
 
370
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
 
371
                            "does not exist in branch:"],
 
372
                           ['log', '-r123.123'])
 
373
 
 
374
    def test_log_change_nonexistent_revno(self):
 
375
        self.make_minimal_branch()
 
376
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
 
377
                            "does not exist in branch:"],
 
378
                           ['log', '-c1234'])
 
379
 
 
380
    def test_log_change_nonexistent_dotted_revno(self):
 
381
        self.make_minimal_branch()
 
382
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
 
383
                            "does not exist in branch:"],
 
384
                           ['log', '-c123.123'])
 
385
 
 
386
    def test_log_change_single_revno_only(self):
 
387
        self.make_minimal_branch()
 
388
        self.run_bzr_error(['brz: ERROR: Option --change does not'
 
389
                            ' accept revision ranges'],
 
390
                           ['log', '--change', '2..3'])
 
391
 
 
392
    def test_log_change_incompatible_with_revision(self):
 
393
        self.run_bzr_error(['brz: ERROR: --revision and --change'
 
394
                            ' are mutually exclusive'],
 
395
                           ['log', '--change', '2', '--revision', '3'])
 
396
 
 
397
    def test_log_nonexistent_file(self):
 
398
        self.make_minimal_branch()
 
399
        # files that don't exist in either the basis tree or working tree
 
400
        # should give an error
 
401
        out, err = self.run_bzr('log does-not-exist', retcode=3)
 
402
        self.assertContainsRe(err,
 
403
                              'Path unknown at end or start of revision range: '
 
404
                              'does-not-exist')
 
405
 
 
406
    def test_log_reversed_revspecs(self):
 
407
        self.make_linear_branch()
 
408
        self.run_bzr_error(('brz: ERROR: Start revision must be older than '
 
409
                            'the end revision.\n',),
 
410
                           ['log', '-r3..1'])
 
411
 
 
412
    def test_log_reversed_dotted_revspecs(self):
 
413
        self.make_merged_branch()
 
414
        self.run_bzr_error(('brz: ERROR: Start revision not found in '
 
415
                            'history of end revision.\n',),
 
416
                           "log -r 1.1.1..1")
 
417
 
 
418
    def test_log_bad_message_re(self):
 
419
        """Bad --message argument gives a sensible message
 
420
 
 
421
        See https://bugs.launchpad.net/bzr/+bug/251352
 
422
        """
 
423
        self.make_minimal_branch()
 
424
        out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
 
425
        self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
 
426
        self.assertNotContainsRe(err, "Unprintable exception")
 
427
        self.assertEqual(out, '')
 
428
 
 
429
    def test_log_unsupported_timezone(self):
 
430
        self.make_linear_branch()
 
431
        self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
 
432
                            'options are "utc", "original", "local".'],
 
433
                           ['log', '--timezone', 'foo'])
 
434
 
 
435
    def test_log_exclude_ancestry_no_range(self):
 
436
        self.make_linear_branch()
 
437
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
 
438
                            ' requires -r with two revisions'],
 
439
                           ['log', '--exclude-common-ancestry'])
 
440
 
 
441
    def test_log_exclude_ancestry_single_revision(self):
 
442
        self.make_merged_branch()
 
443
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
 
444
                            ' requires two different revisions'],
 
445
                           ['log', '--exclude-common-ancestry',
 
446
                            '-r1.1.1..1.1.1'])
 
447
 
 
448
 
 
449
class TestLogTags(TestLog):
 
450
 
 
451
    def test_log_with_tags(self):
 
452
        tree = self.make_linear_branch(format='dirstate-tags')
 
453
        branch = tree.branch
 
454
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
 
455
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
 
456
        branch.tags.set_tag('tag3', branch.last_revision())
 
457
 
 
458
        log = self.run_bzr("log -r-1")[0]
 
459
        self.assertTrue('tags: tag3' in log)
 
460
 
 
461
        log = self.run_bzr("log -r1")[0]
 
462
        # I guess that we can't know the order of tags in the output
 
463
        # since dicts are unordered, need to check both possibilities
 
464
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
 
465
 
 
466
    def test_merged_log_with_tags(self):
 
467
        branch1_tree = self.make_linear_branch('branch1',
 
468
                                               format='dirstate-tags')
 
469
        branch1 = branch1_tree.branch
 
470
        branch2_tree = branch1_tree.controldir.sprout(
 
471
            'branch2').open_workingtree()
 
472
        branch1_tree.commit(message='foobar', allow_pointless=True)
 
473
        branch1.tags.set_tag('tag1', branch1.last_revision())
 
474
        # tags don't propagate if we don't merge
 
475
        self.run_bzr('merge ../branch1', working_dir='branch2')
 
476
        branch2_tree.commit(message='merge branch 1')
 
477
        log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
 
478
        self.assertContainsRe(log, r'    tags: tag1')
 
479
        log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
 
480
        self.assertContainsRe(log, r'tags: tag1')
 
481
 
 
482
 
 
483
class TestLogSignatures(TestLog):
 
484
 
 
485
    def test_log_with_signatures(self):
 
486
        self.requireFeature(features.gpg)
 
487
 
 
488
        tree = self.make_linear_branch(format='dirstate-tags')
 
489
 
 
490
        log = self.run_bzr("log --signatures")[0]
 
491
        self.assertTrue('signature: no signature' in log)
 
492
 
 
493
    def test_log_without_signatures(self):
 
494
        self.requireFeature(features.gpg)
 
495
 
 
496
        tree = self.make_linear_branch(format='dirstate-tags')
 
497
 
 
498
        log = self.run_bzr("log")[0]
 
499
        self.assertFalse('signature: no signature' in log)
 
500
 
 
501
 
 
502
class TestLogVerbose(TestLog):
 
503
 
 
504
    def setUp(self):
 
505
        super(TestLogVerbose, self).setUp()
 
506
        self.make_minimal_branch()
 
507
 
 
508
    def assertUseShortDeltaFormat(self, cmd):
 
509
        log = self.run_bzr(cmd)[0]
 
510
        # Check that we use the short status format
 
511
        self.assertContainsRe(log, '(?m)^\\s*A  hello.txt$')
 
512
        self.assertNotContainsRe(log, '(?m)^\\s*added:$')
 
513
 
 
514
    def assertUseLongDeltaFormat(self, cmd):
 
515
        log = self.run_bzr(cmd)[0]
 
516
        # Check that we use the long status format
 
517
        self.assertNotContainsRe(log, '(?m)^\\s*A  hello.txt$')
 
518
        self.assertContainsRe(log, '(?m)^\\s*added:$')
 
519
 
 
520
    def test_log_short_verbose(self):
 
521
        self.assertUseShortDeltaFormat(['log', '--short', '-v'])
 
522
 
 
523
    def test_log_s_verbose(self):
 
524
        self.assertUseShortDeltaFormat(['log', '-S', '-v'])
 
525
 
 
526
    def test_log_short_verbose_verbose(self):
 
527
        self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
 
528
 
 
529
    def test_log_long_verbose(self):
 
530
        # Check that we use the long status format, ignoring the verbosity
 
531
        # level
 
532
        self.assertUseLongDeltaFormat(['log', '--long', '-v'])
 
533
 
 
534
    def test_log_long_verbose_verbose(self):
 
535
        # Check that we use the long status format, ignoring the verbosity
 
536
        # level
 
537
        self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
 
538
 
 
539
 
 
540
class TestLogMerges(TestLogWithLogCatcher):
 
541
 
 
542
    def setUp(self):
 
543
        super(TestLogMerges, self).setUp()
 
544
        self.make_branches_with_merges()
 
545
 
 
546
    def make_branches_with_merges(self):
 
547
        level0 = self.make_branch_and_tree('level0')
 
548
        self.wt_commit(level0, 'in branch level0')
 
549
        level1 = level0.controldir.sprout('level1').open_workingtree()
 
550
        self.wt_commit(level1, 'in branch level1')
 
551
        level2 = level1.controldir.sprout('level2').open_workingtree()
 
552
        self.wt_commit(level2, 'in branch level2')
 
553
        level1.merge_from_branch(level2.branch)
 
554
        self.wt_commit(level1, 'merge branch level2')
 
555
        level0.merge_from_branch(level1.branch)
 
556
        self.wt_commit(level0, 'merge branch level1')
 
557
 
 
558
    def test_merges_are_indented_by_level(self):
 
559
        self.run_bzr(['log', '-n0'], working_dir='level0')
 
560
        revnos_and_depth = [(r.revno, r.merge_depth)
 
561
                            for r in self.get_captured_revisions()]
 
562
        self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
 
563
                          ('1', 0)],
 
564
                         [(r.revno, r.merge_depth)
 
565
                          for r in self.get_captured_revisions()])
 
566
 
 
567
    def test_force_merge_revisions_off(self):
 
568
        self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
 
569
 
 
570
    def test_force_merge_revisions_on(self):
 
571
        self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
 
572
                             working_dir='level0')
 
573
 
 
574
    def test_include_merged(self):
 
575
        # Confirm --include-merged gives the same output as -n0
 
576
        expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
 
577
        self.assertLogRevnos(['--include-merged'],
 
578
                             expected, working_dir='level0')
 
579
        self.assertLogRevnos(['--include-merged'],
 
580
                             expected, working_dir='level0')
 
581
 
 
582
    def test_force_merge_revisions_N(self):
 
583
        self.assertLogRevnos(['-n2'],
 
584
                             ['2', '1.1.2', '1.1.1', '1'],
 
585
                             working_dir='level0')
 
586
 
 
587
    def test_merges_single_merge_rev(self):
 
588
        self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
 
589
                                      [('1.1.2', 0), ('1.2.1', 1)],
 
590
                                      working_dir='level0')
 
591
 
 
592
    def test_merges_partial_range(self):
 
593
        self.assertLogRevnosAndDepths(
 
594
            ['-n0', '-r1.1.1..1.1.2'],
 
595
            [('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
 
596
            working_dir='level0')
 
597
 
 
598
    def test_merges_partial_range_ignore_before_lower_bound(self):
 
599
        """Dont show revisions before the lower bound's merged revs"""
 
600
        self.assertLogRevnosAndDepths(
 
601
            ['-n0', '-r1.1.2..2'],
 
602
            [('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
 
603
            working_dir='level0')
 
604
 
 
605
    def test_omit_merges_with_sidelines(self):
 
606
        self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
 
607
                             working_dir='level0')
 
608
 
 
609
    def test_omit_merges_without_sidelines(self):
 
610
        self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
 
611
                             working_dir='level0')
 
612
 
 
613
 
 
614
class TestLogDiff(TestLogWithLogCatcher):
 
615
 
 
616
    # FIXME: We need specific tests for each LogFormatter about how the diffs
 
617
    # are displayed: --long indent them by depth, --short use a fixed
 
618
    # indent and --line does't display them. -- vila 10019
 
619
 
 
620
    def setUp(self):
 
621
        super(TestLogDiff, self).setUp()
 
622
        self.make_branch_with_diffs()
 
623
 
 
624
    def make_branch_with_diffs(self):
 
625
        level0 = self.make_branch_and_tree('level0')
 
626
        self.build_tree(['level0/file1', 'level0/file2'])
 
627
        level0.add('file1')
 
628
        level0.add('file2')
 
629
        self.wt_commit(level0, 'in branch level0')
 
630
 
 
631
        level1 = level0.controldir.sprout('level1').open_workingtree()
 
632
        self.build_tree_contents([('level1/file2', b'hello\n')])
 
633
        self.wt_commit(level1, 'in branch level1')
 
634
        level0.merge_from_branch(level1.branch)
 
635
        self.wt_commit(level0, 'merge branch level1')
 
636
 
 
637
    def _diff_file1_revno1(self):
 
638
        return b"""=== added file 'file1'
 
639
--- file1\t1970-01-01 00:00:00 +0000
 
640
+++ file1\t2005-11-22 00:00:00 +0000
 
641
@@ -0,0 +1,1 @@
 
642
+contents of level0/file1
 
643
 
 
644
"""
 
645
 
 
646
    def _diff_file2_revno2(self):
 
647
        return b"""=== modified file 'file2'
 
648
--- file2\t2005-11-22 00:00:00 +0000
 
649
+++ file2\t2005-11-22 00:00:01 +0000
 
650
@@ -1,1 +1,1 @@
 
651
-contents of level0/file2
 
652
+hello
 
653
 
 
654
"""
 
655
 
 
656
    def _diff_file2_revno1_1_1(self):
 
657
        return b"""=== modified file 'file2'
 
658
--- file2\t2005-11-22 00:00:00 +0000
 
659
+++ file2\t2005-11-22 00:00:01 +0000
 
660
@@ -1,1 +1,1 @@
 
661
-contents of level0/file2
 
662
+hello
 
663
 
 
664
"""
 
665
 
 
666
    def _diff_file2_revno1(self):
 
667
        return b"""=== added file 'file2'
 
668
--- file2\t1970-01-01 00:00:00 +0000
 
669
+++ file2\t2005-11-22 00:00:00 +0000
 
670
@@ -0,0 +1,1 @@
 
671
+contents of level0/file2
 
672
 
 
673
"""
 
674
 
 
675
    def assertLogRevnosAndDiff(self, args, expected,
 
676
                               working_dir='.'):
 
677
        self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
 
678
        expected_revnos_and_depths = [
 
679
            (revno, depth) for revno, depth, diff in expected]
 
680
        # Check the revnos and depths first to make debugging easier
 
681
        self.assertEqual(expected_revnos_and_depths,
 
682
                         [(r.revno, r.merge_depth)
 
683
                          for r in self.get_captured_revisions()])
 
684
        # Now check the diffs, adding the revno  in case of failure
 
685
        fmt = 'In revno %s\n%s'
 
686
        for expected_rev, actual_rev in zip(expected,
 
687
                                            self.get_captured_revisions()):
 
688
            revno, depth, expected_diff = expected_rev
 
689
            actual_diff = actual_rev.diff
 
690
            self.assertEqualDiff(fmt % (revno, expected_diff),
 
691
                                 fmt % (revno, actual_diff))
 
692
 
 
693
    def test_log_diff_with_merges(self):
 
694
        self.assertLogRevnosAndDiff(
 
695
            ['-n0'],
 
696
            [('2', 0, self._diff_file2_revno2()),
 
697
             ('1.1.1', 1, self._diff_file2_revno1_1_1()),
 
698
             ('1', 0, self._diff_file1_revno1() +
 
699
              self._diff_file2_revno1())],
 
700
            working_dir='level0')
 
701
 
 
702
    def test_log_diff_file1(self):
 
703
        self.assertLogRevnosAndDiff(['-n0', 'file1'],
 
704
                                    [('1', 0, self._diff_file1_revno1())],
 
705
                                    working_dir='level0')
 
706
 
 
707
    def test_log_diff_file2(self):
 
708
        self.assertLogRevnosAndDiff(['-n1', 'file2'],
 
709
                                    [('2', 0, self._diff_file2_revno2()),
 
710
                                     ('1', 0, self._diff_file2_revno1())],
 
711
                                    working_dir='level0')
 
712
 
 
713
 
 
714
class TestLogUnicodeDiff(TestLog):
 
715
 
 
716
    def test_log_show_diff_non_ascii(self):
 
717
        # Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
 
718
        message = u'Message with \xb5'
 
719
        body = b'Body with \xb5\n'
 
720
        wt = self.make_branch_and_tree('.')
 
721
        self.build_tree_contents([('foo', body)])
 
722
        wt.add('foo')
 
723
        wt.commit(message=message)
 
724
        # check that command won't fail with unicode error
 
725
        # don't care about exact output because we have other tests for this
 
726
        out, err = self.run_bzr('log -p --long')
 
727
        self.assertNotEqual('', out)
 
728
        self.assertEqual('', err)
 
729
        out, err = self.run_bzr('log -p --short')
 
730
        self.assertNotEqual('', out)
 
731
        self.assertEqual('', err)
 
732
        out, err = self.run_bzr('log -p --line')
 
733
        self.assertNotEqual('', out)
 
734
        self.assertEqual('', err)
 
735
 
 
736
 
 
737
class TestLogEncodings(tests.TestCaseInTempDir):
 
738
 
 
739
    _mu = u'\xb5'
 
740
    _message = u'Message with \xb5'
 
741
 
 
742
    # Encodings which can encode mu
 
743
    good_encodings = [
 
744
        'utf-8',
 
745
        'latin-1',
 
746
        'iso-8859-1',
 
747
        'cp437',  # Common windows encoding
 
748
        'cp1251',  # Russian windows encoding
 
749
        'cp1258',  # Common windows encoding
 
750
    ]
 
751
    # Encodings which cannot encode mu
 
752
    bad_encodings = [
 
753
        'ascii',
 
754
        'iso-8859-2',
 
755
        'koi8_r',
 
756
    ]
 
757
 
 
758
    def setUp(self):
 
759
        super(TestLogEncodings, self).setUp()
 
760
        self.overrideAttr(osutils, '_cached_user_encoding')
 
761
 
 
762
    def create_branch(self):
 
763
        brz = self.run_bzr
 
764
        brz('init')
 
765
        self.build_tree_contents([('a', b'some stuff\n')])
 
766
        brz('add a')
 
767
        brz(['commit', '-m', self._message])
 
768
 
 
769
    def try_encoding(self, encoding, fail=False):
 
770
        brz = self.run_bzr
 
771
        if fail:
 
772
            self.assertRaises(UnicodeEncodeError,
 
773
                              self._mu.encode, encoding)
 
774
            encoded_msg = self._message.encode(encoding, 'replace')
 
775
        else:
 
776
            encoded_msg = self._message.encode(encoding)
 
777
 
 
778
        old_encoding = osutils._cached_user_encoding
 
779
        # This test requires that 'run_bzr' uses the current
 
780
        # breezy, because we override user_encoding, and expect
 
781
        # it to be used
 
782
        try:
 
783
            osutils._cached_user_encoding = 'ascii'
 
784
            # We should be able to handle any encoding
 
785
            out, err = brz('log', encoding=encoding)
 
786
            if not fail:
 
787
                # Make sure we wrote mu as we expected it to exist
 
788
                if not PY3:
 
789
                    self.assertNotEqual(-1, out.find(encoded_msg))
 
790
                    out_unicode = out.decode(encoding)
 
791
                else:
 
792
                    out_unicode = out
 
793
                self.assertNotEqual(-1, out_unicode.find(self._message))
 
794
            else:
 
795
                self.assertNotEqual(-1, out.find('Message with ?'))
 
796
        finally:
 
797
            osutils._cached_user_encoding = old_encoding
 
798
 
 
799
    def test_log_handles_encoding(self):
 
800
        self.create_branch()
 
801
 
 
802
        for encoding in self.good_encodings:
 
803
            self.try_encoding(encoding)
 
804
 
 
805
    def test_log_handles_bad_encoding(self):
 
806
        self.create_branch()
 
807
 
 
808
        for encoding in self.bad_encodings:
 
809
            self.try_encoding(encoding, fail=True)
 
810
 
 
811
    def test_stdout_encoding(self):
 
812
        brz = self.run_bzr
 
813
        osutils._cached_user_encoding = "cp1251"
 
814
 
 
815
        brz('init')
 
816
        self.build_tree(['a'])
 
817
        brz('add a')
 
818
        brz(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
 
819
        stdout, stderr = self.run_bzr_raw('log', encoding='cp866')
 
820
 
 
821
        message = stdout.splitlines()[-1]
 
822
 
 
823
        # explanation of the check:
 
824
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
 
825
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
 
826
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
 
827
        # This test should check that output of log command
 
828
        # encoded to sys.stdout.encoding
 
829
        test_in_cp866 = b'\x92\xa5\xe1\xe2'
 
830
        test_in_cp1251 = b'\xd2\xe5\xf1\xf2'
 
831
        # Make sure the log string is encoded in cp866
 
832
        self.assertEqual(test_in_cp866, message[2:])
 
833
        # Make sure the cp1251 string is not found anywhere
 
834
        self.assertEqual(-1, stdout.find(test_in_cp1251))
 
835
 
 
836
 
 
837
class TestLogFile(TestLogWithLogCatcher):
 
838
 
 
839
    def test_log_local_branch_file(self):
 
840
        """We should be able to log files in local treeless branches"""
 
841
        tree = self.make_branch_and_tree('tree')
 
842
        self.build_tree(['tree/file'])
 
843
        tree.add('file')
 
844
        tree.commit('revision 1')
 
845
        tree.controldir.destroy_workingtree()
 
846
        self.run_bzr('log tree/file')
 
847
 
 
848
    def prepare_tree(self, complex=False):
 
849
        # The complex configuration includes deletes and renames
 
850
        tree = self.make_branch_and_tree('parent')
 
851
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
 
852
        tree.add('file1')
 
853
        tree.commit('add file1')
 
854
        tree.add('file2')
 
855
        tree.commit('add file2')
 
856
        tree.add('file3')
 
857
        tree.commit('add file3')
 
858
        child_tree = tree.controldir.sprout('child').open_workingtree()
 
859
        self.build_tree_contents([('child/file2', b'hello')])
 
860
        child_tree.commit(message='branch 1')
 
861
        tree.merge_from_branch(child_tree.branch)
 
862
        tree.commit(message='merge child branch')
 
863
        if complex:
 
864
            tree.remove('file2')
 
865
            tree.commit('remove file2')
 
866
            tree.rename_one('file3', 'file4')
 
867
            tree.commit('file3 is now called file4')
 
868
            tree.remove('file1')
 
869
            tree.commit('remove file1')
 
870
        os.chdir('parent')
 
871
 
 
872
    # FIXME: It would be good to parametrize the following tests against all
 
873
    # formatters. But the revisions selection is not *currently* part of the
 
874
    # LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
 
875
    def test_log_file1(self):
 
876
        self.prepare_tree()
 
877
        self.assertLogRevnos(['-n0', 'file1'], ['1'])
 
878
 
 
879
    def test_log_file2(self):
 
880
        self.prepare_tree()
 
881
        # file2 full history
 
882
        self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
 
883
        # file2 in a merge revision
 
884
        self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
 
885
        # file2 in a mainline revision
 
886
        self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
 
887
        # file2 since a revision
 
888
        self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
 
889
        # file2 up to a revision
 
890
        self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
 
891
 
 
892
    def test_log_file3(self):
 
893
        self.prepare_tree()
 
894
        self.assertLogRevnos(['-n0', 'file3'], ['3'])
 
895
 
 
896
    def test_log_file_historical_missing(self):
 
897
        # Check logging a deleted file gives an error if the
 
898
        # file isn't found at the end or start of the revision range
 
899
        self.prepare_tree(complex=True)
 
900
        err_msg = "Path unknown at end or start of revision range: file2"
 
901
        err = self.run_bzr('log file2', retcode=3)[1]
 
902
        self.assertContainsRe(err, err_msg)
 
903
 
 
904
    def test_log_file_historical_end(self):
 
905
        # Check logging a deleted file is ok if the file existed
 
906
        # at the end the revision range
 
907
        self.prepare_tree(complex=True)
 
908
        self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
 
909
 
 
910
    def test_log_file_historical_start(self):
 
911
        # Check logging a deleted file is ok if the file existed
 
912
        # at the start of the revision range
 
913
        self.prepare_tree(complex=True)
 
914
        self.assertLogRevnos(['file1'], ['1'])
 
915
 
 
916
    def test_log_file_renamed(self):
 
917
        """File matched against revision range, not current tree."""
 
918
        self.prepare_tree(complex=True)
 
919
 
 
920
        # Check logging a renamed file gives an error by default
 
921
        err_msg = "Path unknown at end or start of revision range: file3"
 
922
        err = self.run_bzr('log file3', retcode=3)[1]
 
923
        self.assertContainsRe(err, err_msg)
 
924
 
 
925
        # Check we can see a renamed file if we give the right end revision
 
926
        self.assertLogRevnos(['-r..4', 'file3'], ['3'])
 
927
 
 
928
 
 
929
class TestLogMultiple(TestLogWithLogCatcher):
 
930
 
 
931
    def prepare_tree(self):
 
932
        tree = self.make_branch_and_tree('parent')
 
933
        self.build_tree([
 
934
            'parent/file1',
 
935
            'parent/file2',
 
936
            'parent/dir1/',
 
937
            'parent/dir1/file5',
 
938
            'parent/dir1/dir2/',
 
939
            'parent/dir1/dir2/file3',
 
940
            'parent/file4'])
 
941
        tree.add('file1')
 
942
        tree.commit('add file1')
 
943
        tree.add('file2')
 
944
        tree.commit('add file2')
 
945
        tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
 
946
        tree.commit('add file3')
 
947
        tree.add('file4')
 
948
        tree.commit('add file4')
 
949
        tree.add('dir1/file5')
 
950
        tree.commit('add file5')
 
951
        child_tree = tree.controldir.sprout('child').open_workingtree()
 
952
        self.build_tree_contents([('child/file2', b'hello')])
 
953
        child_tree.commit(message='branch 1')
 
954
        tree.merge_from_branch(child_tree.branch)
 
955
        tree.commit(message='merge child branch')
 
956
        os.chdir('parent')
 
957
 
 
958
    def test_log_files(self):
 
959
        """The log for multiple file should only list revs for those files"""
 
960
        self.prepare_tree()
 
961
        self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
 
962
                             ['6', '5.1.1', '3', '2', '1'])
 
963
 
 
964
    def test_log_directory(self):
 
965
        """The log for a directory should show all nested files."""
 
966
        self.prepare_tree()
 
967
        self.assertLogRevnos(['dir1'], ['5', '3'])
 
968
 
 
969
    def test_log_nested_directory(self):
 
970
        """The log for a directory should show all nested files."""
 
971
        self.prepare_tree()
 
972
        self.assertLogRevnos(['dir1/dir2'], ['3'])
 
973
 
 
974
    def test_log_in_nested_directory(self):
 
975
        """The log for a directory should show all nested files."""
 
976
        self.prepare_tree()
 
977
        os.chdir("dir1")
 
978
        self.assertLogRevnos(['.'], ['5', '3'])
 
979
 
 
980
    def test_log_files_and_directories(self):
 
981
        """Logging files and directories together should be fine."""
 
982
        self.prepare_tree()
 
983
        self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
 
984
 
 
985
    def test_log_files_and_dirs_in_nested_directory(self):
 
986
        """The log for a directory should show all nested files."""
 
987
        self.prepare_tree()
 
988
        os.chdir("dir1")
 
989
        self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
 
990
 
 
991
 
 
992
class MainlineGhostTests(TestLogWithLogCatcher):
 
993
 
 
994
    def setUp(self):
 
995
        super(MainlineGhostTests, self).setUp()
 
996
        tree = self.make_branch_and_tree('')
 
997
        tree.set_parent_ids([b"spooky"], allow_leftmost_as_ghost=True)
 
998
        tree.add('')
 
999
        tree.commit('msg1', rev_id=b'rev1')
 
1000
        tree.commit('msg2', rev_id=b'rev2')
 
1001
 
 
1002
    def test_log_range(self):
 
1003
        self.assertLogRevnos(["-r1..2"], ["2", "1"])
 
1004
 
 
1005
    def test_log_norange(self):
 
1006
        self.assertLogRevnos([], ["2", "1"])
 
1007
 
 
1008
    def test_log_range_open_begin(self):
 
1009
        (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
 
1010
        self.assertEqual(["2", "1"],
 
1011
                         [r.revno for r in self.get_captured_revisions()])
 
1012
        self.assertEqual("brz: ERROR: Further revision history missing.\n",
 
1013
                         stderr)
 
1014
 
 
1015
    def test_log_range_open_end(self):
 
1016
        self.assertLogRevnos(["-r1.."], ["2", "1"])
 
1017
 
 
1018
 
 
1019
class TestLogMatch(TestLogWithLogCatcher):
 
1020
 
 
1021
    def prepare_tree(self):
 
1022
        tree = self.make_branch_and_tree('')
 
1023
        self.build_tree(
 
1024
            ['/hello.txt', '/goodbye.txt'])
 
1025
        tree.add('hello.txt')
 
1026
        tree.commit(message='message1', committer='committer1',
 
1027
                    authors=['author1'])
 
1028
        tree.add('goodbye.txt')
 
1029
        tree.commit(message='message2', committer='committer2',
 
1030
                    authors=['author2'])
 
1031
 
 
1032
    def test_message(self):
 
1033
        self.prepare_tree()
 
1034
        self.assertLogRevnos(["-m", "message1"], ["1"])
 
1035
        self.assertLogRevnos(["-m", "message2"], ["2"])
 
1036
        self.assertLogRevnos(["-m", "message"], ["2", "1"])
 
1037
        self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
 
1038
        self.assertLogRevnos(["--match-message", "message1"], ["1"])
 
1039
        self.assertLogRevnos(["--match-message", "message2"], ["2"])
 
1040
        self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
 
1041
        self.assertLogRevnos(["--match-message", "message1",
 
1042
                              "--match-message", "message2"], ["2", "1"])
 
1043
        self.assertLogRevnos(["--message", "message1"], ["1"])
 
1044
        self.assertLogRevnos(["--message", "message2"], ["2"])
 
1045
        self.assertLogRevnos(["--message", "message"], ["2", "1"])
 
1046
        self.assertLogRevnos(["--match-message", "message1",
 
1047
                              "--message", "message2"], ["2", "1"])
 
1048
        self.assertLogRevnos(["--message", "message1",
 
1049
                              "--match-message", "message2"], ["2", "1"])
 
1050
 
 
1051
    def test_committer(self):
 
1052
        self.prepare_tree()
 
1053
        self.assertLogRevnos(["-m", "committer1"], ["1"])
 
1054
        self.assertLogRevnos(["-m", "committer2"], ["2"])
 
1055
        self.assertLogRevnos(["-m", "committer"], ["2", "1"])
 
1056
        self.assertLogRevnos(["-m", "committer1", "-m", "committer2"],
 
1057
                             ["2", "1"])
 
1058
        self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
 
1059
        self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
 
1060
        self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
 
1061
        self.assertLogRevnos(["--match-committer", "committer1",
 
1062
                              "--match-committer", "committer2"], ["2", "1"])
 
1063
 
 
1064
    def test_author(self):
 
1065
        self.prepare_tree()
 
1066
        self.assertLogRevnos(["-m", "author1"], ["1"])
 
1067
        self.assertLogRevnos(["-m", "author2"], ["2"])
 
1068
        self.assertLogRevnos(["-m", "author"], ["2", "1"])
 
1069
        self.assertLogRevnos(["-m", "author1", "-m", "author2"],
 
1070
                             ["2", "1"])
 
1071
        self.assertLogRevnos(["--match-author", "author1"], ["1"])
 
1072
        self.assertLogRevnos(["--match-author", "author2"], ["2"])
 
1073
        self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
 
1074
        self.assertLogRevnos(["--match-author", "author1",
 
1075
                              "--match-author", "author2"], ["2", "1"])
 
1076
 
 
1077
 
 
1078
class TestSmartServerLog(tests.TestCaseWithTransport):
 
1079
 
 
1080
    def test_standard_log(self):
 
1081
        self.setup_smart_server_with_call_log()
 
1082
        t = self.make_branch_and_tree('branch')
 
1083
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
1084
        t.add("foo")
 
1085
        t.commit("message")
 
1086
        self.reset_smart_call_log()
 
1087
        out, err = self.run_bzr(['log', self.get_url('branch')])
 
1088
        # This figure represent the amount of work to perform this use case. It
 
1089
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1090
        # being too low. If rpc_count increases, more network roundtrips have
 
1091
        # become necessary for this use case. Please do not adjust this number
 
1092
        # upwards without agreement from bzr's network support maintainers.
 
1093
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1094
        self.assertLength(1, self.hpss_connections)
 
1095
        self.assertLength(9, self.hpss_calls)
 
1096
 
 
1097
    def test_verbose_log(self):
 
1098
        self.setup_smart_server_with_call_log()
 
1099
        t = self.make_branch_and_tree('branch')
 
1100
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
1101
        t.add("foo")
 
1102
        t.commit("message")
 
1103
        self.reset_smart_call_log()
 
1104
        out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
 
1105
        # This figure represent the amount of work to perform this use case. It
 
1106
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1107
        # being too low. If rpc_count increases, more network roundtrips have
 
1108
        # become necessary for this use case. Please do not adjust this number
 
1109
        # upwards without agreement from bzr's network support maintainers.
 
1110
        self.assertLength(10, self.hpss_calls)
 
1111
        self.assertLength(1, self.hpss_connections)
 
1112
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1113
 
 
1114
    def test_per_file(self):
 
1115
        self.setup_smart_server_with_call_log()
 
1116
        t = self.make_branch_and_tree('branch')
 
1117
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
1118
        t.add("foo")
 
1119
        t.commit("message")
 
1120
        self.reset_smart_call_log()
 
1121
        out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
 
1122
        # This figure represent the amount of work to perform this use case. It
 
1123
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1124
        # being too low. If rpc_count increases, more network roundtrips have
 
1125
        # become necessary for this use case. Please do not adjust this number
 
1126
        # upwards without agreement from bzr's network support maintainers.
 
1127
        self.assertLength(14, self.hpss_calls)
 
1128
        self.assertLength(1, self.hpss_connections)
 
1129
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)