~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: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import (
 
21
    branchbuilder,
21
22
    errors,
22
23
    log,
23
24
    registry,
24
25
    revision,
25
26
    revisionspec,
 
27
    symbol_versioning,
26
28
    tests,
27
29
    )
28
30
 
29
31
 
30
 
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
 
32
class TestLogMixin(object):
 
33
 
 
34
    def wt_commit(self, wt, message, **kwargs):
 
35
        """Use some mostly fixed values for commits to simplify tests.
 
36
 
 
37
        Tests can use this function to get some commit attributes. The time
 
38
        stamp is incremented at each commit.
 
39
        """
 
40
        if getattr(self, 'timestamp', None) is None:
 
41
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
 
42
        else:
 
43
            self.timestamp += 1 # 1 second between each commit
 
44
        kwargs.setdefault('timestamp', self.timestamp)
 
45
        kwargs.setdefault('timezone', 0) # UTC
 
46
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
 
47
 
 
48
        return wt.commit(message, **kwargs)
 
49
 
 
50
 
 
51
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
31
52
 
32
53
    def setUp(self):
33
 
        super(TestCaseWithoutPropsHandler, self).setUp()
 
54
        super(TestCaseForLogFormatter, self).setUp()
34
55
        # keep a reference to the "current" custom prop. handler registry
35
56
        self.properties_handler_registry = log.properties_handler_registry
36
57
        # Use a clean registry for log
40
61
            log.properties_handler_registry = self.properties_handler_registry
41
62
        self.addCleanup(restore)
42
63
 
 
64
    def assertFormatterResult(self, result, branch, formatter_class,
 
65
                              formatter_kwargs=None, show_log_kwargs=None):
 
66
        logfile = self.make_utf8_encoded_stringio()
 
67
        if formatter_kwargs is None:
 
68
            formatter_kwargs = {}
 
69
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
 
70
        if show_log_kwargs is None:
 
71
            show_log_kwargs = {}
 
72
        log.show_log(branch, formatter, **show_log_kwargs)
 
73
        self.assertEqualDiff(result, logfile.getvalue())
 
74
 
 
75
    def make_standard_commit(self, branch_nick, **kwargs):
 
76
        wt = self.make_branch_and_tree('.')
 
77
        wt.lock_write()
 
78
        self.addCleanup(wt.unlock)
 
79
        self.build_tree(['a'])
 
80
        wt.add(['a'])
 
81
        wt.branch.nick = branch_nick
 
82
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
 
83
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
 
84
        self.wt_commit(wt, 'add a', **kwargs)
 
85
        return wt
 
86
 
 
87
    def make_commits_with_trailing_newlines(self, wt):
 
88
        """Helper method for LogFormatter tests"""
 
89
        b = wt.branch
 
90
        b.nick = 'test'
 
91
        self.build_tree_contents([('a', 'hello moto\n')])
 
92
        self.wt_commit(wt, 'simple log message', rev_id='a1')
 
93
        self.build_tree_contents([('b', 'goodbye\n')])
 
94
        wt.add('b')
 
95
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
 
96
 
 
97
        self.build_tree_contents([('c', 'just another manic monday\n')])
 
98
        wt.add('c')
 
99
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
 
100
        return b
 
101
 
 
102
    def _prepare_tree_with_merges(self, with_tags=False):
 
103
        wt = self.make_branch_and_memory_tree('.')
 
104
        wt.lock_write()
 
105
        self.addCleanup(wt.unlock)
 
106
        wt.add('')
 
107
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
 
108
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
 
109
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
110
        wt.branch.set_last_revision_info(1, 'rev-1')
 
111
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
 
112
        if with_tags:
 
113
            branch = wt.branch
 
114
            branch.tags.set_tag('v0.2', 'rev-2b')
 
115
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
 
116
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
117
            branch.tags.set_tag('v1.0', 'rev-3')
 
118
        return wt
43
119
 
44
120
class LogCatcher(log.LogFormatter):
45
121
    """Pull log messages into a list rather than displaying them.
49
125
    being dependent on the formatting.
50
126
    """
51
127
 
 
128
    supports_merge_revisions = True
52
129
    supports_delta = True
 
130
    supports_diff = True
 
131
    preferred_levels = 0
53
132
 
54
 
    def __init__(self):
55
 
        super(LogCatcher, self).__init__(to_file=None)
 
133
    def __init__(self, *args, **kwargs):
 
134
        kwargs.update(dict(to_file=None))
 
135
        super(LogCatcher, self).__init__(*args, **kwargs)
56
136
        self.revisions = []
57
137
 
58
138
    def log_revision(self, revision):
142
222
        lf = LogCatcher()
143
223
        log.show_log(wt.branch, lf, verbose=True)
144
224
        committed_msg = lf.revisions[0].rev.message
145
 
        self.assertNotEqual(msg, committed_msg)
146
 
        self.assertTrue(len(committed_msg) > len(msg))
 
225
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
 
226
            self.assertNotEqual(msg, committed_msg)
 
227
            self.assertTrue(len(committed_msg) > len(msg))
 
228
        else:
 
229
            self.assertEqual(msg, committed_msg)
147
230
 
148
231
    def test_commit_message_without_control_chars(self):
149
232
        wt = self.make_branch_and_tree('.')
198
281
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
199
282
 
200
283
 
201
 
def make_commits_with_trailing_newlines(wt):
202
 
    """Helper method for LogFormatter tests"""
203
 
    b = wt.branch
204
 
    b.nick='test'
205
 
    open('a', 'wb').write('hello moto\n')
206
 
    wt.add('a')
207
 
    wt.commit('simple log message', rev_id='a1',
208
 
              timestamp=1132586655.459960938, timezone=-6*3600,
209
 
              committer='Joe Foo <joe@foo.com>')
210
 
    open('b', 'wb').write('goodbye\n')
211
 
    wt.add('b')
212
 
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
213
 
              timestamp=1132586842.411175966, timezone=-6*3600,
214
 
              committer='Joe Foo <joe@foo.com>',
215
 
              authors=['Joe Bar <joe@bar.com>'])
216
 
 
217
 
    open('c', 'wb').write('just another manic monday\n')
218
 
    wt.add('c')
219
 
    wt.commit('single line with trailing newline\n', rev_id='a3',
220
 
              timestamp=1132587176.835228920, timezone=-6*3600,
221
 
              committer = 'Joe Foo <joe@foo.com>')
222
 
    return b
223
 
 
224
 
 
225
 
def normalize_log(log):
226
 
    """Replaces the variable lines of logs with fixed lines"""
227
 
    author = 'author: Dolor Sit <test@example.com>'
228
 
    committer = 'committer: Lorem Ipsum <test@example.com>'
229
 
    lines = log.splitlines(True)
230
 
    for idx,line in enumerate(lines):
231
 
        stripped_line = line.lstrip()
232
 
        indent = ' ' * (len(line) - len(stripped_line))
233
 
        if stripped_line.startswith('author:'):
234
 
            lines[idx] = indent + author + '\n'
235
 
        elif stripped_line.startswith('committer:'):
236
 
            lines[idx] = indent + committer + '\n'
237
 
        elif stripped_line.startswith('timestamp:'):
238
 
            lines[idx] = indent + 'timestamp: Just now\n'
239
 
    return ''.join(lines)
240
 
 
241
 
 
242
 
class TestShortLogFormatter(tests.TestCaseWithTransport):
 
284
class TestShortLogFormatter(TestCaseForLogFormatter):
243
285
 
244
286
    def test_trailing_newlines(self):
245
287
        wt = self.make_branch_and_tree('.')
246
 
        b = make_commits_with_trailing_newlines(wt)
247
 
        sio = self.make_utf8_encoded_stringio()
248
 
        lf = log.ShortLogFormatter(to_file=sio)
249
 
        log.show_log(b, lf)
250
 
        self.assertEqualDiff("""\
251
 
    3 Joe Foo\t2005-11-21
 
288
        b = self.make_commits_with_trailing_newlines(wt)
 
289
        self.assertFormatterResult("""\
 
290
    3 Joe Foo\t2005-11-22
252
291
      single line with trailing newline
253
292
 
254
 
    2 Joe Bar\t2005-11-21
 
293
    2 Joe Foo\t2005-11-22
255
294
      multiline
256
295
      log
257
296
      message
258
297
 
259
 
    1 Joe Foo\t2005-11-21
 
298
    1 Joe Foo\t2005-11-22
260
299
      simple log message
261
300
 
262
301
""",
263
 
                             sio.getvalue())
264
 
 
265
 
    def _prepare_tree_with_merges(self, with_tags=False):
266
 
        wt = self.make_branch_and_memory_tree('.')
267
 
        wt.lock_write()
268
 
        self.addCleanup(wt.unlock)
269
 
        wt.add('')
270
 
        wt.commit('rev-1', rev_id='rev-1',
271
 
                  timestamp=1132586655, timezone=36000,
272
 
                  committer='Joe Foo <joe@foo.com>')
273
 
        wt.commit('rev-merged', rev_id='rev-2a',
274
 
                  timestamp=1132586700, timezone=36000,
275
 
                  committer='Joe Foo <joe@foo.com>')
276
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
277
 
        wt.branch.set_last_revision_info(1, 'rev-1')
278
 
        wt.commit('rev-2', rev_id='rev-2b',
279
 
                  timestamp=1132586800, timezone=36000,
280
 
                  committer='Joe Foo <joe@foo.com>')
281
 
        if with_tags:
282
 
            branch = wt.branch
283
 
            branch.tags.set_tag('v0.2', 'rev-2b')
284
 
            wt.commit('rev-3', rev_id='rev-3',
285
 
                      timestamp=1132586900, timezone=36000,
286
 
                      committer='Jane Foo <jane@foo.com>')
287
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
288
 
            branch.tags.set_tag('v1.0', 'rev-3')
289
 
        return wt
 
302
            b, log.ShortLogFormatter)
290
303
 
291
304
    def test_short_log_with_merges(self):
292
305
        wt = self._prepare_tree_with_merges()
293
 
        logfile = self.make_utf8_encoded_stringio()
294
 
        formatter = log.ShortLogFormatter(to_file=logfile)
295
 
        log.show_log(wt.branch, formatter)
296
 
        self.assertEqualDiff("""\
 
306
        self.assertFormatterResult("""\
297
307
    2 Joe Foo\t2005-11-22 [merge]
298
308
      rev-2
299
309
 
301
311
      rev-1
302
312
 
303
313
""",
304
 
                             logfile.getvalue())
 
314
            wt.branch, log.ShortLogFormatter)
305
315
 
306
316
    def test_short_log_with_merges_and_advice(self):
307
317
        wt = self._prepare_tree_with_merges()
308
 
        logfile = self.make_utf8_encoded_stringio()
309
 
        formatter = log.ShortLogFormatter(to_file=logfile,
310
 
            show_advice=True)
311
 
        log.show_log(wt.branch, formatter)
312
 
        self.assertEqualDiff("""\
 
318
        self.assertFormatterResult("""\
313
319
    2 Joe Foo\t2005-11-22 [merge]
314
320
      rev-2
315
321
 
318
324
 
319
325
Use --include-merges or -n0 to see merged revisions.
320
326
""",
321
 
                             logfile.getvalue())
 
327
            wt.branch, log.ShortLogFormatter,
 
328
            formatter_kwargs=dict(show_advice=True))
322
329
 
323
330
    def test_short_log_with_merges_and_range(self):
324
 
        wt = self.make_branch_and_memory_tree('.')
325
 
        wt.lock_write()
326
 
        self.addCleanup(wt.unlock)
327
 
        wt.add('')
328
 
        wt.commit('rev-1', rev_id='rev-1',
329
 
                  timestamp=1132586655, timezone=36000,
330
 
                  committer='Joe Foo <joe@foo.com>')
331
 
        wt.commit('rev-merged', rev_id='rev-2a',
332
 
                  timestamp=1132586700, timezone=36000,
333
 
                  committer='Joe Foo <joe@foo.com>')
334
 
        wt.branch.set_last_revision_info(1, 'rev-1')
335
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
336
 
        wt.commit('rev-2b', rev_id='rev-2b',
337
 
                  timestamp=1132586800, timezone=36000,
338
 
                  committer='Joe Foo <joe@foo.com>')
339
 
        wt.commit('rev-3a', rev_id='rev-3a',
340
 
                  timestamp=1132586800, timezone=36000,
341
 
                  committer='Joe Foo <joe@foo.com>')
 
331
        wt = self._prepare_tree_with_merges()
 
332
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
342
333
        wt.branch.set_last_revision_info(2, 'rev-2b')
343
334
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
344
 
        wt.commit('rev-3b', rev_id='rev-3b',
345
 
                  timestamp=1132586800, timezone=36000,
346
 
                  committer='Joe Foo <joe@foo.com>')
347
 
        logfile = self.make_utf8_encoded_stringio()
348
 
        formatter = log.ShortLogFormatter(to_file=logfile)
349
 
        log.show_log(wt.branch, formatter,
350
 
            start_revision=2, end_revision=3)
351
 
        self.assertEqualDiff("""\
 
335
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
 
336
        self.assertFormatterResult("""\
352
337
    3 Joe Foo\t2005-11-22 [merge]
353
338
      rev-3b
354
339
 
355
340
    2 Joe Foo\t2005-11-22 [merge]
356
 
      rev-2b
 
341
      rev-2
357
342
 
358
343
""",
359
 
                             logfile.getvalue())
 
344
            wt.branch, log.ShortLogFormatter,
 
345
            show_log_kwargs=dict(start_revision=2, end_revision=3))
360
346
 
361
347
    def test_short_log_with_tags(self):
362
348
        wt = self._prepare_tree_with_merges(with_tags=True)
363
 
        logfile = self.make_utf8_encoded_stringio()
364
 
        formatter = log.ShortLogFormatter(to_file=logfile)
365
 
        log.show_log(wt.branch, formatter)
366
 
        self.assertEqualDiff("""\
367
 
    3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
 
349
        self.assertFormatterResult("""\
 
350
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
368
351
      rev-3
369
352
 
370
353
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
374
357
      rev-1
375
358
 
376
359
""",
377
 
                             logfile.getvalue())
 
360
            wt.branch, log.ShortLogFormatter)
378
361
 
379
362
    def test_short_log_single_merge_revision(self):
380
 
        wt = self.make_branch_and_memory_tree('.')
381
 
        wt.lock_write()
382
 
        self.addCleanup(wt.unlock)
383
 
        wt.add('')
384
 
        wt.commit('rev-1', rev_id='rev-1',
385
 
                  timestamp=1132586655, timezone=36000,
386
 
                  committer='Joe Foo <joe@foo.com>')
387
 
        wt.commit('rev-merged', rev_id='rev-2a',
388
 
                  timestamp=1132586700, timezone=36000,
389
 
                  committer='Joe Foo <joe@foo.com>')
390
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
391
 
        wt.branch.set_last_revision_info(1, 'rev-1')
392
 
        wt.commit('rev-2', rev_id='rev-2b',
393
 
                  timestamp=1132586800, timezone=36000,
394
 
                  committer='Joe Foo <joe@foo.com>')
395
 
        logfile = self.make_utf8_encoded_stringio()
396
 
        formatter = log.ShortLogFormatter(to_file=logfile)
 
363
        wt = self._prepare_tree_with_merges()
397
364
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
398
 
        wtb = wt.branch
399
 
        rev = revspec.in_history(wtb)
400
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
401
 
        self.assertEqualDiff("""\
 
365
        rev = revspec.in_history(wt.branch)
 
366
        self.assertFormatterResult("""\
402
367
      1.1.1 Joe Foo\t2005-11-22
403
368
            rev-merged
404
369
 
405
370
""",
406
 
                             logfile.getvalue())
407
 
 
408
 
 
409
 
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
371
            wt.branch, log.ShortLogFormatter,
 
372
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
373
 
 
374
 
 
375
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
410
376
 
411
377
    def test_short_merge_revs_log_with_merges(self):
412
 
        wt = self.make_branch_and_memory_tree('.')
413
 
        wt.lock_write()
414
 
        self.addCleanup(wt.unlock)
415
 
        wt.add('')
416
 
        wt.commit('rev-1', rev_id='rev-1',
417
 
                  timestamp=1132586655, timezone=36000,
418
 
                  committer='Joe Foo <joe@foo.com>')
419
 
        wt.commit('rev-merged', rev_id='rev-2a',
420
 
                  timestamp=1132586700, timezone=36000,
421
 
                  committer='Joe Foo <joe@foo.com>')
422
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
423
 
        wt.branch.set_last_revision_info(1, 'rev-1')
424
 
        wt.commit('rev-2', rev_id='rev-2b',
425
 
                  timestamp=1132586800, timezone=36000,
426
 
                  committer='Joe Foo <joe@foo.com>')
427
 
        logfile = self.make_utf8_encoded_stringio()
428
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
429
 
        log.show_log(wt.branch, formatter)
 
378
        wt = self._prepare_tree_with_merges()
430
379
        # Note that the 1.1.1 indenting is in fact correct given that
431
380
        # the revision numbers are right justified within 5 characters
432
381
        # for mainline revnos and 9 characters for dotted revnos.
433
 
        self.assertEqualDiff("""\
 
382
        self.assertFormatterResult("""\
434
383
    2 Joe Foo\t2005-11-22 [merge]
435
384
      rev-2
436
385
 
441
390
      rev-1
442
391
 
443
392
""",
444
 
                             logfile.getvalue())
 
393
            wt.branch, log.ShortLogFormatter,
 
394
            formatter_kwargs=dict(levels=0))
445
395
 
446
396
    def test_short_merge_revs_log_single_merge_revision(self):
447
 
        wt = self.make_branch_and_memory_tree('.')
448
 
        wt.lock_write()
449
 
        self.addCleanup(wt.unlock)
450
 
        wt.add('')
451
 
        wt.commit('rev-1', rev_id='rev-1',
452
 
                  timestamp=1132586655, timezone=36000,
453
 
                  committer='Joe Foo <joe@foo.com>')
454
 
        wt.commit('rev-merged', rev_id='rev-2a',
455
 
                  timestamp=1132586700, timezone=36000,
456
 
                  committer='Joe Foo <joe@foo.com>')
457
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
458
 
        wt.branch.set_last_revision_info(1, 'rev-1')
459
 
        wt.commit('rev-2', rev_id='rev-2b',
460
 
                  timestamp=1132586800, timezone=36000,
461
 
                  committer='Joe Foo <joe@foo.com>')
462
 
        logfile = self.make_utf8_encoded_stringio()
463
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
397
        wt = self._prepare_tree_with_merges()
464
398
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
465
 
        wtb = wt.branch
466
 
        rev = revspec.in_history(wtb)
467
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
468
 
        self.assertEqualDiff("""\
 
399
        rev = revspec.in_history(wt.branch)
 
400
        self.assertFormatterResult("""\
469
401
      1.1.1 Joe Foo\t2005-11-22
470
402
            rev-merged
471
403
 
472
404
""",
473
 
                             logfile.getvalue())
474
 
 
475
 
 
476
 
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
 
405
            wt.branch, log.ShortLogFormatter,
 
406
            formatter_kwargs=dict(levels=0),
 
407
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
408
 
 
409
 
 
410
class TestLongLogFormatter(TestCaseForLogFormatter):
477
411
 
478
412
    def test_verbose_log(self):
479
413
        """Verbose log includes changed files
480
414
 
481
415
        bug #4676
482
416
        """
483
 
        wt = self.make_branch_and_tree('.')
484
 
        b = wt.branch
485
 
        self.build_tree(['a'])
486
 
        wt.add('a')
487
 
        # XXX: why does a longer nick show up?
488
 
        b.nick = 'test_verbose_log'
489
 
        wt.commit(message='add a',
490
 
                  timestamp=1132711707,
491
 
                  timezone=36000,
492
 
                  committer='Lorem Ipsum <test@example.com>')
493
 
        logfile = file('out.tmp', 'w+')
494
 
        formatter = log.LongLogFormatter(to_file=logfile)
495
 
        log.show_log(b, formatter, verbose=True)
496
 
        logfile.flush()
497
 
        logfile.seek(0)
498
 
        log_contents = logfile.read()
499
 
        self.assertEqualDiff('''\
 
417
        wt = self.make_standard_commit('test_verbose_log', authors=[])
 
418
        self.assertFormatterResult('''\
500
419
------------------------------------------------------------
501
420
revno: 1
502
421
committer: Lorem Ipsum <test@example.com>
503
422
branch nick: test_verbose_log
504
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
423
timestamp: Tue 2005-11-22 00:00:00 +0000
505
424
message:
506
425
  add a
507
426
added:
508
427
  a
509
428
''',
510
 
                             log_contents)
 
429
            wt.branch, log.LongLogFormatter,
 
430
            show_log_kwargs=dict(verbose=True))
511
431
 
512
432
    def test_merges_are_indented_by_level(self):
513
433
        wt = self.make_branch_and_tree('parent')
514
 
        wt.commit('first post')
515
 
        self.run_bzr('branch parent child')
516
 
        self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
517
 
        self.run_bzr('branch child smallerchild')
518
 
        self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
519
 
            'smallerchild'])
520
 
        os.chdir('child')
521
 
        self.run_bzr('merge ../smallerchild')
522
 
        self.run_bzr(['commit', '-m', 'merge branch 2'])
523
 
        os.chdir('../parent')
524
 
        self.run_bzr('merge ../child')
525
 
        wt.commit('merge branch 1')
526
 
        b = wt.branch
527
 
        sio = self.make_utf8_encoded_stringio()
528
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
529
 
        log.show_log(b, lf, verbose=True)
530
 
        the_log = normalize_log(sio.getvalue())
531
 
        self.assertEqualDiff("""\
 
434
        self.wt_commit(wt, 'first post')
 
435
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
436
        self.wt_commit(child_wt, 'branch 1')
 
437
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
 
438
        self.wt_commit(smallerchild_wt, 'branch 2')
 
439
        child_wt.merge_from_branch(smallerchild_wt.branch)
 
440
        self.wt_commit(child_wt, 'merge branch 2')
 
441
        wt.merge_from_branch(child_wt.branch)
 
442
        self.wt_commit(wt, 'merge branch 1')
 
443
        self.assertFormatterResult("""\
532
444
------------------------------------------------------------
533
445
revno: 2 [merge]
534
 
committer: Lorem Ipsum <test@example.com>
 
446
committer: Joe Foo <joe@foo.com>
535
447
branch nick: parent
536
 
timestamp: Just now
 
448
timestamp: Tue 2005-11-22 00:00:04 +0000
537
449
message:
538
450
  merge branch 1
539
451
    ------------------------------------------------------------
540
452
    revno: 1.1.2 [merge]
541
 
    committer: Lorem Ipsum <test@example.com>
 
453
    committer: Joe Foo <joe@foo.com>
542
454
    branch nick: child
543
 
    timestamp: Just now
 
455
    timestamp: Tue 2005-11-22 00:00:03 +0000
544
456
    message:
545
457
      merge branch 2
546
458
        ------------------------------------------------------------
547
459
        revno: 1.2.1
548
 
        committer: Lorem Ipsum <test@example.com>
 
460
        committer: Joe Foo <joe@foo.com>
549
461
        branch nick: smallerchild
550
 
        timestamp: Just now
 
462
        timestamp: Tue 2005-11-22 00:00:02 +0000
551
463
        message:
552
464
          branch 2
553
465
    ------------------------------------------------------------
554
466
    revno: 1.1.1
555
 
    committer: Lorem Ipsum <test@example.com>
 
467
    committer: Joe Foo <joe@foo.com>
556
468
    branch nick: child
557
 
    timestamp: Just now
 
469
    timestamp: Tue 2005-11-22 00:00:01 +0000
558
470
    message:
559
471
      branch 1
560
472
------------------------------------------------------------
561
473
revno: 1
562
 
committer: Lorem Ipsum <test@example.com>
 
474
committer: Joe Foo <joe@foo.com>
563
475
branch nick: parent
564
 
timestamp: Just now
 
476
timestamp: Tue 2005-11-22 00:00:00 +0000
565
477
message:
566
478
  first post
567
479
""",
568
 
                             the_log)
 
480
            wt.branch, log.LongLogFormatter,
 
481
            formatter_kwargs=dict(levels=0),
 
482
            show_log_kwargs=dict(verbose=True))
569
483
 
570
484
    def test_verbose_merge_revisions_contain_deltas(self):
571
485
        wt = self.make_branch_and_tree('parent')
572
486
        self.build_tree(['parent/f1', 'parent/f2'])
573
487
        wt.add(['f1','f2'])
574
 
        wt.commit('first post')
575
 
        self.run_bzr('branch parent child')
 
488
        self.wt_commit(wt, 'first post')
 
489
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
576
490
        os.unlink('child/f1')
577
 
        file('child/f2', 'wb').write('hello\n')
578
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
579
 
            'child'])
580
 
        os.chdir('parent')
581
 
        self.run_bzr('merge ../child')
582
 
        wt.commit('merge branch 1')
583
 
        b = wt.branch
584
 
        sio = self.make_utf8_encoded_stringio()
585
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
586
 
        log.show_log(b, lf, verbose=True)
587
 
        the_log = normalize_log(sio.getvalue())
588
 
        self.assertEqualDiff("""\
 
491
        self.build_tree_contents([('child/f2', 'hello\n')])
 
492
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
493
        wt.merge_from_branch(child_wt.branch)
 
494
        self.wt_commit(wt, 'merge branch 1')
 
495
        self.assertFormatterResult("""\
589
496
------------------------------------------------------------
590
497
revno: 2 [merge]
591
 
committer: Lorem Ipsum <test@example.com>
 
498
committer: Joe Foo <joe@foo.com>
592
499
branch nick: parent
593
 
timestamp: Just now
 
500
timestamp: Tue 2005-11-22 00:00:02 +0000
594
501
message:
595
502
  merge branch 1
596
503
removed:
599
506
  f2
600
507
    ------------------------------------------------------------
601
508
    revno: 1.1.1
602
 
    committer: Lorem Ipsum <test@example.com>
 
509
    committer: Joe Foo <joe@foo.com>
603
510
    branch nick: child
604
 
    timestamp: Just now
 
511
    timestamp: Tue 2005-11-22 00:00:01 +0000
605
512
    message:
606
513
      removed f1 and modified f2
607
514
    removed:
610
517
      f2
611
518
------------------------------------------------------------
612
519
revno: 1
613
 
committer: Lorem Ipsum <test@example.com>
 
520
committer: Joe Foo <joe@foo.com>
614
521
branch nick: parent
615
 
timestamp: Just now
 
522
timestamp: Tue 2005-11-22 00:00:00 +0000
616
523
message:
617
524
  first post
618
525
added:
619
526
  f1
620
527
  f2
621
528
""",
622
 
                             the_log)
 
529
            wt.branch, log.LongLogFormatter,
 
530
            formatter_kwargs=dict(levels=0),
 
531
            show_log_kwargs=dict(verbose=True))
623
532
 
624
533
    def test_trailing_newlines(self):
625
534
        wt = self.make_branch_and_tree('.')
626
 
        b = make_commits_with_trailing_newlines(wt)
627
 
        sio = self.make_utf8_encoded_stringio()
628
 
        lf = log.LongLogFormatter(to_file=sio)
629
 
        log.show_log(b, lf)
630
 
        self.assertEqualDiff("""\
 
535
        b = self.make_commits_with_trailing_newlines(wt)
 
536
        self.assertFormatterResult("""\
631
537
------------------------------------------------------------
632
538
revno: 3
633
539
committer: Joe Foo <joe@foo.com>
634
540
branch nick: test
635
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
541
timestamp: Tue 2005-11-22 00:00:02 +0000
636
542
message:
637
543
  single line with trailing newline
638
544
------------------------------------------------------------
639
545
revno: 2
640
 
author: Joe Bar <joe@bar.com>
641
546
committer: Joe Foo <joe@foo.com>
642
547
branch nick: test
643
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
548
timestamp: Tue 2005-11-22 00:00:01 +0000
644
549
message:
645
550
  multiline
646
551
  log
649
554
revno: 1
650
555
committer: Joe Foo <joe@foo.com>
651
556
branch nick: test
652
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
557
timestamp: Tue 2005-11-22 00:00:00 +0000
653
558
message:
654
559
  simple log message
655
560
""",
656
 
                             sio.getvalue())
 
561
        b, log.LongLogFormatter)
657
562
 
658
563
    def test_author_in_log(self):
659
564
        """Log includes the author name if it's set in
660
565
        the revision properties
661
566
        """
662
 
        wt = self.make_branch_and_tree('.')
663
 
        b = wt.branch
664
 
        self.build_tree(['a'])
665
 
        wt.add('a')
666
 
        b.nick = 'test_author_log'
667
 
        wt.commit(message='add a',
668
 
                  timestamp=1132711707,
669
 
                  timezone=36000,
670
 
                  committer='Lorem Ipsum <test@example.com>',
671
 
                  authors=['John Doe <jdoe@example.com>',
672
 
                           'Jane Rey <jrey@example.com>'])
673
 
        sio = StringIO()
674
 
        formatter = log.LongLogFormatter(to_file=sio)
675
 
        log.show_log(b, formatter)
676
 
        self.assertEqualDiff('''\
 
567
        wt = self.make_standard_commit('test_author_log',
 
568
            authors=['John Doe <jdoe@example.com>',
 
569
                     'Jane Rey <jrey@example.com>'])
 
570
        self.assertFormatterResult("""\
677
571
------------------------------------------------------------
678
572
revno: 1
679
573
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
680
574
committer: Lorem Ipsum <test@example.com>
681
575
branch nick: test_author_log
682
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
576
timestamp: Tue 2005-11-22 00:00:00 +0000
683
577
message:
684
578
  add a
685
 
''',
686
 
                             sio.getvalue())
 
579
""",
 
580
        wt.branch, log.LongLogFormatter)
687
581
 
688
582
    def test_properties_in_log(self):
689
583
        """Log includes the custom properties returned by the registered
690
584
        handlers.
691
585
        """
692
 
        wt = self.make_branch_and_tree('.')
693
 
        b = wt.branch
694
 
        self.build_tree(['a'])
695
 
        wt.add('a')
696
 
        b.nick = 'test_properties_in_log'
697
 
        wt.commit(message='add a',
698
 
                  timestamp=1132711707,
699
 
                  timezone=36000,
700
 
                  committer='Lorem Ipsum <test@example.com>',
701
 
                  authors=['John Doe <jdoe@example.com>'])
702
 
        sio = StringIO()
703
 
        formatter = log.LongLogFormatter(to_file=sio)
704
 
        try:
705
 
            def trivial_custom_prop_handler(revision):
706
 
                return {'test_prop':'test_value'}
 
586
        wt = self.make_standard_commit('test_properties_in_log')
 
587
        def trivial_custom_prop_handler(revision):
 
588
            return {'test_prop':'test_value'}
707
589
 
708
 
            log.properties_handler_registry.register(
709
 
                'trivial_custom_prop_handler',
710
 
                trivial_custom_prop_handler)
711
 
            log.show_log(b, formatter)
712
 
        finally:
713
 
            log.properties_handler_registry.remove(
714
 
                'trivial_custom_prop_handler')
715
 
            self.assertEqualDiff('''\
 
590
        # Cleaned up in setUp()
 
591
        log.properties_handler_registry.register(
 
592
            'trivial_custom_prop_handler',
 
593
            trivial_custom_prop_handler)
 
594
        self.assertFormatterResult("""\
716
595
------------------------------------------------------------
717
596
revno: 1
718
597
test_prop: test_value
719
598
author: John Doe <jdoe@example.com>
720
599
committer: Lorem Ipsum <test@example.com>
721
600
branch nick: test_properties_in_log
722
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
601
timestamp: Tue 2005-11-22 00:00:00 +0000
723
602
message:
724
603
  add a
725
 
''',
726
 
                                 sio.getvalue())
 
604
""",
 
605
            wt.branch, log.LongLogFormatter)
727
606
 
728
607
    def test_properties_in_short_log(self):
729
608
        """Log includes the custom properties returned by the registered
730
609
        handlers.
731
610
        """
732
 
        wt = self.make_branch_and_tree('.')
733
 
        b = wt.branch
734
 
        self.build_tree(['a'])
735
 
        wt.add('a')
736
 
        b.nick = 'test_properties_in_short_log'
737
 
        wt.commit(message='add a',
738
 
                  timestamp=1132711707,
739
 
                  timezone=36000,
740
 
                  committer='Lorem Ipsum <test@example.com>',
741
 
                  authors=['John Doe <jdoe@example.com>'])
742
 
        sio = StringIO()
743
 
        formatter = log.ShortLogFormatter(to_file=sio)
744
 
        try:
745
 
            def trivial_custom_prop_handler(revision):
746
 
                return {'test_prop':'test_value'}
 
611
        wt = self.make_standard_commit('test_properties_in_short_log')
 
612
        def trivial_custom_prop_handler(revision):
 
613
            return {'test_prop':'test_value'}
747
614
 
748
 
            log.properties_handler_registry.register(
749
 
                'trivial_custom_prop_handler',
750
 
                trivial_custom_prop_handler)
751
 
            log.show_log(b, formatter)
752
 
        finally:
753
 
            log.properties_handler_registry.remove(
754
 
                'trivial_custom_prop_handler')
755
 
            self.assertEqualDiff('''\
756
 
    1 John Doe\t2005-11-23
 
615
        log.properties_handler_registry.register(
 
616
            'trivial_custom_prop_handler',
 
617
            trivial_custom_prop_handler)
 
618
        self.assertFormatterResult("""\
 
619
    1 John Doe\t2005-11-22
757
620
      test_prop: test_value
758
621
      add a
759
622
 
760
 
''',
761
 
                                 sio.getvalue())
 
623
""",
 
624
            wt.branch, log.ShortLogFormatter)
762
625
 
763
626
    def test_error_in_properties_handler(self):
764
627
        """Log includes the custom properties returned by the registered
765
628
        handlers.
766
629
        """
767
 
        wt = self.make_branch_and_tree('.')
768
 
        b = wt.branch
769
 
        self.build_tree(['a'])
770
 
        wt.add('a')
771
 
        b.nick = 'test_author_log'
772
 
        wt.commit(message='add a',
773
 
                  timestamp=1132711707,
774
 
                  timezone=36000,
775
 
                  committer='Lorem Ipsum <test@example.com>',
776
 
                  authors=['John Doe <jdoe@example.com>'],
777
 
                  revprops={'first_prop':'first_value'})
778
 
        sio = StringIO()
 
630
        wt = self.make_standard_commit('error_in_properties_handler',
 
631
            revprops={'first_prop':'first_value'})
 
632
        sio = self.make_utf8_encoded_stringio()
779
633
        formatter = log.LongLogFormatter(to_file=sio)
780
 
        try:
781
 
            def trivial_custom_prop_handler(revision):
782
 
                raise StandardError("a test error")
 
634
        def trivial_custom_prop_handler(revision):
 
635
            raise StandardError("a test error")
783
636
 
784
 
            log.properties_handler_registry.register(
785
 
                'trivial_custom_prop_handler',
786
 
                trivial_custom_prop_handler)
787
 
            self.assertRaises(StandardError, log.show_log, b, formatter,)
788
 
        finally:
789
 
            log.properties_handler_registry.remove(
790
 
                'trivial_custom_prop_handler')
 
637
        log.properties_handler_registry.register(
 
638
            'trivial_custom_prop_handler',
 
639
            trivial_custom_prop_handler)
 
640
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
791
641
 
792
642
    def test_properties_handler_bad_argument(self):
793
 
        wt = self.make_branch_and_tree('.')
794
 
        b = wt.branch
795
 
        self.build_tree(['a'])
796
 
        wt.add('a')
797
 
        b.nick = 'test_author_log'
798
 
        wt.commit(message='add a',
799
 
                  timestamp=1132711707,
800
 
                  timezone=36000,
801
 
                  committer='Lorem Ipsum <test@example.com>',
802
 
                  authors=['John Doe <jdoe@example.com>'],
803
 
                  revprops={'a_prop':'test_value'})
804
 
        sio = StringIO()
 
643
        wt = self.make_standard_commit('bad_argument',
 
644
              revprops={'a_prop':'test_value'})
 
645
        sio = self.make_utf8_encoded_stringio()
805
646
        formatter = log.LongLogFormatter(to_file=sio)
806
 
        try:
807
 
            def bad_argument_prop_handler(revision):
808
 
                return {'custom_prop_name':revision.properties['a_prop']}
809
 
 
810
 
            log.properties_handler_registry.register(
811
 
                'bad_argument_prop_handler',
812
 
                bad_argument_prop_handler)
813
 
 
814
 
            self.assertRaises(AttributeError, formatter.show_properties,
815
 
                              'a revision', '')
816
 
 
817
 
            revision = b.repository.get_revision(b.last_revision())
818
 
            formatter.show_properties(revision, '')
819
 
            self.assertEqualDiff('''custom_prop_name: test_value\n''',
820
 
                                 sio.getvalue())
821
 
        finally:
822
 
            log.properties_handler_registry.remove(
823
 
                'bad_argument_prop_handler')
824
 
 
825
 
 
826
 
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
 
647
        def bad_argument_prop_handler(revision):
 
648
            return {'custom_prop_name':revision.properties['a_prop']}
 
649
 
 
650
        log.properties_handler_registry.register(
 
651
            'bad_argument_prop_handler',
 
652
            bad_argument_prop_handler)
 
653
 
 
654
        self.assertRaises(AttributeError, formatter.show_properties,
 
655
                          'a revision', '')
 
656
 
 
657
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
 
658
        formatter.show_properties(revision, '')
 
659
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
 
660
                             sio.getvalue())
 
661
 
 
662
 
 
663
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
827
664
 
828
665
    def test_long_verbose_log(self):
829
666
        """Verbose log includes changed files
830
667
 
831
668
        bug #4676
832
669
        """
833
 
        wt = self.make_branch_and_tree('.')
834
 
        b = wt.branch
835
 
        self.build_tree(['a'])
836
 
        wt.add('a')
837
 
        # XXX: why does a longer nick show up?
838
 
        b.nick = 'test_verbose_log'
839
 
        wt.commit(message='add a',
840
 
                  timestamp=1132711707,
841
 
                  timezone=36000,
842
 
                  committer='Lorem Ipsum <test@example.com>')
843
 
        logfile = file('out.tmp', 'w+')
844
 
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
845
 
        log.show_log(b, formatter, verbose=True)
846
 
        logfile.flush()
847
 
        logfile.seek(0)
848
 
        log_contents = logfile.read()
849
 
        self.assertEqualDiff('''\
 
670
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
 
671
        self.assertFormatterResult("""\
850
672
------------------------------------------------------------
851
673
revno: 1
852
674
committer: Lorem Ipsum <test@example.com>
853
 
branch nick: test_verbose_log
854
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
675
branch nick: test_long_verbose_log
 
676
timestamp: Tue 2005-11-22 00:00:00 +0000
855
677
message:
856
678
  add a
857
679
added:
858
680
  a
859
 
''',
860
 
                             log_contents)
 
681
""",
 
682
            wt.branch, log.LongLogFormatter,
 
683
            formatter_kwargs=dict(levels=1),
 
684
            show_log_kwargs=dict(verbose=True))
861
685
 
862
686
    def test_long_verbose_contain_deltas(self):
863
687
        wt = self.make_branch_and_tree('parent')
864
688
        self.build_tree(['parent/f1', 'parent/f2'])
865
689
        wt.add(['f1','f2'])
866
 
        wt.commit('first post')
867
 
        self.run_bzr('branch parent child')
 
690
        self.wt_commit(wt, 'first post')
 
691
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
868
692
        os.unlink('child/f1')
869
 
        file('child/f2', 'wb').write('hello\n')
870
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
871
 
            'child'])
872
 
        os.chdir('parent')
873
 
        self.run_bzr('merge ../child')
874
 
        wt.commit('merge branch 1')
875
 
        b = wt.branch
876
 
        sio = self.make_utf8_encoded_stringio()
877
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
878
 
        log.show_log(b, lf, verbose=True)
879
 
        the_log = normalize_log(sio.getvalue())
880
 
        self.assertEqualDiff("""\
 
693
        self.build_tree_contents([('child/f2', 'hello\n')])
 
694
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
695
        wt.merge_from_branch(child_wt.branch)
 
696
        self.wt_commit(wt, 'merge branch 1')
 
697
        self.assertFormatterResult("""\
881
698
------------------------------------------------------------
882
699
revno: 2 [merge]
883
 
committer: Lorem Ipsum <test@example.com>
 
700
committer: Joe Foo <joe@foo.com>
884
701
branch nick: parent
885
 
timestamp: Just now
 
702
timestamp: Tue 2005-11-22 00:00:02 +0000
886
703
message:
887
704
  merge branch 1
888
705
removed:
891
708
  f2
892
709
------------------------------------------------------------
893
710
revno: 1
894
 
committer: Lorem Ipsum <test@example.com>
 
711
committer: Joe Foo <joe@foo.com>
895
712
branch nick: parent
896
 
timestamp: Just now
 
713
timestamp: Tue 2005-11-22 00:00:00 +0000
897
714
message:
898
715
  first post
899
716
added:
900
717
  f1
901
718
  f2
902
719
""",
903
 
                             the_log)
 
720
            wt.branch, log.LongLogFormatter,
 
721
            formatter_kwargs=dict(levels=1),
 
722
            show_log_kwargs=dict(verbose=True))
904
723
 
905
724
    def test_long_trailing_newlines(self):
906
725
        wt = self.make_branch_and_tree('.')
907
 
        b = make_commits_with_trailing_newlines(wt)
908
 
        sio = self.make_utf8_encoded_stringio()
909
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
910
 
        log.show_log(b, lf)
911
 
        self.assertEqualDiff("""\
 
726
        b = self.make_commits_with_trailing_newlines(wt)
 
727
        self.assertFormatterResult("""\
912
728
------------------------------------------------------------
913
729
revno: 3
914
730
committer: Joe Foo <joe@foo.com>
915
731
branch nick: test
916
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
732
timestamp: Tue 2005-11-22 00:00:02 +0000
917
733
message:
918
734
  single line with trailing newline
919
735
------------------------------------------------------------
920
736
revno: 2
921
 
author: Joe Bar <joe@bar.com>
922
737
committer: Joe Foo <joe@foo.com>
923
738
branch nick: test
924
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
739
timestamp: Tue 2005-11-22 00:00:01 +0000
925
740
message:
926
741
  multiline
927
742
  log
930
745
revno: 1
931
746
committer: Joe Foo <joe@foo.com>
932
747
branch nick: test
933
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
748
timestamp: Tue 2005-11-22 00:00:00 +0000
934
749
message:
935
750
  simple log message
936
751
""",
937
 
                             sio.getvalue())
 
752
        b, log.LongLogFormatter,
 
753
        formatter_kwargs=dict(levels=1))
938
754
 
939
755
    def test_long_author_in_log(self):
940
756
        """Log includes the author name if it's set in
941
757
        the revision properties
942
758
        """
943
 
        wt = self.make_branch_and_tree('.')
944
 
        b = wt.branch
945
 
        self.build_tree(['a'])
946
 
        wt.add('a')
947
 
        b.nick = 'test_author_log'
948
 
        wt.commit(message='add a',
949
 
                  timestamp=1132711707,
950
 
                  timezone=36000,
951
 
                  committer='Lorem Ipsum <test@example.com>',
952
 
                  authors=['John Doe <jdoe@example.com>'])
953
 
        sio = StringIO()
954
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
955
 
        log.show_log(b, formatter)
956
 
        self.assertEqualDiff('''\
 
759
        wt = self.make_standard_commit('test_author_log')
 
760
        self.assertFormatterResult("""\
957
761
------------------------------------------------------------
958
762
revno: 1
959
763
author: John Doe <jdoe@example.com>
960
764
committer: Lorem Ipsum <test@example.com>
961
765
branch nick: test_author_log
962
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
766
timestamp: Tue 2005-11-22 00:00:00 +0000
963
767
message:
964
768
  add a
965
 
''',
966
 
                             sio.getvalue())
 
769
""",
 
770
            wt.branch, log.LongLogFormatter,
 
771
            formatter_kwargs=dict(levels=1))
967
772
 
968
773
    def test_long_properties_in_log(self):
969
774
        """Log includes the custom properties returned by the registered
970
775
        handlers.
971
776
        """
972
 
        wt = self.make_branch_and_tree('.')
973
 
        b = wt.branch
974
 
        self.build_tree(['a'])
975
 
        wt.add('a')
976
 
        b.nick = 'test_properties_in_log'
977
 
        wt.commit(message='add a',
978
 
                  timestamp=1132711707,
979
 
                  timezone=36000,
980
 
                  committer='Lorem Ipsum <test@example.com>',
981
 
                  authors=['John Doe <jdoe@example.com>'])
982
 
        sio = StringIO()
983
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
984
 
        try:
985
 
            def trivial_custom_prop_handler(revision):
986
 
                return {'test_prop':'test_value'}
 
777
        wt = self.make_standard_commit('test_properties_in_log')
 
778
        def trivial_custom_prop_handler(revision):
 
779
            return {'test_prop':'test_value'}
987
780
 
988
 
            log.properties_handler_registry.register(
989
 
                'trivial_custom_prop_handler',
990
 
                trivial_custom_prop_handler)
991
 
            log.show_log(b, formatter)
992
 
        finally:
993
 
            log.properties_handler_registry.remove(
994
 
                'trivial_custom_prop_handler')
995
 
            self.assertEqualDiff('''\
 
781
        log.properties_handler_registry.register(
 
782
            'trivial_custom_prop_handler',
 
783
            trivial_custom_prop_handler)
 
784
        self.assertFormatterResult("""\
996
785
------------------------------------------------------------
997
786
revno: 1
998
787
test_prop: test_value
999
788
author: John Doe <jdoe@example.com>
1000
789
committer: Lorem Ipsum <test@example.com>
1001
790
branch nick: test_properties_in_log
1002
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
791
timestamp: Tue 2005-11-22 00:00:00 +0000
1003
792
message:
1004
793
  add a
1005
 
''',
1006
 
                                 sio.getvalue())
1007
 
 
1008
 
 
1009
 
class TestLineLogFormatter(tests.TestCaseWithTransport):
 
794
""",
 
795
            wt.branch, log.LongLogFormatter,
 
796
            formatter_kwargs=dict(levels=1))
 
797
 
 
798
 
 
799
class TestLineLogFormatter(TestCaseForLogFormatter):
1010
800
 
1011
801
    def test_line_log(self):
1012
802
        """Line log should show revno
1013
803
 
1014
804
        bug #5162
1015
805
        """
1016
 
        wt = self.make_branch_and_tree('.')
1017
 
        b = wt.branch
1018
 
        self.build_tree(['a'])
1019
 
        wt.add('a')
1020
 
        b.nick = 'test-line-log'
1021
 
        wt.commit(message='add a',
1022
 
                  timestamp=1132711707,
1023
 
                  timezone=36000,
1024
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1025
 
        logfile = file('out.tmp', 'w+')
1026
 
        formatter = log.LineLogFormatter(to_file=logfile)
1027
 
        log.show_log(b, formatter)
1028
 
        logfile.flush()
1029
 
        logfile.seek(0)
1030
 
        log_contents = logfile.read()
1031
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1032
 
                             log_contents)
 
806
        wt = self.make_standard_commit('test-line-log',
 
807
                committer='Line-Log-Formatter Tester <test@line.log>',
 
808
                authors=[])
 
809
        self.assertFormatterResult("""\
 
810
1: Line-Log-Formatte... 2005-11-22 add a
 
811
""",
 
812
            wt.branch, log.LineLogFormatter)
1033
813
 
1034
814
    def test_trailing_newlines(self):
1035
815
        wt = self.make_branch_and_tree('.')
1036
 
        b = make_commits_with_trailing_newlines(wt)
1037
 
        sio = self.make_utf8_encoded_stringio()
1038
 
        lf = log.LineLogFormatter(to_file=sio)
1039
 
        log.show_log(b, lf)
1040
 
        self.assertEqualDiff("""\
1041
 
3: Joe Foo 2005-11-21 single line with trailing newline
1042
 
2: Joe Bar 2005-11-21 multiline
1043
 
1: Joe Foo 2005-11-21 simple log message
 
816
        b = self.make_commits_with_trailing_newlines(wt)
 
817
        self.assertFormatterResult("""\
 
818
3: Joe Foo 2005-11-22 single line with trailing newline
 
819
2: Joe Foo 2005-11-22 multiline
 
820
1: Joe Foo 2005-11-22 simple log message
1044
821
""",
1045
 
                             sio.getvalue())
1046
 
 
1047
 
    def _prepare_tree_with_merges(self, with_tags=False):
1048
 
        wt = self.make_branch_and_memory_tree('.')
1049
 
        wt.lock_write()
1050
 
        self.addCleanup(wt.unlock)
1051
 
        wt.add('')
1052
 
        wt.commit('rev-1', rev_id='rev-1',
1053
 
                  timestamp=1132586655, timezone=36000,
1054
 
                  committer='Joe Foo <joe@foo.com>')
1055
 
        wt.commit('rev-merged', rev_id='rev-2a',
1056
 
                  timestamp=1132586700, timezone=36000,
1057
 
                  committer='Joe Foo <joe@foo.com>')
1058
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1059
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1060
 
        wt.commit('rev-2', rev_id='rev-2b',
1061
 
                  timestamp=1132586800, timezone=36000,
1062
 
                  committer='Joe Foo <joe@foo.com>')
1063
 
        if with_tags:
1064
 
            branch = wt.branch
1065
 
            branch.tags.set_tag('v0.2', 'rev-2b')
1066
 
            wt.commit('rev-3', rev_id='rev-3',
1067
 
                      timestamp=1132586900, timezone=36000,
1068
 
                      committer='Jane Foo <jane@foo.com>')
1069
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
1070
 
            branch.tags.set_tag('v1.0', 'rev-3')
1071
 
        return wt
 
822
            b, log.LineLogFormatter)
1072
823
 
1073
824
    def test_line_log_single_merge_revision(self):
1074
825
        wt = self._prepare_tree_with_merges()
1075
 
        logfile = self.make_utf8_encoded_stringio()
1076
 
        formatter = log.LineLogFormatter(to_file=logfile)
1077
826
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1078
 
        wtb = wt.branch
1079
 
        rev = revspec.in_history(wtb)
1080
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1081
 
        self.assertEqualDiff("""\
 
827
        rev = revspec.in_history(wt.branch)
 
828
        self.assertFormatterResult("""\
1082
829
1.1.1: Joe Foo 2005-11-22 rev-merged
1083
830
""",
1084
 
                             logfile.getvalue())
 
831
            wt.branch, log.LineLogFormatter,
 
832
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1085
833
 
1086
834
    def test_line_log_with_tags(self):
1087
835
        wt = self._prepare_tree_with_merges(with_tags=True)
1088
 
        logfile = self.make_utf8_encoded_stringio()
1089
 
        formatter = log.LineLogFormatter(to_file=logfile)
1090
 
        log.show_log(wt.branch, formatter)
1091
 
        self.assertEqualDiff("""\
1092
 
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
 
836
        self.assertFormatterResult("""\
 
837
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1093
838
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
1094
839
1: Joe Foo 2005-11-22 rev-1
1095
840
""",
1096
 
                             logfile.getvalue())
1097
 
 
1098
 
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
841
            wt.branch, log.LineLogFormatter)
 
842
 
 
843
 
 
844
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
1099
845
 
1100
846
    def test_line_merge_revs_log(self):
1101
847
        """Line log should show revno
1102
848
 
1103
849
        bug #5162
1104
850
        """
1105
 
        wt = self.make_branch_and_tree('.')
1106
 
        b = wt.branch
1107
 
        self.build_tree(['a'])
1108
 
        wt.add('a')
1109
 
        b.nick = 'test-line-log'
1110
 
        wt.commit(message='add a',
1111
 
                  timestamp=1132711707,
1112
 
                  timezone=36000,
1113
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1114
 
        logfile = file('out.tmp', 'w+')
1115
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1116
 
        log.show_log(b, formatter)
1117
 
        logfile.flush()
1118
 
        logfile.seek(0)
1119
 
        log_contents = logfile.read()
1120
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1121
 
                             log_contents)
 
851
        wt = self.make_standard_commit('test-line-log',
 
852
                committer='Line-Log-Formatter Tester <test@line.log>',
 
853
                authors=[])
 
854
        self.assertFormatterResult("""\
 
855
1: Line-Log-Formatte... 2005-11-22 add a
 
856
""",
 
857
            wt.branch, log.LineLogFormatter)
1122
858
 
1123
859
    def test_line_merge_revs_log_single_merge_revision(self):
1124
 
        wt = self.make_branch_and_memory_tree('.')
1125
 
        wt.lock_write()
1126
 
        self.addCleanup(wt.unlock)
1127
 
        wt.add('')
1128
 
        wt.commit('rev-1', rev_id='rev-1',
1129
 
                  timestamp=1132586655, timezone=36000,
1130
 
                  committer='Joe Foo <joe@foo.com>')
1131
 
        wt.commit('rev-merged', rev_id='rev-2a',
1132
 
                  timestamp=1132586700, timezone=36000,
1133
 
                  committer='Joe Foo <joe@foo.com>')
1134
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1135
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1136
 
        wt.commit('rev-2', rev_id='rev-2b',
1137
 
                  timestamp=1132586800, timezone=36000,
1138
 
                  committer='Joe Foo <joe@foo.com>')
1139
 
        logfile = self.make_utf8_encoded_stringio()
1140
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
860
        wt = self._prepare_tree_with_merges()
1141
861
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1142
 
        wtb = wt.branch
1143
 
        rev = revspec.in_history(wtb)
1144
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1145
 
        self.assertEqualDiff("""\
 
862
        rev = revspec.in_history(wt.branch)
 
863
        self.assertFormatterResult("""\
1146
864
1.1.1: Joe Foo 2005-11-22 rev-merged
1147
865
""",
1148
 
                             logfile.getvalue())
 
866
            wt.branch, log.LineLogFormatter,
 
867
            formatter_kwargs=dict(levels=0),
 
868
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1149
869
 
1150
870
    def test_line_merge_revs_log_with_merges(self):
1151
 
        wt = self.make_branch_and_memory_tree('.')
1152
 
        wt.lock_write()
1153
 
        self.addCleanup(wt.unlock)
1154
 
        wt.add('')
1155
 
        wt.commit('rev-1', rev_id='rev-1',
1156
 
                  timestamp=1132586655, timezone=36000,
1157
 
                  committer='Joe Foo <joe@foo.com>')
1158
 
        wt.commit('rev-merged', rev_id='rev-2a',
1159
 
                  timestamp=1132586700, timezone=36000,
1160
 
                  committer='Joe Foo <joe@foo.com>')
1161
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1162
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1163
 
        wt.commit('rev-2', rev_id='rev-2b',
1164
 
                  timestamp=1132586800, timezone=36000,
1165
 
                  committer='Joe Foo <joe@foo.com>')
1166
 
        logfile = self.make_utf8_encoded_stringio()
1167
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1168
 
        log.show_log(wt.branch, formatter)
1169
 
        self.assertEqualDiff("""\
 
871
        wt = self._prepare_tree_with_merges()
 
872
        self.assertFormatterResult("""\
1170
873
2: Joe Foo 2005-11-22 [merge] rev-2
1171
874
  1.1.1: Joe Foo 2005-11-22 rev-merged
1172
875
1: Joe Foo 2005-11-22 rev-1
1173
876
""",
1174
 
                             logfile.getvalue())
1175
 
 
1176
 
class TestGetViewRevisions(tests.TestCaseWithTransport):
 
877
            wt.branch, log.LineLogFormatter,
 
878
            formatter_kwargs=dict(levels=0))
 
879
 
 
880
 
 
881
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
 
882
 
 
883
    def test_gnu_changelog(self):
 
884
        wt = self.make_standard_commit('nicky', authors=[])
 
885
        self.assertFormatterResult('''\
 
886
2005-11-22  Lorem Ipsum  <test@example.com>
 
887
 
 
888
\tadd a
 
889
 
 
890
''',
 
891
            wt.branch, log.GnuChangelogLogFormatter)
 
892
 
 
893
    def test_with_authors(self):
 
894
        wt = self.make_standard_commit('nicky',
 
895
            authors=['Fooa Fooz <foo@example.com>',
 
896
                     'Bari Baro <bar@example.com>'])
 
897
        self.assertFormatterResult('''\
 
898
2005-11-22  Fooa Fooz  <foo@example.com>
 
899
 
 
900
\tadd a
 
901
 
 
902
''',
 
903
            wt.branch, log.GnuChangelogLogFormatter)
 
904
 
 
905
    def test_verbose(self):
 
906
        wt = self.make_standard_commit('nicky')
 
907
        self.assertFormatterResult('''\
 
908
2005-11-22  John Doe  <jdoe@example.com>
 
909
 
 
910
\t* a:
 
911
 
 
912
\tadd a
 
913
 
 
914
''',
 
915
            wt.branch, log.GnuChangelogLogFormatter,
 
916
            show_log_kwargs=dict(verbose=True))
 
917
 
 
918
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
 
919
 
 
920
    def _get_view_revisions(self, *args, **kwargs):
 
921
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
922
                                    log.get_view_revisions, *args, **kwargs)
1177
923
 
1178
924
    def make_tree_with_commits(self):
1179
925
        """Create a tree with well-known revision ids"""
1180
926
        wt = self.make_branch_and_tree('tree1')
1181
 
        wt.commit('commit one', rev_id='1')
1182
 
        wt.commit('commit two', rev_id='2')
1183
 
        wt.commit('commit three', rev_id='3')
 
927
        self.wt_commit(wt, 'commit one', rev_id='1')
 
928
        self.wt_commit(wt, 'commit two', rev_id='2')
 
929
        self.wt_commit(wt, 'commit three', rev_id='3')
1184
930
        mainline_revs = [None, '1', '2', '3']
1185
931
        rev_nos = {'1': 1, '2': 2, '3': 3}
1186
932
        return mainline_revs, rev_nos, wt
1189
935
        """Create a tree with well-known revision ids and a merge"""
1190
936
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1191
937
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1192
 
        tree2.commit('four-a', rev_id='4a')
 
938
        self.wt_commit(tree2, 'four-a', rev_id='4a')
1193
939
        wt.merge_from_branch(tree2.branch)
1194
 
        wt.commit('four-b', rev_id='4b')
 
940
        self.wt_commit(wt, 'four-b', rev_id='4b')
1195
941
        mainline_revs.append('4b')
1196
942
        rev_nos['4b'] = 4
1197
943
        # 4a: 3.1.1
1198
944
        return mainline_revs, rev_nos, wt
1199
945
 
1200
 
    def make_tree_with_many_merges(self):
 
946
    def make_branch_with_many_merges(self):
1201
947
        """Create a tree with well-known revision ids"""
1202
 
        wt = self.make_branch_and_tree('tree1')
1203
 
        self.build_tree_contents([('tree1/f', '1\n')])
1204
 
        wt.add(['f'], ['f-id'])
1205
 
        wt.commit('commit one', rev_id='1')
1206
 
        wt.commit('commit two', rev_id='2')
1207
 
 
1208
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
1209
 
        self.build_tree_contents([('tree3/f', '1\n2\n3a\n')])
1210
 
        tree3.commit('commit three a', rev_id='3a')
1211
 
 
1212
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1213
 
        tree2.merge_from_branch(tree3.branch)
1214
 
        tree2.commit('commit three b', rev_id='3b')
1215
 
 
1216
 
        wt.merge_from_branch(tree2.branch)
1217
 
        wt.commit('commit three c', rev_id='3c')
1218
 
        tree2.commit('four-a', rev_id='4a')
1219
 
 
1220
 
        wt.merge_from_branch(tree2.branch)
1221
 
        wt.commit('four-b', rev_id='4b')
 
948
        builder = self.make_branch_builder('tree1')
 
949
        builder.start_series()
 
950
        builder.build_snapshot('1', None, [
 
951
            ('add', ('', 'TREE_ROOT', 'directory', '')),
 
952
            ('add', ('f', 'f-id', 'file', '1\n'))])
 
953
        builder.build_snapshot('2', ['1'], [])
 
954
        builder.build_snapshot('3a', ['2'], [
 
955
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
956
        builder.build_snapshot('3b', ['2', '3a'], [
 
957
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
958
        builder.build_snapshot('3c', ['2', '3b'], [
 
959
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
960
        builder.build_snapshot('4a', ['3b'], [])
 
961
        builder.build_snapshot('4b', ['3c', '4a'], [])
 
962
        builder.finish_series()
 
963
 
 
964
        # 1
 
965
        # |
 
966
        # 2-.
 
967
        # |\ \
 
968
        # | | 3a
 
969
        # | |/
 
970
        # | 3b
 
971
        # |/|
 
972
        # 3c4a
 
973
        # |/
 
974
        # 4b
1222
975
 
1223
976
        mainline_revs = [None, '1', '2', '3c', '4b']
1224
977
        rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
1231
984
            '4a': '2.2.2', # second commit tree 2
1232
985
            '4b': '4', # merges 4a to main
1233
986
            }
1234
 
        return mainline_revs, rev_nos, wt
 
987
        return mainline_revs, rev_nos, builder.get_branch()
1235
988
 
1236
989
    def test_get_view_revisions_forward(self):
1237
990
        """Test the get_view_revisions method"""
1238
991
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1239
992
        wt.lock_read()
1240
993
        self.addCleanup(wt.unlock)
1241
 
        revisions = list(log.get_view_revisions(
 
994
        revisions = list(self._get_view_revisions(
1242
995
                mainline_revs, rev_nos, wt.branch, 'forward'))
1243
996
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1244
997
                         revisions)
1245
 
        revisions2 = list(log.get_view_revisions(
 
998
        revisions2 = list(self._get_view_revisions(
1246
999
                mainline_revs, rev_nos, wt.branch, 'forward',
1247
1000
                include_merges=False))
1248
1001
        self.assertEqual(revisions, revisions2)
1252
1005
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1253
1006
        wt.lock_read()
1254
1007
        self.addCleanup(wt.unlock)
1255
 
        revisions = list(log.get_view_revisions(
 
1008
        revisions = list(self._get_view_revisions(
1256
1009
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1257
1010
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1258
1011
                         revisions)
1259
 
        revisions2 = list(log.get_view_revisions(
 
1012
        revisions2 = list(self._get_view_revisions(
1260
1013
                mainline_revs, rev_nos, wt.branch, 'reverse',
1261
1014
                include_merges=False))
1262
1015
        self.assertEqual(revisions, revisions2)
1266
1019
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1267
1020
        wt.lock_read()
1268
1021
        self.addCleanup(wt.unlock)
1269
 
        revisions = list(log.get_view_revisions(
 
1022
        revisions = list(self._get_view_revisions(
1270
1023
                mainline_revs, rev_nos, wt.branch, 'forward'))
1271
1024
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1272
1025
                          ('4b', '4', 0), ('4a', '3.1.1', 1)],
1273
1026
                         revisions)
1274
 
        revisions = list(log.get_view_revisions(
 
1027
        revisions = list(self._get_view_revisions(
1275
1028
                mainline_revs, rev_nos, wt.branch, 'forward',
1276
1029
                include_merges=False))
1277
1030
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1283
1036
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1284
1037
        wt.lock_read()
1285
1038
        self.addCleanup(wt.unlock)
1286
 
        revisions = list(log.get_view_revisions(
 
1039
        revisions = list(self._get_view_revisions(
1287
1040
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1288
1041
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1289
1042
                          ('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1290
1043
                         revisions)
1291
 
        revisions = list(log.get_view_revisions(
 
1044
        revisions = list(self._get_view_revisions(
1292
1045
                mainline_revs, rev_nos, wt.branch, 'reverse',
1293
1046
                include_merges=False))
1294
1047
        self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1297
1050
 
1298
1051
    def test_get_view_revisions_merge2(self):
1299
1052
        """Test get_view_revisions when there are merges"""
1300
 
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1301
 
        wt.lock_read()
1302
 
        self.addCleanup(wt.unlock)
1303
 
        revisions = list(log.get_view_revisions(
1304
 
                mainline_revs, rev_nos, wt.branch, 'forward'))
 
1053
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
 
1054
        b.lock_read()
 
1055
        self.addCleanup(b.unlock)
 
1056
        revisions = list(self._get_view_revisions(
 
1057
                mainline_revs, rev_nos, b, 'forward'))
1305
1058
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1306
 
                    ('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
 
1059
                    ('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1307
1060
                    ('4a', '2.2.2', 1)]
1308
1061
        self.assertEqual(expected, revisions)
1309
 
        revisions = list(log.get_view_revisions(
1310
 
                mainline_revs, rev_nos, wt.branch, 'forward',
 
1062
        revisions = list(self._get_view_revisions(
 
1063
                mainline_revs, rev_nos, b, 'forward',
1311
1064
                include_merges=False))
1312
1065
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1313
1066
                          ('4b', '4', 0)],
1314
1067
                         revisions)
1315
1068
 
1316
 
 
1317
1069
    def test_file_id_for_range(self):
1318
 
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1319
 
        wt.lock_read()
1320
 
        self.addCleanup(wt.unlock)
 
1070
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
 
1071
        b.lock_read()
 
1072
        self.addCleanup(b.unlock)
1321
1073
 
1322
1074
        def rev_from_rev_id(revid, branch):
1323
1075
            revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1324
1076
            return revspec.in_history(branch)
1325
1077
 
1326
1078
        def view_revs(start_rev, end_rev, file_id, direction):
1327
 
            revs = log.calculate_view_revisions(
1328
 
                wt.branch,
 
1079
            revs = self.applyDeprecated(
 
1080
                symbol_versioning.deprecated_in((2, 2, 0)),
 
1081
                log.calculate_view_revisions,
 
1082
                b,
1329
1083
                start_rev, # start_revision
1330
1084
                end_rev, # end_revision
1331
1085
                direction, # direction
1334
1088
                )
1335
1089
            return revs
1336
1090
 
1337
 
        rev_3a = rev_from_rev_id('3a', wt.branch)
1338
 
        rev_4b = rev_from_rev_id('4b', wt.branch)
1339
 
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
 
1091
        rev_3a = rev_from_rev_id('3a', b)
 
1092
        rev_4b = rev_from_rev_id('4b', b)
 
1093
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1094
                          ('3a', '2.1.1', 2)],
1340
1095
                          view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1341
1096
        # Note: 3c still appears before 3a here because of depth-based sorting
1342
 
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
 
1097
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1098
                          ('3a', '2.1.1', 2)],
1343
1099
                          view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1344
1100
 
1345
1101
 
1346
1102
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1347
1103
 
 
1104
    def get_view_revisions(self, *args):
 
1105
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
1106
                                    log.get_view_revisions, *args)
 
1107
 
1348
1108
    def create_tree_with_single_merge(self):
1349
1109
        """Create a branch with a moderate layout.
1350
1110
 
1368
1128
        #       use it. Since 'log' only uses the tree in a readonly
1369
1129
        #       fashion, it seems a shame to regenerate an identical
1370
1130
        #       tree for each test.
 
1131
        # TODO: vila 20100122 One way to address the shame above will be to
 
1132
        #       create a memory tree during test parametrization and give a
 
1133
        #       *copy* of this tree to each test. Copying a memory tree ought
 
1134
        #       to be cheap, at least cheaper than creating them with such
 
1135
        #       complex setups.
1371
1136
        tree = self.make_branch_and_tree('tree')
1372
1137
        tree.lock_write()
1373
1138
        self.addCleanup(tree.unlock)
1448
1213
        mainline = tree.branch.revision_history()
1449
1214
        mainline.insert(0, None)
1450
1215
        revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1451
 
        view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1452
 
                                                'reverse', True)
 
1216
        view_revs_iter = self.get_view_revisions(
 
1217
            mainline, revnos, tree.branch, 'reverse', True)
1453
1218
        actual_revs = log._filter_revisions_touching_file_id(
1454
 
                            tree.branch,
1455
 
                            file_id,
1456
 
                            list(view_revs_iter))
 
1219
            tree.branch, file_id, list(view_revs_iter))
1457
1220
        self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1458
1221
 
1459
1222
    def test_file_id_f1(self):
1511
1274
 
1512
1275
class TestLogFormatter(tests.TestCase):
1513
1276
 
 
1277
    def setUp(self):
 
1278
        super(TestLogFormatter, self).setUp()
 
1279
        self.rev = revision.Revision('a-id')
 
1280
        self.lf = log.LogFormatter(None)
 
1281
 
1514
1282
    def test_short_committer(self):
1515
 
        rev = revision.Revision('a-id')
1516
 
        rev.committer = 'John Doe <jdoe@example.com>'
1517
 
        lf = log.LogFormatter(None)
1518
 
        self.assertEqual('John Doe', lf.short_committer(rev))
1519
 
        rev.committer = 'John Smith <jsmith@example.com>'
1520
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1521
 
        rev.committer = 'John Smith'
1522
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1523
 
        rev.committer = 'jsmith@example.com'
1524
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1525
 
        rev.committer = '<jsmith@example.com>'
1526
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1527
 
        rev.committer = 'John Smith jsmith@example.com'
1528
 
        self.assertEqual('John Smith', lf.short_committer(rev))
 
1283
        def assertCommitter(expected, committer):
 
1284
            self.rev.committer = committer
 
1285
            self.assertEqual(expected, self.lf.short_committer(self.rev))
 
1286
 
 
1287
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
 
1288
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
 
1289
        assertCommitter('John Smith', 'John Smith')
 
1290
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
 
1291
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
 
1292
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
1529
1293
 
1530
1294
    def test_short_author(self):
1531
 
        rev = revision.Revision('a-id')
1532
 
        rev.committer = 'John Doe <jdoe@example.com>'
1533
 
        lf = log.LogFormatter(None)
1534
 
        self.assertEqual('John Doe', lf.short_author(rev))
1535
 
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
1536
 
        self.assertEqual('John Smith', lf.short_author(rev))
1537
 
        rev.properties['author'] = 'John Smith'
1538
 
        self.assertEqual('John Smith', lf.short_author(rev))
1539
 
        rev.properties['author'] = 'jsmith@example.com'
1540
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1541
 
        rev.properties['author'] = '<jsmith@example.com>'
1542
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1543
 
        rev.properties['author'] = 'John Smith jsmith@example.com'
1544
 
        self.assertEqual('John Smith', lf.short_author(rev))
1545
 
        del rev.properties['author']
1546
 
        rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1547
 
                'Jane Rey <jrey@example.com>')
1548
 
        self.assertEqual('John Smith', lf.short_author(rev))
 
1295
        def assertAuthor(expected, author):
 
1296
            self.rev.properties['author'] = author
 
1297
            self.assertEqual(expected, self.lf.short_author(self.rev))
 
1298
 
 
1299
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
 
1300
        assertAuthor('John Smith', 'John Smith')
 
1301
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
 
1302
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
 
1303
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
 
1304
 
 
1305
    def test_short_author_from_committer(self):
 
1306
        self.rev.committer = 'John Doe <jdoe@example.com>'
 
1307
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
 
1308
 
 
1309
    def test_short_author_from_authors(self):
 
1310
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
 
1311
                                          'Jane Rey <jrey@example.com>')
 
1312
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
1549
1313
 
1550
1314
 
1551
1315
class TestReverseByDepth(tests.TestCase):
1697
1461
        log.show_branch_change(tree.branch, s, 3, '3b')
1698
1462
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1699
1463
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
 
1464
 
 
1465
 
 
1466
 
 
1467
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
 
1468
 
 
1469
    def setUp(self):
 
1470
        TestCaseForLogFormatter.setUp(self)
 
1471
        log.properties_handler_registry.register(
 
1472
            'bugs_properties_handler',
 
1473
            log._bugs_properties_handler)
 
1474
 
 
1475
    def make_commits_with_bugs(self):
 
1476
        """Helper method for LogFormatter tests"""
 
1477
        tree = self.make_branch_and_tree(u'.')
 
1478
        self.build_tree(['a', 'b'])
 
1479
        tree.add('a')
 
1480
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1481
                       revprops={'bugs': 'test://bug/id fixed'})
 
1482
        tree.add('b')
 
1483
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
 
1484
                       authors=['Joe Bar <joe@bar.com>'],
 
1485
                       revprops={'bugs': 'test://bug/id fixed\n'
 
1486
                                 'test://bug/2 fixed'})
 
1487
        return tree
 
1488
 
 
1489
 
 
1490
    def test_long_bugs(self):
 
1491
        tree = self.make_commits_with_bugs()
 
1492
        self.assertFormatterResult("""\
 
1493
------------------------------------------------------------
 
1494
revno: 2
 
1495
fixes bug(s): test://bug/id test://bug/2
 
1496
author: Joe Bar <joe@bar.com>
 
1497
committer: Joe Foo <joe@foo.com>
 
1498
branch nick: work
 
1499
timestamp: Tue 2005-11-22 00:00:01 +0000
 
1500
message:
 
1501
  multiline
 
1502
  log
 
1503
  message
 
1504
------------------------------------------------------------
 
1505
revno: 1
 
1506
fixes bug(s): test://bug/id
 
1507
committer: Joe Foo <joe@foo.com>
 
1508
branch nick: work
 
1509
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1510
message:
 
1511
  simple log message
 
1512
""",
 
1513
            tree.branch, log.LongLogFormatter)
 
1514
 
 
1515
    def test_short_bugs(self):
 
1516
        tree = self.make_commits_with_bugs()
 
1517
        self.assertFormatterResult("""\
 
1518
    2 Joe Bar\t2005-11-22
 
1519
      fixes bug(s): test://bug/id test://bug/2
 
1520
      multiline
 
1521
      log
 
1522
      message
 
1523
 
 
1524
    1 Joe Foo\t2005-11-22
 
1525
      fixes bug(s): test://bug/id
 
1526
      simple log message
 
1527
 
 
1528
""",
 
1529
            tree.branch, log.ShortLogFormatter)
 
1530
 
 
1531
    def test_wrong_bugs_property(self):
 
1532
        tree = self.make_branch_and_tree(u'.')
 
1533
        self.build_tree(['foo'])
 
1534
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1535
                       revprops={'bugs': 'test://bug/id invalid_value'})
 
1536
        self.assertFormatterResult("""\
 
1537
    1 Joe Foo\t2005-11-22
 
1538
      simple log message
 
1539
 
 
1540
""",
 
1541
            tree.branch, log.ShortLogFormatter)
 
1542
 
 
1543
    def test_bugs_handler_present(self):
 
1544
        self.properties_handler_registry.get('bugs_properties_handler')
 
1545
 
 
1546
 
 
1547
class TestLogForAuthors(TestCaseForLogFormatter):
 
1548
 
 
1549
    def setUp(self):
 
1550
        TestCaseForLogFormatter.setUp(self)
 
1551
        self.wt = self.make_standard_commit('nicky',
 
1552
            authors=['John Doe <jdoe@example.com>',
 
1553
                     'Jane Rey <jrey@example.com>'])
 
1554
 
 
1555
    def assertFormatterResult(self, formatter, who, result):
 
1556
        formatter_kwargs = dict()
 
1557
        if who is not None:
 
1558
            author_list_handler = log.author_list_registry.get(who)
 
1559
            formatter_kwargs['author_list_handler'] = author_list_handler
 
1560
        TestCaseForLogFormatter.assertFormatterResult(self, result,
 
1561
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
 
1562
 
 
1563
    def test_line_default(self):
 
1564
        self.assertFormatterResult(log.LineLogFormatter, None, """\
 
1565
1: John Doe 2005-11-22 add a
 
1566
""")
 
1567
 
 
1568
    def test_line_committer(self):
 
1569
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
 
1570
1: Lorem Ipsum 2005-11-22 add a
 
1571
""")
 
1572
 
 
1573
    def test_line_first(self):
 
1574
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
 
1575
1: John Doe 2005-11-22 add a
 
1576
""")
 
1577
 
 
1578
    def test_line_all(self):
 
1579
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
 
1580
1: John Doe, Jane Rey 2005-11-22 add a
 
1581
""")
 
1582
 
 
1583
 
 
1584
    def test_short_default(self):
 
1585
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
 
1586
    1 John Doe\t2005-11-22
 
1587
      add a
 
1588
 
 
1589
""")
 
1590
 
 
1591
    def test_short_committer(self):
 
1592
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
 
1593
    1 Lorem Ipsum\t2005-11-22
 
1594
      add a
 
1595
 
 
1596
""")
 
1597
 
 
1598
    def test_short_first(self):
 
1599
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
 
1600
    1 John Doe\t2005-11-22
 
1601
      add a
 
1602
 
 
1603
""")
 
1604
 
 
1605
    def test_short_all(self):
 
1606
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
 
1607
    1 John Doe, Jane Rey\t2005-11-22
 
1608
      add a
 
1609
 
 
1610
""")
 
1611
 
 
1612
    def test_long_default(self):
 
1613
        self.assertFormatterResult(log.LongLogFormatter, None, """\
 
1614
------------------------------------------------------------
 
1615
revno: 1
 
1616
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1617
committer: Lorem Ipsum <test@example.com>
 
1618
branch nick: nicky
 
1619
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1620
message:
 
1621
  add a
 
1622
""")
 
1623
 
 
1624
    def test_long_committer(self):
 
1625
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
 
1626
------------------------------------------------------------
 
1627
revno: 1
 
1628
committer: Lorem Ipsum <test@example.com>
 
1629
branch nick: nicky
 
1630
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1631
message:
 
1632
  add a
 
1633
""")
 
1634
 
 
1635
    def test_long_first(self):
 
1636
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
 
1637
------------------------------------------------------------
 
1638
revno: 1
 
1639
author: John Doe <jdoe@example.com>
 
1640
committer: Lorem Ipsum <test@example.com>
 
1641
branch nick: nicky
 
1642
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1643
message:
 
1644
  add a
 
1645
""")
 
1646
 
 
1647
    def test_long_all(self):
 
1648
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
 
1649
------------------------------------------------------------
 
1650
revno: 1
 
1651
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1652
committer: Lorem Ipsum <test@example.com>
 
1653
branch nick: nicky
 
1654
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1655
message:
 
1656
  add a
 
1657
""")
 
1658
 
 
1659
    def test_gnu_changelog_default(self):
 
1660
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
 
1661
2005-11-22  John Doe  <jdoe@example.com>
 
1662
 
 
1663
\tadd a
 
1664
 
 
1665
""")
 
1666
 
 
1667
    def test_gnu_changelog_committer(self):
 
1668
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
 
1669
2005-11-22  Lorem Ipsum  <test@example.com>
 
1670
 
 
1671
\tadd a
 
1672
 
 
1673
""")
 
1674
 
 
1675
    def test_gnu_changelog_first(self):
 
1676
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
 
1677
2005-11-22  John Doe  <jdoe@example.com>
 
1678
 
 
1679
\tadd a
 
1680
 
 
1681
""")
 
1682
 
 
1683
    def test_gnu_changelog_all(self):
 
1684
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
 
1685
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
 
1686
 
 
1687
\tadd a
 
1688
 
 
1689
""")
 
1690
 
 
1691
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
 
1692
 
 
1693
    def make_branch_with_alternate_ancestries(self, relpath='.'):
 
1694
        # See test_merge_sorted_exclude_ancestry below for the difference with
 
1695
        # bt.per_branch.test_iter_merge_sorted_revision.
 
1696
        # TestIterMergeSortedRevisionsBushyGraph. 
 
1697
        # make_branch_with_alternate_ancestries
 
1698
        # and test_merge_sorted_exclude_ancestry
 
1699
        # See the FIXME in assertLogRevnos too.
 
1700
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
 
1701
        # 1
 
1702
        # |\
 
1703
        # 2 \
 
1704
        # |  |
 
1705
        # |  1.1.1
 
1706
        # |  | \
 
1707
        # |  |  1.2.1
 
1708
        # |  | /
 
1709
        # |  1.1.2
 
1710
        # | /
 
1711
        # 3
 
1712
        builder.start_series()
 
1713
        builder.build_snapshot('1', None, [
 
1714
            ('add', ('', 'TREE_ROOT', 'directory', '')),])
 
1715
        builder.build_snapshot('1.1.1', ['1'], [])
 
1716
        builder.build_snapshot('2', ['1'], [])
 
1717
        builder.build_snapshot('1.2.1', ['1.1.1'], [])
 
1718
        builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
 
1719
        builder.build_snapshot('3', ['2', '1.1.2'], [])
 
1720
        builder.finish_series()
 
1721
        br = builder.get_branch()
 
1722
        br.lock_read()
 
1723
        self.addCleanup(br.unlock)
 
1724
        return br
 
1725
 
 
1726
    def assertLogRevnos(self, expected_revnos, b, start, end,
 
1727
                        exclude_common_ancestry, generate_merge_revisions=True):
 
1728
        # FIXME: the layering in log makes it hard to test intermediate levels,
 
1729
        # I wish adding filters with their parameters were easier...
 
1730
        # -- vila 20100413
 
1731
        iter_revs = log._calc_view_revisions(
 
1732
            b, start, end, direction='reverse',
 
1733
            generate_merge_revisions=generate_merge_revisions,
 
1734
            exclude_common_ancestry=exclude_common_ancestry)
 
1735
        self.assertEqual(expected_revnos,
 
1736
                         [revid for revid, revno, depth in iter_revs])
 
1737
 
 
1738
    def test_merge_sorted_exclude_ancestry(self):
 
1739
        b = self.make_branch_with_alternate_ancestries()
 
1740
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
 
1741
                             b, '1', '3', exclude_common_ancestry=False)
 
1742
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
 
1743
        # it should be mentioned even if merge_sort order will make it appear
 
1744
        # after 1.1.1
 
1745
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
 
1746
                             b, '1.1.1', '3', exclude_common_ancestry=True)
 
1747
 
 
1748
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
 
1749
        b = self.make_branch_with_alternate_ancestries()
 
1750
        self.assertLogRevnos(['3', '2'],
 
1751
                             b, '1', '3', exclude_common_ancestry=True,
 
1752
                             generate_merge_revisions=False)
 
1753
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
 
1754
                             b, '1', '3', exclude_common_ancestry=True,
 
1755
                             generate_merge_revisions=True)
 
1756