~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-03-02 08:49:07 UTC
  • mfrom: (5067.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100302084907-z4r0yoa4ldspjz82
(vila) Resolve --take-this or --take-other correctly rename kept file

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
23
23
    registry,
24
24
    revision,
25
25
    revisionspec,
 
26
    symbol_versioning,
26
27
    tests,
27
28
    )
28
29
 
29
30
 
30
 
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
 
31
class TestLogMixin(object):
 
32
 
 
33
    def wt_commit(self, wt, message, **kwargs):
 
34
        """Use some mostly fixed values for commits to simplify tests.
 
35
 
 
36
        Tests can use this function to get some commit attributes. The time
 
37
        stamp is incremented at each commit.
 
38
        """
 
39
        if getattr(self, 'timestamp', None) is None:
 
40
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
 
41
        else:
 
42
            self.timestamp += 1 # 1 second between each commit
 
43
        kwargs.setdefault('timestamp', self.timestamp)
 
44
        kwargs.setdefault('timezone', 0) # UTC
 
45
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
 
46
 
 
47
        return wt.commit(message, **kwargs)
 
48
 
 
49
 
 
50
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
31
51
 
32
52
    def setUp(self):
33
 
        super(TestCaseWithoutPropsHandler, self).setUp()
 
53
        super(TestCaseForLogFormatter, self).setUp()
34
54
        # keep a reference to the "current" custom prop. handler registry
35
55
        self.properties_handler_registry = log.properties_handler_registry
36
56
        # Use a clean registry for log
40
60
            log.properties_handler_registry = self.properties_handler_registry
41
61
        self.addCleanup(restore)
42
62
 
 
63
    def assertFormatterResult(self, result, branch, formatter_class,
 
64
                              formatter_kwargs=None, show_log_kwargs=None):
 
65
        logfile = self.make_utf8_encoded_stringio()
 
66
        if formatter_kwargs is None:
 
67
            formatter_kwargs = {}
 
68
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
 
69
        if show_log_kwargs is None:
 
70
            show_log_kwargs = {}
 
71
        log.show_log(branch, formatter, **show_log_kwargs)
 
72
        self.assertEqualDiff(result, logfile.getvalue())
 
73
 
 
74
    def make_standard_commit(self, branch_nick, **kwargs):
 
75
        wt = self.make_branch_and_tree('.')
 
76
        wt.lock_write()
 
77
        self.addCleanup(wt.unlock)
 
78
        self.build_tree(['a'])
 
79
        wt.add(['a'])
 
80
        wt.branch.nick = branch_nick
 
81
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
 
82
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
 
83
        self.wt_commit(wt, 'add a', **kwargs)
 
84
        return wt
 
85
 
 
86
    def make_commits_with_trailing_newlines(self, wt):
 
87
        """Helper method for LogFormatter tests"""
 
88
        b = wt.branch
 
89
        b.nick = 'test'
 
90
        self.build_tree_contents([('a', 'hello moto\n')])
 
91
        self.wt_commit(wt, 'simple log message', rev_id='a1')
 
92
        self.build_tree_contents([('b', 'goodbye\n')])
 
93
        wt.add('b')
 
94
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
 
95
 
 
96
        self.build_tree_contents([('c', 'just another manic monday\n')])
 
97
        wt.add('c')
 
98
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
 
99
        return b
 
100
 
 
101
    def _prepare_tree_with_merges(self, with_tags=False):
 
102
        wt = self.make_branch_and_memory_tree('.')
 
103
        wt.lock_write()
 
104
        self.addCleanup(wt.unlock)
 
105
        wt.add('')
 
106
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
 
107
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
 
108
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
109
        wt.branch.set_last_revision_info(1, 'rev-1')
 
110
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
 
111
        if with_tags:
 
112
            branch = wt.branch
 
113
            branch.tags.set_tag('v0.2', 'rev-2b')
 
114
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
 
115
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
116
            branch.tags.set_tag('v1.0', 'rev-3')
 
117
        return wt
43
118
 
44
119
class LogCatcher(log.LogFormatter):
45
120
    """Pull log messages into a list rather than displaying them.
49
124
    being dependent on the formatting.
50
125
    """
51
126
 
 
127
    supports_merge_revisions = True
52
128
    supports_delta = True
 
129
    supports_diff = True
 
130
    preferred_levels = 0
53
131
 
54
 
    def __init__(self):
55
 
        super(LogCatcher, self).__init__(to_file=None)
 
132
    def __init__(self, *args, **kwargs):
 
133
        kwargs.update(dict(to_file=None))
 
134
        super(LogCatcher, self).__init__(*args, **kwargs)
56
135
        self.revisions = []
57
136
 
58
137
    def log_revision(self, revision):
201
280
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
202
281
 
203
282
 
204
 
def make_commits_with_trailing_newlines(wt):
205
 
    """Helper method for LogFormatter tests"""
206
 
    b = wt.branch
207
 
    b.nick='test'
208
 
    open('a', 'wb').write('hello moto\n')
209
 
    wt.add('a')
210
 
    wt.commit('simple log message', rev_id='a1',
211
 
              timestamp=1132586655.459960938, timezone=-6*3600,
212
 
              committer='Joe Foo <joe@foo.com>')
213
 
    open('b', 'wb').write('goodbye\n')
214
 
    wt.add('b')
215
 
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
216
 
              timestamp=1132586842.411175966, timezone=-6*3600,
217
 
              committer='Joe Foo <joe@foo.com>',
218
 
              authors=['Joe Bar <joe@bar.com>'])
219
 
 
220
 
    open('c', 'wb').write('just another manic monday\n')
221
 
    wt.add('c')
222
 
    wt.commit('single line with trailing newline\n', rev_id='a3',
223
 
              timestamp=1132587176.835228920, timezone=-6*3600,
224
 
              committer = 'Joe Foo <joe@foo.com>')
225
 
    return b
226
 
 
227
 
 
228
 
def normalize_log(log):
229
 
    """Replaces the variable lines of logs with fixed lines"""
230
 
    author = 'author: Dolor Sit <test@example.com>'
231
 
    committer = 'committer: Lorem Ipsum <test@example.com>'
232
 
    lines = log.splitlines(True)
233
 
    for idx,line in enumerate(lines):
234
 
        stripped_line = line.lstrip()
235
 
        indent = ' ' * (len(line) - len(stripped_line))
236
 
        if stripped_line.startswith('author:'):
237
 
            lines[idx] = indent + author + '\n'
238
 
        elif stripped_line.startswith('committer:'):
239
 
            lines[idx] = indent + committer + '\n'
240
 
        elif stripped_line.startswith('timestamp:'):
241
 
            lines[idx] = indent + 'timestamp: Just now\n'
242
 
    return ''.join(lines)
243
 
 
244
 
 
245
 
class TestShortLogFormatter(tests.TestCaseWithTransport):
 
283
class TestShortLogFormatter(TestCaseForLogFormatter):
246
284
 
247
285
    def test_trailing_newlines(self):
248
286
        wt = self.make_branch_and_tree('.')
249
 
        b = make_commits_with_trailing_newlines(wt)
250
 
        sio = self.make_utf8_encoded_stringio()
251
 
        lf = log.ShortLogFormatter(to_file=sio)
252
 
        log.show_log(b, lf)
253
 
        self.assertEqualDiff("""\
254
 
    3 Joe Foo\t2005-11-21
 
287
        b = self.make_commits_with_trailing_newlines(wt)
 
288
        self.assertFormatterResult("""\
 
289
    3 Joe Foo\t2005-11-22
255
290
      single line with trailing newline
256
291
 
257
 
    2 Joe Bar\t2005-11-21
 
292
    2 Joe Foo\t2005-11-22
258
293
      multiline
259
294
      log
260
295
      message
261
296
 
262
 
    1 Joe Foo\t2005-11-21
 
297
    1 Joe Foo\t2005-11-22
263
298
      simple log message
264
299
 
265
300
""",
266
 
                             sio.getvalue())
267
 
 
268
 
    def _prepare_tree_with_merges(self, with_tags=False):
269
 
        wt = self.make_branch_and_memory_tree('.')
270
 
        wt.lock_write()
271
 
        self.addCleanup(wt.unlock)
272
 
        wt.add('')
273
 
        wt.commit('rev-1', rev_id='rev-1',
274
 
                  timestamp=1132586655, timezone=36000,
275
 
                  committer='Joe Foo <joe@foo.com>')
276
 
        wt.commit('rev-merged', rev_id='rev-2a',
277
 
                  timestamp=1132586700, timezone=36000,
278
 
                  committer='Joe Foo <joe@foo.com>')
279
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
280
 
        wt.branch.set_last_revision_info(1, 'rev-1')
281
 
        wt.commit('rev-2', rev_id='rev-2b',
282
 
                  timestamp=1132586800, timezone=36000,
283
 
                  committer='Joe Foo <joe@foo.com>')
284
 
        if with_tags:
285
 
            branch = wt.branch
286
 
            branch.tags.set_tag('v0.2', 'rev-2b')
287
 
            wt.commit('rev-3', rev_id='rev-3',
288
 
                      timestamp=1132586900, timezone=36000,
289
 
                      committer='Jane Foo <jane@foo.com>')
290
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
291
 
            branch.tags.set_tag('v1.0', 'rev-3')
292
 
        return wt
 
301
            b, log.ShortLogFormatter)
293
302
 
294
303
    def test_short_log_with_merges(self):
295
304
        wt = self._prepare_tree_with_merges()
296
 
        logfile = self.make_utf8_encoded_stringio()
297
 
        formatter = log.ShortLogFormatter(to_file=logfile)
298
 
        log.show_log(wt.branch, formatter)
299
 
        self.assertEqualDiff("""\
 
305
        self.assertFormatterResult("""\
300
306
    2 Joe Foo\t2005-11-22 [merge]
301
307
      rev-2
302
308
 
304
310
      rev-1
305
311
 
306
312
""",
307
 
                             logfile.getvalue())
 
313
            wt.branch, log.ShortLogFormatter)
308
314
 
309
315
    def test_short_log_with_merges_and_advice(self):
310
316
        wt = self._prepare_tree_with_merges()
311
 
        logfile = self.make_utf8_encoded_stringio()
312
 
        formatter = log.ShortLogFormatter(to_file=logfile,
313
 
            show_advice=True)
314
 
        log.show_log(wt.branch, formatter)
315
 
        self.assertEqualDiff("""\
 
317
        self.assertFormatterResult("""\
316
318
    2 Joe Foo\t2005-11-22 [merge]
317
319
      rev-2
318
320
 
321
323
 
322
324
Use --include-merges or -n0 to see merged revisions.
323
325
""",
324
 
                             logfile.getvalue())
 
326
            wt.branch, log.ShortLogFormatter,
 
327
            formatter_kwargs=dict(show_advice=True))
325
328
 
326
329
    def test_short_log_with_merges_and_range(self):
327
 
        wt = self.make_branch_and_memory_tree('.')
328
 
        wt.lock_write()
329
 
        self.addCleanup(wt.unlock)
330
 
        wt.add('')
331
 
        wt.commit('rev-1', rev_id='rev-1',
332
 
                  timestamp=1132586655, timezone=36000,
333
 
                  committer='Joe Foo <joe@foo.com>')
334
 
        wt.commit('rev-merged', rev_id='rev-2a',
335
 
                  timestamp=1132586700, timezone=36000,
336
 
                  committer='Joe Foo <joe@foo.com>')
337
 
        wt.branch.set_last_revision_info(1, 'rev-1')
338
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
339
 
        wt.commit('rev-2b', rev_id='rev-2b',
340
 
                  timestamp=1132586800, timezone=36000,
341
 
                  committer='Joe Foo <joe@foo.com>')
342
 
        wt.commit('rev-3a', rev_id='rev-3a',
343
 
                  timestamp=1132586800, timezone=36000,
344
 
                  committer='Joe Foo <joe@foo.com>')
 
330
        wt = self._prepare_tree_with_merges()
 
331
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
345
332
        wt.branch.set_last_revision_info(2, 'rev-2b')
346
333
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
347
 
        wt.commit('rev-3b', rev_id='rev-3b',
348
 
                  timestamp=1132586800, timezone=36000,
349
 
                  committer='Joe Foo <joe@foo.com>')
350
 
        logfile = self.make_utf8_encoded_stringio()
351
 
        formatter = log.ShortLogFormatter(to_file=logfile)
352
 
        log.show_log(wt.branch, formatter,
353
 
            start_revision=2, end_revision=3)
354
 
        self.assertEqualDiff("""\
 
334
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
 
335
        self.assertFormatterResult("""\
355
336
    3 Joe Foo\t2005-11-22 [merge]
356
337
      rev-3b
357
338
 
358
339
    2 Joe Foo\t2005-11-22 [merge]
359
 
      rev-2b
 
340
      rev-2
360
341
 
361
342
""",
362
 
                             logfile.getvalue())
 
343
            wt.branch, log.ShortLogFormatter,
 
344
            show_log_kwargs=dict(start_revision=2, end_revision=3))
363
345
 
364
346
    def test_short_log_with_tags(self):
365
347
        wt = self._prepare_tree_with_merges(with_tags=True)
366
 
        logfile = self.make_utf8_encoded_stringio()
367
 
        formatter = log.ShortLogFormatter(to_file=logfile)
368
 
        log.show_log(wt.branch, formatter)
369
 
        self.assertEqualDiff("""\
370
 
    3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
 
348
        self.assertFormatterResult("""\
 
349
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
371
350
      rev-3
372
351
 
373
352
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
377
356
      rev-1
378
357
 
379
358
""",
380
 
                             logfile.getvalue())
 
359
            wt.branch, log.ShortLogFormatter)
381
360
 
382
361
    def test_short_log_single_merge_revision(self):
383
 
        wt = self.make_branch_and_memory_tree('.')
384
 
        wt.lock_write()
385
 
        self.addCleanup(wt.unlock)
386
 
        wt.add('')
387
 
        wt.commit('rev-1', rev_id='rev-1',
388
 
                  timestamp=1132586655, timezone=36000,
389
 
                  committer='Joe Foo <joe@foo.com>')
390
 
        wt.commit('rev-merged', rev_id='rev-2a',
391
 
                  timestamp=1132586700, timezone=36000,
392
 
                  committer='Joe Foo <joe@foo.com>')
393
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
394
 
        wt.branch.set_last_revision_info(1, 'rev-1')
395
 
        wt.commit('rev-2', rev_id='rev-2b',
396
 
                  timestamp=1132586800, timezone=36000,
397
 
                  committer='Joe Foo <joe@foo.com>')
398
 
        logfile = self.make_utf8_encoded_stringio()
399
 
        formatter = log.ShortLogFormatter(to_file=logfile)
 
362
        wt = self._prepare_tree_with_merges()
400
363
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
401
 
        wtb = wt.branch
402
 
        rev = revspec.in_history(wtb)
403
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
404
 
        self.assertEqualDiff("""\
 
364
        rev = revspec.in_history(wt.branch)
 
365
        self.assertFormatterResult("""\
405
366
      1.1.1 Joe Foo\t2005-11-22
406
367
            rev-merged
407
368
 
408
369
""",
409
 
                             logfile.getvalue())
410
 
 
411
 
 
412
 
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
370
            wt.branch, log.ShortLogFormatter,
 
371
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
372
 
 
373
 
 
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
413
375
 
414
376
    def test_short_merge_revs_log_with_merges(self):
415
 
        wt = self.make_branch_and_memory_tree('.')
416
 
        wt.lock_write()
417
 
        self.addCleanup(wt.unlock)
418
 
        wt.add('')
419
 
        wt.commit('rev-1', rev_id='rev-1',
420
 
                  timestamp=1132586655, timezone=36000,
421
 
                  committer='Joe Foo <joe@foo.com>')
422
 
        wt.commit('rev-merged', rev_id='rev-2a',
423
 
                  timestamp=1132586700, timezone=36000,
424
 
                  committer='Joe Foo <joe@foo.com>')
425
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
426
 
        wt.branch.set_last_revision_info(1, 'rev-1')
427
 
        wt.commit('rev-2', rev_id='rev-2b',
428
 
                  timestamp=1132586800, timezone=36000,
429
 
                  committer='Joe Foo <joe@foo.com>')
430
 
        logfile = self.make_utf8_encoded_stringio()
431
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
432
 
        log.show_log(wt.branch, formatter)
 
377
        wt = self._prepare_tree_with_merges()
433
378
        # Note that the 1.1.1 indenting is in fact correct given that
434
379
        # the revision numbers are right justified within 5 characters
435
380
        # for mainline revnos and 9 characters for dotted revnos.
436
 
        self.assertEqualDiff("""\
 
381
        self.assertFormatterResult("""\
437
382
    2 Joe Foo\t2005-11-22 [merge]
438
383
      rev-2
439
384
 
444
389
      rev-1
445
390
 
446
391
""",
447
 
                             logfile.getvalue())
 
392
            wt.branch, log.ShortLogFormatter,
 
393
            formatter_kwargs=dict(levels=0))
448
394
 
449
395
    def test_short_merge_revs_log_single_merge_revision(self):
450
 
        wt = self.make_branch_and_memory_tree('.')
451
 
        wt.lock_write()
452
 
        self.addCleanup(wt.unlock)
453
 
        wt.add('')
454
 
        wt.commit('rev-1', rev_id='rev-1',
455
 
                  timestamp=1132586655, timezone=36000,
456
 
                  committer='Joe Foo <joe@foo.com>')
457
 
        wt.commit('rev-merged', rev_id='rev-2a',
458
 
                  timestamp=1132586700, timezone=36000,
459
 
                  committer='Joe Foo <joe@foo.com>')
460
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
461
 
        wt.branch.set_last_revision_info(1, 'rev-1')
462
 
        wt.commit('rev-2', rev_id='rev-2b',
463
 
                  timestamp=1132586800, timezone=36000,
464
 
                  committer='Joe Foo <joe@foo.com>')
465
 
        logfile = self.make_utf8_encoded_stringio()
466
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
396
        wt = self._prepare_tree_with_merges()
467
397
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
468
 
        wtb = wt.branch
469
 
        rev = revspec.in_history(wtb)
470
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
471
 
        self.assertEqualDiff("""\
 
398
        rev = revspec.in_history(wt.branch)
 
399
        self.assertFormatterResult("""\
472
400
      1.1.1 Joe Foo\t2005-11-22
473
401
            rev-merged
474
402
 
475
403
""",
476
 
                             logfile.getvalue())
477
 
 
478
 
 
479
 
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
 
404
            wt.branch, log.ShortLogFormatter,
 
405
            formatter_kwargs=dict(levels=0),
 
406
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
407
 
 
408
 
 
409
class TestLongLogFormatter(TestCaseForLogFormatter):
480
410
 
481
411
    def test_verbose_log(self):
482
412
        """Verbose log includes changed files
483
413
 
484
414
        bug #4676
485
415
        """
486
 
        wt = self.make_branch_and_tree('.')
487
 
        b = wt.branch
488
 
        self.build_tree(['a'])
489
 
        wt.add('a')
490
 
        # XXX: why does a longer nick show up?
491
 
        b.nick = 'test_verbose_log'
492
 
        wt.commit(message='add a',
493
 
                  timestamp=1132711707,
494
 
                  timezone=36000,
495
 
                  committer='Lorem Ipsum <test@example.com>')
496
 
        logfile = file('out.tmp', 'w+')
497
 
        formatter = log.LongLogFormatter(to_file=logfile)
498
 
        log.show_log(b, formatter, verbose=True)
499
 
        logfile.flush()
500
 
        logfile.seek(0)
501
 
        log_contents = logfile.read()
502
 
        self.assertEqualDiff('''\
 
416
        wt = self.make_standard_commit('test_verbose_log', authors=[])
 
417
        self.assertFormatterResult('''\
503
418
------------------------------------------------------------
504
419
revno: 1
505
420
committer: Lorem Ipsum <test@example.com>
506
421
branch nick: test_verbose_log
507
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
422
timestamp: Tue 2005-11-22 00:00:00 +0000
508
423
message:
509
424
  add a
510
425
added:
511
426
  a
512
427
''',
513
 
                             log_contents)
 
428
            wt.branch, log.LongLogFormatter,
 
429
            show_log_kwargs=dict(verbose=True))
514
430
 
515
431
    def test_merges_are_indented_by_level(self):
516
432
        wt = self.make_branch_and_tree('parent')
517
 
        wt.commit('first post')
518
 
        self.run_bzr('branch parent child')
519
 
        self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
520
 
        self.run_bzr('branch child smallerchild')
521
 
        self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
522
 
            'smallerchild'])
523
 
        os.chdir('child')
524
 
        self.run_bzr('merge ../smallerchild')
525
 
        self.run_bzr(['commit', '-m', 'merge branch 2'])
526
 
        os.chdir('../parent')
527
 
        self.run_bzr('merge ../child')
528
 
        wt.commit('merge branch 1')
529
 
        b = wt.branch
530
 
        sio = self.make_utf8_encoded_stringio()
531
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
532
 
        log.show_log(b, lf, verbose=True)
533
 
        the_log = normalize_log(sio.getvalue())
534
 
        self.assertEqualDiff("""\
 
433
        self.wt_commit(wt, 'first post')
 
434
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
435
        self.wt_commit(child_wt, 'branch 1')
 
436
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
 
437
        self.wt_commit(smallerchild_wt, 'branch 2')
 
438
        child_wt.merge_from_branch(smallerchild_wt.branch)
 
439
        self.wt_commit(child_wt, 'merge branch 2')
 
440
        wt.merge_from_branch(child_wt.branch)
 
441
        self.wt_commit(wt, 'merge branch 1')
 
442
        self.assertFormatterResult("""\
535
443
------------------------------------------------------------
536
444
revno: 2 [merge]
537
 
committer: Lorem Ipsum <test@example.com>
 
445
committer: Joe Foo <joe@foo.com>
538
446
branch nick: parent
539
 
timestamp: Just now
 
447
timestamp: Tue 2005-11-22 00:00:04 +0000
540
448
message:
541
449
  merge branch 1
542
450
    ------------------------------------------------------------
543
451
    revno: 1.1.2 [merge]
544
 
    committer: Lorem Ipsum <test@example.com>
 
452
    committer: Joe Foo <joe@foo.com>
545
453
    branch nick: child
546
 
    timestamp: Just now
 
454
    timestamp: Tue 2005-11-22 00:00:03 +0000
547
455
    message:
548
456
      merge branch 2
549
457
        ------------------------------------------------------------
550
458
        revno: 1.2.1
551
 
        committer: Lorem Ipsum <test@example.com>
 
459
        committer: Joe Foo <joe@foo.com>
552
460
        branch nick: smallerchild
553
 
        timestamp: Just now
 
461
        timestamp: Tue 2005-11-22 00:00:02 +0000
554
462
        message:
555
463
          branch 2
556
464
    ------------------------------------------------------------
557
465
    revno: 1.1.1
558
 
    committer: Lorem Ipsum <test@example.com>
 
466
    committer: Joe Foo <joe@foo.com>
559
467
    branch nick: child
560
 
    timestamp: Just now
 
468
    timestamp: Tue 2005-11-22 00:00:01 +0000
561
469
    message:
562
470
      branch 1
563
471
------------------------------------------------------------
564
472
revno: 1
565
 
committer: Lorem Ipsum <test@example.com>
 
473
committer: Joe Foo <joe@foo.com>
566
474
branch nick: parent
567
 
timestamp: Just now
 
475
timestamp: Tue 2005-11-22 00:00:00 +0000
568
476
message:
569
477
  first post
570
478
""",
571
 
                             the_log)
 
479
            wt.branch, log.LongLogFormatter,
 
480
            formatter_kwargs=dict(levels=0),
 
481
            show_log_kwargs=dict(verbose=True))
572
482
 
573
483
    def test_verbose_merge_revisions_contain_deltas(self):
574
484
        wt = self.make_branch_and_tree('parent')
575
485
        self.build_tree(['parent/f1', 'parent/f2'])
576
486
        wt.add(['f1','f2'])
577
 
        wt.commit('first post')
578
 
        self.run_bzr('branch parent child')
 
487
        self.wt_commit(wt, 'first post')
 
488
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
579
489
        os.unlink('child/f1')
580
 
        file('child/f2', 'wb').write('hello\n')
581
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
582
 
            'child'])
583
 
        os.chdir('parent')
584
 
        self.run_bzr('merge ../child')
585
 
        wt.commit('merge branch 1')
586
 
        b = wt.branch
587
 
        sio = self.make_utf8_encoded_stringio()
588
 
        lf = log.LongLogFormatter(to_file=sio, levels=0)
589
 
        log.show_log(b, lf, verbose=True)
590
 
        the_log = normalize_log(sio.getvalue())
591
 
        self.assertEqualDiff("""\
 
490
        self.build_tree_contents([('child/f2', 'hello\n')])
 
491
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
492
        wt.merge_from_branch(child_wt.branch)
 
493
        self.wt_commit(wt, 'merge branch 1')
 
494
        self.assertFormatterResult("""\
592
495
------------------------------------------------------------
593
496
revno: 2 [merge]
594
 
committer: Lorem Ipsum <test@example.com>
 
497
committer: Joe Foo <joe@foo.com>
595
498
branch nick: parent
596
 
timestamp: Just now
 
499
timestamp: Tue 2005-11-22 00:00:02 +0000
597
500
message:
598
501
  merge branch 1
599
502
removed:
602
505
  f2
603
506
    ------------------------------------------------------------
604
507
    revno: 1.1.1
605
 
    committer: Lorem Ipsum <test@example.com>
 
508
    committer: Joe Foo <joe@foo.com>
606
509
    branch nick: child
607
 
    timestamp: Just now
 
510
    timestamp: Tue 2005-11-22 00:00:01 +0000
608
511
    message:
609
512
      removed f1 and modified f2
610
513
    removed:
613
516
      f2
614
517
------------------------------------------------------------
615
518
revno: 1
616
 
committer: Lorem Ipsum <test@example.com>
 
519
committer: Joe Foo <joe@foo.com>
617
520
branch nick: parent
618
 
timestamp: Just now
 
521
timestamp: Tue 2005-11-22 00:00:00 +0000
619
522
message:
620
523
  first post
621
524
added:
622
525
  f1
623
526
  f2
624
527
""",
625
 
                             the_log)
 
528
            wt.branch, log.LongLogFormatter,
 
529
            formatter_kwargs=dict(levels=0),
 
530
            show_log_kwargs=dict(verbose=True))
626
531
 
627
532
    def test_trailing_newlines(self):
628
533
        wt = self.make_branch_and_tree('.')
629
 
        b = make_commits_with_trailing_newlines(wt)
630
 
        sio = self.make_utf8_encoded_stringio()
631
 
        lf = log.LongLogFormatter(to_file=sio)
632
 
        log.show_log(b, lf)
633
 
        self.assertEqualDiff("""\
 
534
        b = self.make_commits_with_trailing_newlines(wt)
 
535
        self.assertFormatterResult("""\
634
536
------------------------------------------------------------
635
537
revno: 3
636
538
committer: Joe Foo <joe@foo.com>
637
539
branch nick: test
638
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
540
timestamp: Tue 2005-11-22 00:00:02 +0000
639
541
message:
640
542
  single line with trailing newline
641
543
------------------------------------------------------------
642
544
revno: 2
643
 
author: Joe Bar <joe@bar.com>
644
545
committer: Joe Foo <joe@foo.com>
645
546
branch nick: test
646
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
547
timestamp: Tue 2005-11-22 00:00:01 +0000
647
548
message:
648
549
  multiline
649
550
  log
652
553
revno: 1
653
554
committer: Joe Foo <joe@foo.com>
654
555
branch nick: test
655
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
556
timestamp: Tue 2005-11-22 00:00:00 +0000
656
557
message:
657
558
  simple log message
658
559
""",
659
 
                             sio.getvalue())
 
560
        b, log.LongLogFormatter)
660
561
 
661
562
    def test_author_in_log(self):
662
563
        """Log includes the author name if it's set in
663
564
        the revision properties
664
565
        """
665
 
        wt = self.make_branch_and_tree('.')
666
 
        b = wt.branch
667
 
        self.build_tree(['a'])
668
 
        wt.add('a')
669
 
        b.nick = 'test_author_log'
670
 
        wt.commit(message='add a',
671
 
                  timestamp=1132711707,
672
 
                  timezone=36000,
673
 
                  committer='Lorem Ipsum <test@example.com>',
674
 
                  authors=['John Doe <jdoe@example.com>',
675
 
                           'Jane Rey <jrey@example.com>'])
676
 
        sio = StringIO()
677
 
        formatter = log.LongLogFormatter(to_file=sio)
678
 
        log.show_log(b, formatter)
679
 
        self.assertEqualDiff('''\
 
566
        wt = self.make_standard_commit('test_author_log',
 
567
            authors=['John Doe <jdoe@example.com>',
 
568
                     'Jane Rey <jrey@example.com>'])
 
569
        self.assertFormatterResult("""\
680
570
------------------------------------------------------------
681
571
revno: 1
682
572
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
683
573
committer: Lorem Ipsum <test@example.com>
684
574
branch nick: test_author_log
685
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
575
timestamp: Tue 2005-11-22 00:00:00 +0000
686
576
message:
687
577
  add a
688
 
''',
689
 
                             sio.getvalue())
 
578
""",
 
579
        wt.branch, log.LongLogFormatter)
690
580
 
691
581
    def test_properties_in_log(self):
692
582
        """Log includes the custom properties returned by the registered
693
583
        handlers.
694
584
        """
695
 
        wt = self.make_branch_and_tree('.')
696
 
        b = wt.branch
697
 
        self.build_tree(['a'])
698
 
        wt.add('a')
699
 
        b.nick = 'test_properties_in_log'
700
 
        wt.commit(message='add a',
701
 
                  timestamp=1132711707,
702
 
                  timezone=36000,
703
 
                  committer='Lorem Ipsum <test@example.com>',
704
 
                  authors=['John Doe <jdoe@example.com>'])
705
 
        sio = StringIO()
706
 
        formatter = log.LongLogFormatter(to_file=sio)
707
 
        try:
708
 
            def trivial_custom_prop_handler(revision):
709
 
                return {'test_prop':'test_value'}
 
585
        wt = self.make_standard_commit('test_properties_in_log')
 
586
        def trivial_custom_prop_handler(revision):
 
587
            return {'test_prop':'test_value'}
710
588
 
711
 
            log.properties_handler_registry.register(
712
 
                'trivial_custom_prop_handler',
713
 
                trivial_custom_prop_handler)
714
 
            log.show_log(b, formatter)
715
 
        finally:
716
 
            log.properties_handler_registry.remove(
717
 
                'trivial_custom_prop_handler')
718
 
            self.assertEqualDiff('''\
 
589
        # Cleaned up in setUp()
 
590
        log.properties_handler_registry.register(
 
591
            'trivial_custom_prop_handler',
 
592
            trivial_custom_prop_handler)
 
593
        self.assertFormatterResult("""\
719
594
------------------------------------------------------------
720
595
revno: 1
721
596
test_prop: test_value
722
597
author: John Doe <jdoe@example.com>
723
598
committer: Lorem Ipsum <test@example.com>
724
599
branch nick: test_properties_in_log
725
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
600
timestamp: Tue 2005-11-22 00:00:00 +0000
726
601
message:
727
602
  add a
728
 
''',
729
 
                                 sio.getvalue())
 
603
""",
 
604
            wt.branch, log.LongLogFormatter)
730
605
 
731
606
    def test_properties_in_short_log(self):
732
607
        """Log includes the custom properties returned by the registered
733
608
        handlers.
734
609
        """
735
 
        wt = self.make_branch_and_tree('.')
736
 
        b = wt.branch
737
 
        self.build_tree(['a'])
738
 
        wt.add('a')
739
 
        b.nick = 'test_properties_in_short_log'
740
 
        wt.commit(message='add a',
741
 
                  timestamp=1132711707,
742
 
                  timezone=36000,
743
 
                  committer='Lorem Ipsum <test@example.com>',
744
 
                  authors=['John Doe <jdoe@example.com>'])
745
 
        sio = StringIO()
746
 
        formatter = log.ShortLogFormatter(to_file=sio)
747
 
        try:
748
 
            def trivial_custom_prop_handler(revision):
749
 
                return {'test_prop':'test_value'}
 
610
        wt = self.make_standard_commit('test_properties_in_short_log')
 
611
        def trivial_custom_prop_handler(revision):
 
612
            return {'test_prop':'test_value'}
750
613
 
751
 
            log.properties_handler_registry.register(
752
 
                'trivial_custom_prop_handler',
753
 
                trivial_custom_prop_handler)
754
 
            log.show_log(b, formatter)
755
 
        finally:
756
 
            log.properties_handler_registry.remove(
757
 
                'trivial_custom_prop_handler')
758
 
            self.assertEqualDiff('''\
759
 
    1 John Doe\t2005-11-23
 
614
        log.properties_handler_registry.register(
 
615
            'trivial_custom_prop_handler',
 
616
            trivial_custom_prop_handler)
 
617
        self.assertFormatterResult("""\
 
618
    1 John Doe\t2005-11-22
760
619
      test_prop: test_value
761
620
      add a
762
621
 
763
 
''',
764
 
                                 sio.getvalue())
 
622
""",
 
623
            wt.branch, log.ShortLogFormatter)
765
624
 
766
625
    def test_error_in_properties_handler(self):
767
626
        """Log includes the custom properties returned by the registered
768
627
        handlers.
769
628
        """
770
 
        wt = self.make_branch_and_tree('.')
771
 
        b = wt.branch
772
 
        self.build_tree(['a'])
773
 
        wt.add('a')
774
 
        b.nick = 'test_author_log'
775
 
        wt.commit(message='add a',
776
 
                  timestamp=1132711707,
777
 
                  timezone=36000,
778
 
                  committer='Lorem Ipsum <test@example.com>',
779
 
                  authors=['John Doe <jdoe@example.com>'],
780
 
                  revprops={'first_prop':'first_value'})
781
 
        sio = StringIO()
 
629
        wt = self.make_standard_commit('error_in_properties_handler',
 
630
            revprops={'first_prop':'first_value'})
 
631
        sio = self.make_utf8_encoded_stringio()
782
632
        formatter = log.LongLogFormatter(to_file=sio)
783
 
        try:
784
 
            def trivial_custom_prop_handler(revision):
785
 
                raise StandardError("a test error")
 
633
        def trivial_custom_prop_handler(revision):
 
634
            raise StandardError("a test error")
786
635
 
787
 
            log.properties_handler_registry.register(
788
 
                'trivial_custom_prop_handler',
789
 
                trivial_custom_prop_handler)
790
 
            self.assertRaises(StandardError, log.show_log, b, formatter,)
791
 
        finally:
792
 
            log.properties_handler_registry.remove(
793
 
                'trivial_custom_prop_handler')
 
636
        log.properties_handler_registry.register(
 
637
            'trivial_custom_prop_handler',
 
638
            trivial_custom_prop_handler)
 
639
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
794
640
 
795
641
    def test_properties_handler_bad_argument(self):
796
 
        wt = self.make_branch_and_tree('.')
797
 
        b = wt.branch
798
 
        self.build_tree(['a'])
799
 
        wt.add('a')
800
 
        b.nick = 'test_author_log'
801
 
        wt.commit(message='add a',
802
 
                  timestamp=1132711707,
803
 
                  timezone=36000,
804
 
                  committer='Lorem Ipsum <test@example.com>',
805
 
                  authors=['John Doe <jdoe@example.com>'],
806
 
                  revprops={'a_prop':'test_value'})
807
 
        sio = StringIO()
 
642
        wt = self.make_standard_commit('bad_argument',
 
643
              revprops={'a_prop':'test_value'})
 
644
        sio = self.make_utf8_encoded_stringio()
808
645
        formatter = log.LongLogFormatter(to_file=sio)
809
 
        try:
810
 
            def bad_argument_prop_handler(revision):
811
 
                return {'custom_prop_name':revision.properties['a_prop']}
812
 
 
813
 
            log.properties_handler_registry.register(
814
 
                'bad_argument_prop_handler',
815
 
                bad_argument_prop_handler)
816
 
 
817
 
            self.assertRaises(AttributeError, formatter.show_properties,
818
 
                              'a revision', '')
819
 
 
820
 
            revision = b.repository.get_revision(b.last_revision())
821
 
            formatter.show_properties(revision, '')
822
 
            self.assertEqualDiff('''custom_prop_name: test_value\n''',
823
 
                                 sio.getvalue())
824
 
        finally:
825
 
            log.properties_handler_registry.remove(
826
 
                'bad_argument_prop_handler')
827
 
 
828
 
 
829
 
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
 
646
        def bad_argument_prop_handler(revision):
 
647
            return {'custom_prop_name':revision.properties['a_prop']}
 
648
 
 
649
        log.properties_handler_registry.register(
 
650
            'bad_argument_prop_handler',
 
651
            bad_argument_prop_handler)
 
652
 
 
653
        self.assertRaises(AttributeError, formatter.show_properties,
 
654
                          'a revision', '')
 
655
 
 
656
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
 
657
        formatter.show_properties(revision, '')
 
658
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
 
659
                             sio.getvalue())
 
660
 
 
661
 
 
662
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
830
663
 
831
664
    def test_long_verbose_log(self):
832
665
        """Verbose log includes changed files
833
666
 
834
667
        bug #4676
835
668
        """
836
 
        wt = self.make_branch_and_tree('.')
837
 
        b = wt.branch
838
 
        self.build_tree(['a'])
839
 
        wt.add('a')
840
 
        # XXX: why does a longer nick show up?
841
 
        b.nick = 'test_verbose_log'
842
 
        wt.commit(message='add a',
843
 
                  timestamp=1132711707,
844
 
                  timezone=36000,
845
 
                  committer='Lorem Ipsum <test@example.com>')
846
 
        logfile = file('out.tmp', 'w+')
847
 
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
848
 
        log.show_log(b, formatter, verbose=True)
849
 
        logfile.flush()
850
 
        logfile.seek(0)
851
 
        log_contents = logfile.read()
852
 
        self.assertEqualDiff('''\
 
669
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
 
670
        self.assertFormatterResult("""\
853
671
------------------------------------------------------------
854
672
revno: 1
855
673
committer: Lorem Ipsum <test@example.com>
856
 
branch nick: test_verbose_log
857
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
674
branch nick: test_long_verbose_log
 
675
timestamp: Tue 2005-11-22 00:00:00 +0000
858
676
message:
859
677
  add a
860
678
added:
861
679
  a
862
 
''',
863
 
                             log_contents)
 
680
""",
 
681
            wt.branch, log.LongLogFormatter,
 
682
            formatter_kwargs=dict(levels=1),
 
683
            show_log_kwargs=dict(verbose=True))
864
684
 
865
685
    def test_long_verbose_contain_deltas(self):
866
686
        wt = self.make_branch_and_tree('parent')
867
687
        self.build_tree(['parent/f1', 'parent/f2'])
868
688
        wt.add(['f1','f2'])
869
 
        wt.commit('first post')
870
 
        self.run_bzr('branch parent child')
 
689
        self.wt_commit(wt, 'first post')
 
690
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
871
691
        os.unlink('child/f1')
872
 
        file('child/f2', 'wb').write('hello\n')
873
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
874
 
            'child'])
875
 
        os.chdir('parent')
876
 
        self.run_bzr('merge ../child')
877
 
        wt.commit('merge branch 1')
878
 
        b = wt.branch
879
 
        sio = self.make_utf8_encoded_stringio()
880
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
881
 
        log.show_log(b, lf, verbose=True)
882
 
        the_log = normalize_log(sio.getvalue())
883
 
        self.assertEqualDiff("""\
 
692
        self.build_tree_contents([('child/f2', 'hello\n')])
 
693
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
694
        wt.merge_from_branch(child_wt.branch)
 
695
        self.wt_commit(wt, 'merge branch 1')
 
696
        self.assertFormatterResult("""\
884
697
------------------------------------------------------------
885
698
revno: 2 [merge]
886
 
committer: Lorem Ipsum <test@example.com>
 
699
committer: Joe Foo <joe@foo.com>
887
700
branch nick: parent
888
 
timestamp: Just now
 
701
timestamp: Tue 2005-11-22 00:00:02 +0000
889
702
message:
890
703
  merge branch 1
891
704
removed:
894
707
  f2
895
708
------------------------------------------------------------
896
709
revno: 1
897
 
committer: Lorem Ipsum <test@example.com>
 
710
committer: Joe Foo <joe@foo.com>
898
711
branch nick: parent
899
 
timestamp: Just now
 
712
timestamp: Tue 2005-11-22 00:00:00 +0000
900
713
message:
901
714
  first post
902
715
added:
903
716
  f1
904
717
  f2
905
718
""",
906
 
                             the_log)
 
719
            wt.branch, log.LongLogFormatter,
 
720
            formatter_kwargs=dict(levels=1),
 
721
            show_log_kwargs=dict(verbose=True))
907
722
 
908
723
    def test_long_trailing_newlines(self):
909
724
        wt = self.make_branch_and_tree('.')
910
 
        b = make_commits_with_trailing_newlines(wt)
911
 
        sio = self.make_utf8_encoded_stringio()
912
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
913
 
        log.show_log(b, lf)
914
 
        self.assertEqualDiff("""\
 
725
        b = self.make_commits_with_trailing_newlines(wt)
 
726
        self.assertFormatterResult("""\
915
727
------------------------------------------------------------
916
728
revno: 3
917
729
committer: Joe Foo <joe@foo.com>
918
730
branch nick: test
919
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
731
timestamp: Tue 2005-11-22 00:00:02 +0000
920
732
message:
921
733
  single line with trailing newline
922
734
------------------------------------------------------------
923
735
revno: 2
924
 
author: Joe Bar <joe@bar.com>
925
736
committer: Joe Foo <joe@foo.com>
926
737
branch nick: test
927
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
738
timestamp: Tue 2005-11-22 00:00:01 +0000
928
739
message:
929
740
  multiline
930
741
  log
933
744
revno: 1
934
745
committer: Joe Foo <joe@foo.com>
935
746
branch nick: test
936
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
747
timestamp: Tue 2005-11-22 00:00:00 +0000
937
748
message:
938
749
  simple log message
939
750
""",
940
 
                             sio.getvalue())
 
751
        b, log.LongLogFormatter,
 
752
        formatter_kwargs=dict(levels=1))
941
753
 
942
754
    def test_long_author_in_log(self):
943
755
        """Log includes the author name if it's set in
944
756
        the revision properties
945
757
        """
946
 
        wt = self.make_branch_and_tree('.')
947
 
        b = wt.branch
948
 
        self.build_tree(['a'])
949
 
        wt.add('a')
950
 
        b.nick = 'test_author_log'
951
 
        wt.commit(message='add a',
952
 
                  timestamp=1132711707,
953
 
                  timezone=36000,
954
 
                  committer='Lorem Ipsum <test@example.com>',
955
 
                  authors=['John Doe <jdoe@example.com>'])
956
 
        sio = StringIO()
957
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
958
 
        log.show_log(b, formatter)
959
 
        self.assertEqualDiff('''\
 
758
        wt = self.make_standard_commit('test_author_log')
 
759
        self.assertFormatterResult("""\
960
760
------------------------------------------------------------
961
761
revno: 1
962
762
author: John Doe <jdoe@example.com>
963
763
committer: Lorem Ipsum <test@example.com>
964
764
branch nick: test_author_log
965
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
765
timestamp: Tue 2005-11-22 00:00:00 +0000
966
766
message:
967
767
  add a
968
 
''',
969
 
                             sio.getvalue())
 
768
""",
 
769
            wt.branch, log.LongLogFormatter,
 
770
            formatter_kwargs=dict(levels=1))
970
771
 
971
772
    def test_long_properties_in_log(self):
972
773
        """Log includes the custom properties returned by the registered
973
774
        handlers.
974
775
        """
975
 
        wt = self.make_branch_and_tree('.')
976
 
        b = wt.branch
977
 
        self.build_tree(['a'])
978
 
        wt.add('a')
979
 
        b.nick = 'test_properties_in_log'
980
 
        wt.commit(message='add a',
981
 
                  timestamp=1132711707,
982
 
                  timezone=36000,
983
 
                  committer='Lorem Ipsum <test@example.com>',
984
 
                  authors=['John Doe <jdoe@example.com>'])
985
 
        sio = StringIO()
986
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
987
 
        try:
988
 
            def trivial_custom_prop_handler(revision):
989
 
                return {'test_prop':'test_value'}
 
776
        wt = self.make_standard_commit('test_properties_in_log')
 
777
        def trivial_custom_prop_handler(revision):
 
778
            return {'test_prop':'test_value'}
990
779
 
991
 
            log.properties_handler_registry.register(
992
 
                'trivial_custom_prop_handler',
993
 
                trivial_custom_prop_handler)
994
 
            log.show_log(b, formatter)
995
 
        finally:
996
 
            log.properties_handler_registry.remove(
997
 
                'trivial_custom_prop_handler')
998
 
            self.assertEqualDiff('''\
 
780
        log.properties_handler_registry.register(
 
781
            'trivial_custom_prop_handler',
 
782
            trivial_custom_prop_handler)
 
783
        self.assertFormatterResult("""\
999
784
------------------------------------------------------------
1000
785
revno: 1
1001
786
test_prop: test_value
1002
787
author: John Doe <jdoe@example.com>
1003
788
committer: Lorem Ipsum <test@example.com>
1004
789
branch nick: test_properties_in_log
1005
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
790
timestamp: Tue 2005-11-22 00:00:00 +0000
1006
791
message:
1007
792
  add a
1008
 
''',
1009
 
                                 sio.getvalue())
1010
 
 
1011
 
 
1012
 
class TestLineLogFormatter(tests.TestCaseWithTransport):
 
793
""",
 
794
            wt.branch, log.LongLogFormatter,
 
795
            formatter_kwargs=dict(levels=1))
 
796
 
 
797
 
 
798
class TestLineLogFormatter(TestCaseForLogFormatter):
1013
799
 
1014
800
    def test_line_log(self):
1015
801
        """Line log should show revno
1016
802
 
1017
803
        bug #5162
1018
804
        """
1019
 
        wt = self.make_branch_and_tree('.')
1020
 
        b = wt.branch
1021
 
        self.build_tree(['a'])
1022
 
        wt.add('a')
1023
 
        b.nick = 'test-line-log'
1024
 
        wt.commit(message='add a',
1025
 
                  timestamp=1132711707,
1026
 
                  timezone=36000,
1027
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1028
 
        logfile = file('out.tmp', 'w+')
1029
 
        formatter = log.LineLogFormatter(to_file=logfile)
1030
 
        log.show_log(b, formatter)
1031
 
        logfile.flush()
1032
 
        logfile.seek(0)
1033
 
        log_contents = logfile.read()
1034
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1035
 
                             log_contents)
 
805
        wt = self.make_standard_commit('test-line-log',
 
806
                committer='Line-Log-Formatter Tester <test@line.log>',
 
807
                authors=[])
 
808
        self.assertFormatterResult("""\
 
809
1: Line-Log-Formatte... 2005-11-22 add a
 
810
""",
 
811
            wt.branch, log.LineLogFormatter)
1036
812
 
1037
813
    def test_trailing_newlines(self):
1038
814
        wt = self.make_branch_and_tree('.')
1039
 
        b = make_commits_with_trailing_newlines(wt)
1040
 
        sio = self.make_utf8_encoded_stringio()
1041
 
        lf = log.LineLogFormatter(to_file=sio)
1042
 
        log.show_log(b, lf)
1043
 
        self.assertEqualDiff("""\
1044
 
3: Joe Foo 2005-11-21 single line with trailing newline
1045
 
2: Joe Bar 2005-11-21 multiline
1046
 
1: Joe Foo 2005-11-21 simple log message
 
815
        b = self.make_commits_with_trailing_newlines(wt)
 
816
        self.assertFormatterResult("""\
 
817
3: Joe Foo 2005-11-22 single line with trailing newline
 
818
2: Joe Foo 2005-11-22 multiline
 
819
1: Joe Foo 2005-11-22 simple log message
1047
820
""",
1048
 
                             sio.getvalue())
1049
 
 
1050
 
    def _prepare_tree_with_merges(self, with_tags=False):
1051
 
        wt = self.make_branch_and_memory_tree('.')
1052
 
        wt.lock_write()
1053
 
        self.addCleanup(wt.unlock)
1054
 
        wt.add('')
1055
 
        wt.commit('rev-1', rev_id='rev-1',
1056
 
                  timestamp=1132586655, timezone=36000,
1057
 
                  committer='Joe Foo <joe@foo.com>')
1058
 
        wt.commit('rev-merged', rev_id='rev-2a',
1059
 
                  timestamp=1132586700, timezone=36000,
1060
 
                  committer='Joe Foo <joe@foo.com>')
1061
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1062
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1063
 
        wt.commit('rev-2', rev_id='rev-2b',
1064
 
                  timestamp=1132586800, timezone=36000,
1065
 
                  committer='Joe Foo <joe@foo.com>')
1066
 
        if with_tags:
1067
 
            branch = wt.branch
1068
 
            branch.tags.set_tag('v0.2', 'rev-2b')
1069
 
            wt.commit('rev-3', rev_id='rev-3',
1070
 
                      timestamp=1132586900, timezone=36000,
1071
 
                      committer='Jane Foo <jane@foo.com>')
1072
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
1073
 
            branch.tags.set_tag('v1.0', 'rev-3')
1074
 
        return wt
 
821
            b, log.LineLogFormatter)
1075
822
 
1076
823
    def test_line_log_single_merge_revision(self):
1077
824
        wt = self._prepare_tree_with_merges()
1078
 
        logfile = self.make_utf8_encoded_stringio()
1079
 
        formatter = log.LineLogFormatter(to_file=logfile)
1080
825
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1081
 
        wtb = wt.branch
1082
 
        rev = revspec.in_history(wtb)
1083
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1084
 
        self.assertEqualDiff("""\
 
826
        rev = revspec.in_history(wt.branch)
 
827
        self.assertFormatterResult("""\
1085
828
1.1.1: Joe Foo 2005-11-22 rev-merged
1086
829
""",
1087
 
                             logfile.getvalue())
 
830
            wt.branch, log.LineLogFormatter,
 
831
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1088
832
 
1089
833
    def test_line_log_with_tags(self):
1090
834
        wt = self._prepare_tree_with_merges(with_tags=True)
1091
 
        logfile = self.make_utf8_encoded_stringio()
1092
 
        formatter = log.LineLogFormatter(to_file=logfile)
1093
 
        log.show_log(wt.branch, formatter)
1094
 
        self.assertEqualDiff("""\
1095
 
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
 
835
        self.assertFormatterResult("""\
 
836
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1096
837
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
1097
838
1: Joe Foo 2005-11-22 rev-1
1098
839
""",
1099
 
                             logfile.getvalue())
1100
 
 
1101
 
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
840
            wt.branch, log.LineLogFormatter)
 
841
 
 
842
 
 
843
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
1102
844
 
1103
845
    def test_line_merge_revs_log(self):
1104
846
        """Line log should show revno
1105
847
 
1106
848
        bug #5162
1107
849
        """
1108
 
        wt = self.make_branch_and_tree('.')
1109
 
        b = wt.branch
1110
 
        self.build_tree(['a'])
1111
 
        wt.add('a')
1112
 
        b.nick = 'test-line-log'
1113
 
        wt.commit(message='add a',
1114
 
                  timestamp=1132711707,
1115
 
                  timezone=36000,
1116
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1117
 
        logfile = file('out.tmp', 'w+')
1118
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1119
 
        log.show_log(b, formatter)
1120
 
        logfile.flush()
1121
 
        logfile.seek(0)
1122
 
        log_contents = logfile.read()
1123
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1124
 
                             log_contents)
 
850
        wt = self.make_standard_commit('test-line-log',
 
851
                committer='Line-Log-Formatter Tester <test@line.log>',
 
852
                authors=[])
 
853
        self.assertFormatterResult("""\
 
854
1: Line-Log-Formatte... 2005-11-22 add a
 
855
""",
 
856
            wt.branch, log.LineLogFormatter)
1125
857
 
1126
858
    def test_line_merge_revs_log_single_merge_revision(self):
1127
 
        wt = self.make_branch_and_memory_tree('.')
1128
 
        wt.lock_write()
1129
 
        self.addCleanup(wt.unlock)
1130
 
        wt.add('')
1131
 
        wt.commit('rev-1', rev_id='rev-1',
1132
 
                  timestamp=1132586655, timezone=36000,
1133
 
                  committer='Joe Foo <joe@foo.com>')
1134
 
        wt.commit('rev-merged', rev_id='rev-2a',
1135
 
                  timestamp=1132586700, timezone=36000,
1136
 
                  committer='Joe Foo <joe@foo.com>')
1137
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1138
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1139
 
        wt.commit('rev-2', rev_id='rev-2b',
1140
 
                  timestamp=1132586800, timezone=36000,
1141
 
                  committer='Joe Foo <joe@foo.com>')
1142
 
        logfile = self.make_utf8_encoded_stringio()
1143
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
859
        wt = self._prepare_tree_with_merges()
1144
860
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1145
 
        wtb = wt.branch
1146
 
        rev = revspec.in_history(wtb)
1147
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1148
 
        self.assertEqualDiff("""\
 
861
        rev = revspec.in_history(wt.branch)
 
862
        self.assertFormatterResult("""\
1149
863
1.1.1: Joe Foo 2005-11-22 rev-merged
1150
864
""",
1151
 
                             logfile.getvalue())
 
865
            wt.branch, log.LineLogFormatter,
 
866
            formatter_kwargs=dict(levels=0),
 
867
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1152
868
 
1153
869
    def test_line_merge_revs_log_with_merges(self):
1154
 
        wt = self.make_branch_and_memory_tree('.')
1155
 
        wt.lock_write()
1156
 
        self.addCleanup(wt.unlock)
1157
 
        wt.add('')
1158
 
        wt.commit('rev-1', rev_id='rev-1',
1159
 
                  timestamp=1132586655, timezone=36000,
1160
 
                  committer='Joe Foo <joe@foo.com>')
1161
 
        wt.commit('rev-merged', rev_id='rev-2a',
1162
 
                  timestamp=1132586700, timezone=36000,
1163
 
                  committer='Joe Foo <joe@foo.com>')
1164
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1165
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1166
 
        wt.commit('rev-2', rev_id='rev-2b',
1167
 
                  timestamp=1132586800, timezone=36000,
1168
 
                  committer='Joe Foo <joe@foo.com>')
1169
 
        logfile = self.make_utf8_encoded_stringio()
1170
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1171
 
        log.show_log(wt.branch, formatter)
1172
 
        self.assertEqualDiff("""\
 
870
        wt = self._prepare_tree_with_merges()
 
871
        self.assertFormatterResult("""\
1173
872
2: Joe Foo 2005-11-22 [merge] rev-2
1174
873
  1.1.1: Joe Foo 2005-11-22 rev-merged
1175
874
1: Joe Foo 2005-11-22 rev-1
1176
875
""",
1177
 
                             logfile.getvalue())
1178
 
 
1179
 
class TestGetViewRevisions(tests.TestCaseWithTransport):
 
876
            wt.branch, log.LineLogFormatter,
 
877
            formatter_kwargs=dict(levels=0))
 
878
 
 
879
 
 
880
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
 
881
 
 
882
    def _get_view_revisions(self, *args, **kwargs):
 
883
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
884
                                    log.get_view_revisions, *args, **kwargs)
1180
885
 
1181
886
    def make_tree_with_commits(self):
1182
887
        """Create a tree with well-known revision ids"""
1183
888
        wt = self.make_branch_and_tree('tree1')
1184
 
        wt.commit('commit one', rev_id='1')
1185
 
        wt.commit('commit two', rev_id='2')
1186
 
        wt.commit('commit three', rev_id='3')
 
889
        self.wt_commit(wt, 'commit one', rev_id='1')
 
890
        self.wt_commit(wt, 'commit two', rev_id='2')
 
891
        self.wt_commit(wt, 'commit three', rev_id='3')
1187
892
        mainline_revs = [None, '1', '2', '3']
1188
893
        rev_nos = {'1': 1, '2': 2, '3': 3}
1189
894
        return mainline_revs, rev_nos, wt
1192
897
        """Create a tree with well-known revision ids and a merge"""
1193
898
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1194
899
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1195
 
        tree2.commit('four-a', rev_id='4a')
 
900
        self.wt_commit(tree2, 'four-a', rev_id='4a')
1196
901
        wt.merge_from_branch(tree2.branch)
1197
 
        wt.commit('four-b', rev_id='4b')
 
902
        self.wt_commit(wt, 'four-b', rev_id='4b')
1198
903
        mainline_revs.append('4b')
1199
904
        rev_nos['4b'] = 4
1200
905
        # 4a: 3.1.1
1248
953
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1249
954
        wt.lock_read()
1250
955
        self.addCleanup(wt.unlock)
1251
 
        revisions = list(log.get_view_revisions(
 
956
        revisions = list(self._get_view_revisions(
1252
957
                mainline_revs, rev_nos, wt.branch, 'forward'))
1253
958
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1254
959
                         revisions)
1255
 
        revisions2 = list(log.get_view_revisions(
 
960
        revisions2 = list(self._get_view_revisions(
1256
961
                mainline_revs, rev_nos, wt.branch, 'forward',
1257
962
                include_merges=False))
1258
963
        self.assertEqual(revisions, revisions2)
1262
967
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1263
968
        wt.lock_read()
1264
969
        self.addCleanup(wt.unlock)
1265
 
        revisions = list(log.get_view_revisions(
 
970
        revisions = list(self._get_view_revisions(
1266
971
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1267
972
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1268
973
                         revisions)
1269
 
        revisions2 = list(log.get_view_revisions(
 
974
        revisions2 = list(self._get_view_revisions(
1270
975
                mainline_revs, rev_nos, wt.branch, 'reverse',
1271
976
                include_merges=False))
1272
977
        self.assertEqual(revisions, revisions2)
1276
981
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1277
982
        wt.lock_read()
1278
983
        self.addCleanup(wt.unlock)
1279
 
        revisions = list(log.get_view_revisions(
 
984
        revisions = list(self._get_view_revisions(
1280
985
                mainline_revs, rev_nos, wt.branch, 'forward'))
1281
986
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1282
987
                          ('4b', '4', 0), ('4a', '3.1.1', 1)],
1283
988
                         revisions)
1284
 
        revisions = list(log.get_view_revisions(
 
989
        revisions = list(self._get_view_revisions(
1285
990
                mainline_revs, rev_nos, wt.branch, 'forward',
1286
991
                include_merges=False))
1287
992
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1293
998
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1294
999
        wt.lock_read()
1295
1000
        self.addCleanup(wt.unlock)
1296
 
        revisions = list(log.get_view_revisions(
 
1001
        revisions = list(self._get_view_revisions(
1297
1002
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1298
1003
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1299
1004
                          ('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1300
1005
                         revisions)
1301
 
        revisions = list(log.get_view_revisions(
 
1006
        revisions = list(self._get_view_revisions(
1302
1007
                mainline_revs, rev_nos, wt.branch, 'reverse',
1303
1008
                include_merges=False))
1304
1009
        self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1310
1015
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1311
1016
        b.lock_read()
1312
1017
        self.addCleanup(b.unlock)
1313
 
        revisions = list(log.get_view_revisions(
 
1018
        revisions = list(self._get_view_revisions(
1314
1019
                mainline_revs, rev_nos, b, 'forward'))
1315
1020
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1316
1021
                    ('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1317
1022
                    ('4a', '2.2.2', 1)]
1318
1023
        self.assertEqual(expected, revisions)
1319
 
        revisions = list(log.get_view_revisions(
 
1024
        revisions = list(self._get_view_revisions(
1320
1025
                mainline_revs, rev_nos, b, 'forward',
1321
1026
                include_merges=False))
1322
1027
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1323
1028
                          ('4b', '4', 0)],
1324
1029
                         revisions)
1325
1030
 
1326
 
 
1327
1031
    def test_file_id_for_range(self):
1328
1032
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1329
1033
        b.lock_read()
1334
1038
            return revspec.in_history(branch)
1335
1039
 
1336
1040
        def view_revs(start_rev, end_rev, file_id, direction):
1337
 
            revs = log.calculate_view_revisions(
 
1041
            revs = self.applyDeprecated(
 
1042
                symbol_versioning.deprecated_in((2, 2, 0)),
 
1043
                log.calculate_view_revisions,
1338
1044
                b,
1339
1045
                start_rev, # start_revision
1340
1046
                end_rev, # end_revision
1346
1052
 
1347
1053
        rev_3a = rev_from_rev_id('3a', b)
1348
1054
        rev_4b = rev_from_rev_id('4b', b)
1349
 
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
 
1055
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1056
                          ('3a', '2.1.1', 2)],
1350
1057
                          view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1351
1058
        # Note: 3c still appears before 3a here because of depth-based sorting
1352
 
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
 
1059
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1060
                          ('3a', '2.1.1', 2)],
1353
1061
                          view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1354
1062
 
1355
1063
 
1356
1064
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1357
1065
 
 
1066
    def get_view_revisions(self, *args):
 
1067
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
1068
                                    log.get_view_revisions, *args)
 
1069
 
1358
1070
    def create_tree_with_single_merge(self):
1359
1071
        """Create a branch with a moderate layout.
1360
1072
 
1378
1090
        #       use it. Since 'log' only uses the tree in a readonly
1379
1091
        #       fashion, it seems a shame to regenerate an identical
1380
1092
        #       tree for each test.
 
1093
        # TODO: vila 20100122 One way to address the shame above will be to
 
1094
        #       create a memory tree during test parametrization and give a
 
1095
        #       *copy* of this tree to each test. Copying a memory tree ought
 
1096
        #       to be cheap, at least cheaper than creating them with such
 
1097
        #       complex setups.
1381
1098
        tree = self.make_branch_and_tree('tree')
1382
1099
        tree.lock_write()
1383
1100
        self.addCleanup(tree.unlock)
1458
1175
        mainline = tree.branch.revision_history()
1459
1176
        mainline.insert(0, None)
1460
1177
        revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1461
 
        view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1462
 
                                                'reverse', True)
 
1178
        view_revs_iter = self.get_view_revisions(
 
1179
            mainline, revnos, tree.branch, 'reverse', True)
1463
1180
        actual_revs = log._filter_revisions_touching_file_id(
1464
 
                            tree.branch,
1465
 
                            file_id,
1466
 
                            list(view_revs_iter))
 
1181
            tree.branch, file_id, list(view_revs_iter))
1467
1182
        self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1468
1183
 
1469
1184
    def test_file_id_f1(self):
1521
1236
 
1522
1237
class TestLogFormatter(tests.TestCase):
1523
1238
 
 
1239
    def setUp(self):
 
1240
        super(TestLogFormatter, self).setUp()
 
1241
        self.rev = revision.Revision('a-id')
 
1242
        self.lf = log.LogFormatter(None)
 
1243
 
1524
1244
    def test_short_committer(self):
1525
 
        rev = revision.Revision('a-id')
1526
 
        rev.committer = 'John Doe <jdoe@example.com>'
1527
 
        lf = log.LogFormatter(None)
1528
 
        self.assertEqual('John Doe', lf.short_committer(rev))
1529
 
        rev.committer = 'John Smith <jsmith@example.com>'
1530
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1531
 
        rev.committer = 'John Smith'
1532
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1533
 
        rev.committer = 'jsmith@example.com'
1534
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1535
 
        rev.committer = '<jsmith@example.com>'
1536
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1537
 
        rev.committer = 'John Smith jsmith@example.com'
1538
 
        self.assertEqual('John Smith', lf.short_committer(rev))
 
1245
        def assertCommitter(expected, committer):
 
1246
            self.rev.committer = committer
 
1247
            self.assertEqual(expected, self.lf.short_committer(self.rev))
 
1248
 
 
1249
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
 
1250
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
 
1251
        assertCommitter('John Smith', 'John Smith')
 
1252
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
 
1253
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
 
1254
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
1539
1255
 
1540
1256
    def test_short_author(self):
1541
 
        rev = revision.Revision('a-id')
1542
 
        rev.committer = 'John Doe <jdoe@example.com>'
1543
 
        lf = log.LogFormatter(None)
1544
 
        self.assertEqual('John Doe', lf.short_author(rev))
1545
 
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
1546
 
        self.assertEqual('John Smith', lf.short_author(rev))
1547
 
        rev.properties['author'] = 'John Smith'
1548
 
        self.assertEqual('John Smith', lf.short_author(rev))
1549
 
        rev.properties['author'] = 'jsmith@example.com'
1550
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1551
 
        rev.properties['author'] = '<jsmith@example.com>'
1552
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1553
 
        rev.properties['author'] = 'John Smith jsmith@example.com'
1554
 
        self.assertEqual('John Smith', lf.short_author(rev))
1555
 
        del rev.properties['author']
1556
 
        rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1557
 
                'Jane Rey <jrey@example.com>')
1558
 
        self.assertEqual('John Smith', lf.short_author(rev))
 
1257
        def assertAuthor(expected, author):
 
1258
            self.rev.properties['author'] = author
 
1259
            self.assertEqual(expected, self.lf.short_author(self.rev))
 
1260
 
 
1261
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
 
1262
        assertAuthor('John Smith', 'John Smith')
 
1263
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
 
1264
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
 
1265
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
 
1266
 
 
1267
    def test_short_author_from_committer(self):
 
1268
        self.rev.committer = 'John Doe <jdoe@example.com>'
 
1269
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
 
1270
 
 
1271
    def test_short_author_from_authors(self):
 
1272
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
 
1273
                                          'Jane Rey <jrey@example.com>')
 
1274
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
1559
1275
 
1560
1276
 
1561
1277
class TestReverseByDepth(tests.TestCase):
1707
1423
        log.show_branch_change(tree.branch, s, 3, '3b')
1708
1424
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1709
1425
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
 
1426
 
 
1427
 
 
1428
 
 
1429
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
 
1430
 
 
1431
    def setUp(self):
 
1432
        TestCaseForLogFormatter.setUp(self)
 
1433
        log.properties_handler_registry.register(
 
1434
            'bugs_properties_handler',
 
1435
            log._bugs_properties_handler)
 
1436
 
 
1437
    def make_commits_with_bugs(self):
 
1438
        """Helper method for LogFormatter tests"""
 
1439
        tree = self.make_branch_and_tree(u'.')
 
1440
        self.build_tree(['a', 'b'])
 
1441
        tree.add('a')
 
1442
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1443
                       revprops={'bugs': 'test://bug/id fixed'})
 
1444
        tree.add('b')
 
1445
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
 
1446
                       authors=['Joe Bar <joe@bar.com>'],
 
1447
                       revprops={'bugs': 'test://bug/id fixed\n'
 
1448
                                 'test://bug/2 fixed'})
 
1449
        return tree
 
1450
 
 
1451
 
 
1452
    def test_long_bugs(self):
 
1453
        tree = self.make_commits_with_bugs()
 
1454
        self.assertFormatterResult("""\
 
1455
------------------------------------------------------------
 
1456
revno: 2
 
1457
fixes bug(s): test://bug/id test://bug/2
 
1458
author: Joe Bar <joe@bar.com>
 
1459
committer: Joe Foo <joe@foo.com>
 
1460
branch nick: work
 
1461
timestamp: Tue 2005-11-22 00:00:01 +0000
 
1462
message:
 
1463
  multiline
 
1464
  log
 
1465
  message
 
1466
------------------------------------------------------------
 
1467
revno: 1
 
1468
fixes bug(s): test://bug/id
 
1469
committer: Joe Foo <joe@foo.com>
 
1470
branch nick: work
 
1471
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1472
message:
 
1473
  simple log message
 
1474
""",
 
1475
            tree.branch, log.LongLogFormatter)
 
1476
 
 
1477
    def test_short_bugs(self):
 
1478
        tree = self.make_commits_with_bugs()
 
1479
        self.assertFormatterResult("""\
 
1480
    2 Joe Bar\t2005-11-22
 
1481
      fixes bug(s): test://bug/id test://bug/2
 
1482
      multiline
 
1483
      log
 
1484
      message
 
1485
 
 
1486
    1 Joe Foo\t2005-11-22
 
1487
      fixes bug(s): test://bug/id
 
1488
      simple log message
 
1489
 
 
1490
""",
 
1491
            tree.branch, log.ShortLogFormatter)
 
1492
 
 
1493
    def test_wrong_bugs_property(self):
 
1494
        tree = self.make_branch_and_tree(u'.')
 
1495
        self.build_tree(['foo'])
 
1496
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1497
                       revprops={'bugs': 'test://bug/id invalid_value'})
 
1498
        self.assertFormatterResult("""\
 
1499
    1 Joe Foo\t2005-11-22
 
1500
      simple log message
 
1501
 
 
1502
""",
 
1503
            tree.branch, log.ShortLogFormatter)
 
1504
 
 
1505
    def test_bugs_handler_present(self):
 
1506
        self.properties_handler_registry.get('bugs_properties_handler')