18
18
from cStringIO import StringIO
20
20
from bzrlib import (
32
class TestLogMixin(object):
34
def wt_commit(self, wt, message, **kwargs):
35
"""Use some mostly fixed values for commits to simplify tests.
37
Tests can use this function to get some commit attributes. The time
38
stamp is incremented at each commit.
40
if getattr(self, 'timestamp', None) is None:
41
self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
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>')
48
return wt.commit(message, **kwargs)
51
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
30
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
54
super(TestCaseForLogFormatter, self).setUp()
33
super(TestCaseWithoutPropsHandler, self).setUp()
55
34
# keep a reference to the "current" custom prop. handler registry
56
35
self.properties_handler_registry = log.properties_handler_registry
57
# Use a clean registry for log
36
# clean up the registry in log
58
37
log.properties_handler_registry = registry.Registry()
61
log.properties_handler_registry = self.properties_handler_registry
62
self.addCleanup(restore)
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:
69
formatter = formatter_class(to_file=logfile, **formatter_kwargs)
70
if show_log_kwargs is None:
72
log.show_log(branch, formatter, **show_log_kwargs)
73
self.assertEqualDiff(result, logfile.getvalue())
75
def make_standard_commit(self, branch_nick, **kwargs):
76
wt = self.make_branch_and_tree('.')
78
self.addCleanup(wt.unlock)
79
self.build_tree(['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)
87
def make_commits_with_trailing_newlines(self, wt):
88
"""Helper method for LogFormatter tests"""
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')])
95
self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
97
self.build_tree_contents([('c', 'just another manic monday\n')])
99
self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
102
def _prepare_tree_with_merges(self, with_tags=False):
103
wt = self.make_branch_and_memory_tree('.')
105
self.addCleanup(wt.unlock)
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')
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')
40
super(TestCaseWithoutPropsHandler, self)._cleanup()
41
# restore the custom properties handler registry
42
log.properties_handler_registry = self.properties_handler_registry
120
45
class LogCatcher(log.LogFormatter):
121
"""Pull log messages into a list rather than displaying them.
123
To simplify testing we save logged revisions here rather than actually
124
formatting anything, so that we can precisely check the result without
125
being dependent on the formatting.
46
"""Pull log messages into list rather than displaying them.
48
For ease of testing we save log messages here rather than actually
49
formatting them, so that we can precisely check the result without
50
being too dependent on the exact formatting.
52
We should also test the LogFormatter.
128
supports_merge_revisions = True
129
55
supports_delta = True
133
def __init__(self, *args, **kwargs):
134
kwargs.update(dict(to_file=None))
135
super(LogCatcher, self).__init__(*args, **kwargs)
58
super(LogCatcher, self).__init__(to_file=None)
138
61
def log_revision(self, revision):
139
self.revisions.append(revision)
62
self.logs.append(revision)
142
65
class TestShowLog(tests.TestCaseWithTransport):
262
181
lf.supports_merge_revisions = True
263
182
log.show_log(b, lf, verbose=True)
266
self.assertEqual(3, len(revs))
184
self.assertEqual(3, len(lf.logs))
186
logentry = lf.logs[0]
269
187
self.assertEqual('2', logentry.revno)
270
188
self.assertEqual('merge child branch', logentry.rev.message)
271
189
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
191
logentry = lf.logs[1]
274
192
self.assertEqual('1.1.1', logentry.revno)
275
193
self.assertEqual('remove file1 and modify file2', logentry.rev.message)
276
194
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
196
logentry = lf.logs[2]
279
197
self.assertEqual('1', logentry.revno)
280
198
self.assertEqual('add file1 and file2', logentry.rev.message)
281
199
self.checkDelta(logentry.delta, added=['file1', 'file2'])
284
class TestShortLogFormatter(TestCaseForLogFormatter):
202
def make_commits_with_trailing_newlines(wt):
203
"""Helper method for LogFormatter tests"""
206
open('a', 'wb').write('hello moto\n')
208
wt.commit('simple log message', rev_id='a1',
209
timestamp=1132586655.459960938, timezone=-6*3600,
210
committer='Joe Foo <joe@foo.com>')
211
open('b', 'wb').write('goodbye\n')
213
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
214
timestamp=1132586842.411175966, timezone=-6*3600,
215
committer='Joe Foo <joe@foo.com>',
216
authors=['Joe Bar <joe@bar.com>'])
218
open('c', 'wb').write('just another manic monday\n')
220
wt.commit('single line with trailing newline\n', rev_id='a3',
221
timestamp=1132587176.835228920, timezone=-6*3600,
222
committer = 'Joe Foo <joe@foo.com>')
226
def normalize_log(log):
227
"""Replaces the variable lines of logs with fixed lines"""
228
author = 'author: Dolor Sit <test@example.com>'
229
committer = 'committer: Lorem Ipsum <test@example.com>'
230
lines = log.splitlines(True)
231
for idx,line in enumerate(lines):
232
stripped_line = line.lstrip()
233
indent = ' ' * (len(line) - len(stripped_line))
234
if stripped_line.startswith('author:'):
235
lines[idx] = indent + author + '\n'
236
elif stripped_line.startswith('committer:'):
237
lines[idx] = indent + committer + '\n'
238
elif stripped_line.startswith('timestamp:'):
239
lines[idx] = indent + 'timestamp: Just now\n'
240
return ''.join(lines)
243
class TestShortLogFormatter(tests.TestCaseWithTransport):
286
245
def test_trailing_newlines(self):
287
246
wt = self.make_branch_and_tree('.')
288
b = self.make_commits_with_trailing_newlines(wt)
289
self.assertFormatterResult("""\
290
3 Joe Foo\t2005-11-22
247
b = make_commits_with_trailing_newlines(wt)
248
sio = self.make_utf8_encoded_stringio()
249
lf = log.ShortLogFormatter(to_file=sio)
251
self.assertEqualDiff("""\
252
3 Joe Foo\t2005-11-21
291
253
single line with trailing newline
293
2 Joe Foo\t2005-11-22
255
2 Joe Bar\t2005-11-21
298
1 Joe Foo\t2005-11-22
260
1 Joe Foo\t2005-11-21
299
261
simple log message
302
b, log.ShortLogFormatter)
266
def _prepare_tree_with_merges(self, with_tags=False):
267
wt = self.make_branch_and_memory_tree('.')
269
self.addCleanup(wt.unlock)
271
wt.commit('rev-1', rev_id='rev-1',
272
timestamp=1132586655, timezone=36000,
273
committer='Joe Foo <joe@foo.com>')
274
wt.commit('rev-merged', rev_id='rev-2a',
275
timestamp=1132586700, timezone=36000,
276
committer='Joe Foo <joe@foo.com>')
277
wt.set_parent_ids(['rev-1', 'rev-2a'])
278
wt.branch.set_last_revision_info(1, 'rev-1')
279
wt.commit('rev-2', rev_id='rev-2b',
280
timestamp=1132586800, timezone=36000,
281
committer='Joe Foo <joe@foo.com>')
284
branch.tags.set_tag('v0.2', 'rev-2b')
285
wt.commit('rev-3', rev_id='rev-3',
286
timestamp=1132586900, timezone=36000,
287
committer='Jane Foo <jane@foo.com>')
288
branch.tags.set_tag('v1.0rc1', 'rev-3')
289
branch.tags.set_tag('v1.0', 'rev-3')
304
292
def test_short_log_with_merges(self):
305
293
wt = self._prepare_tree_with_merges()
306
self.assertFormatterResult("""\
294
logfile = self.make_utf8_encoded_stringio()
295
formatter = log.ShortLogFormatter(to_file=logfile)
296
log.show_log(wt.branch, formatter)
297
self.assertEqualDiff("""\
307
298
2 Joe Foo\t2005-11-22 [merge]
325
320
Use --include-merges or -n0 to see merged revisions.
327
wt.branch, log.ShortLogFormatter,
328
formatter_kwargs=dict(show_advice=True))
330
324
def test_short_log_with_merges_and_range(self):
331
wt = self._prepare_tree_with_merges()
332
self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
325
wt = self.make_branch_and_memory_tree('.')
327
self.addCleanup(wt.unlock)
329
wt.commit('rev-1', rev_id='rev-1',
330
timestamp=1132586655, timezone=36000,
331
committer='Joe Foo <joe@foo.com>')
332
wt.commit('rev-merged', rev_id='rev-2a',
333
timestamp=1132586700, timezone=36000,
334
committer='Joe Foo <joe@foo.com>')
335
wt.branch.set_last_revision_info(1, 'rev-1')
336
wt.set_parent_ids(['rev-1', 'rev-2a'])
337
wt.commit('rev-2b', rev_id='rev-2b',
338
timestamp=1132586800, timezone=36000,
339
committer='Joe Foo <joe@foo.com>')
340
wt.commit('rev-3a', rev_id='rev-3a',
341
timestamp=1132586800, timezone=36000,
342
committer='Joe Foo <joe@foo.com>')
333
343
wt.branch.set_last_revision_info(2, 'rev-2b')
334
344
wt.set_parent_ids(['rev-2b', 'rev-3a'])
335
self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
336
self.assertFormatterResult("""\
345
wt.commit('rev-3b', rev_id='rev-3b',
346
timestamp=1132586800, timezone=36000,
347
committer='Joe Foo <joe@foo.com>')
348
logfile = self.make_utf8_encoded_stringio()
349
formatter = log.ShortLogFormatter(to_file=logfile)
350
log.show_log(wt.branch, formatter,
351
start_revision=2, end_revision=3)
352
self.assertEqualDiff("""\
337
353
3 Joe Foo\t2005-11-22 [merge]
340
356
2 Joe Foo\t2005-11-22 [merge]
344
wt.branch, log.ShortLogFormatter,
345
show_log_kwargs=dict(start_revision=2, end_revision=3))
347
362
def test_short_log_with_tags(self):
348
363
wt = self._prepare_tree_with_merges(with_tags=True)
349
self.assertFormatterResult("""\
350
3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
364
logfile = self.make_utf8_encoded_stringio()
365
formatter = log.ShortLogFormatter(to_file=logfile)
366
log.show_log(wt.branch, formatter)
367
self.assertEqualDiff("""\
368
3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
353
371
2 Joe Foo\t2005-11-22 {v0.2} [merge]
360
wt.branch, log.ShortLogFormatter)
362
380
def test_short_log_single_merge_revision(self):
363
wt = self._prepare_tree_with_merges()
381
wt = self.make_branch_and_memory_tree('.')
383
self.addCleanup(wt.unlock)
385
wt.commit('rev-1', rev_id='rev-1',
386
timestamp=1132586655, timezone=36000,
387
committer='Joe Foo <joe@foo.com>')
388
wt.commit('rev-merged', rev_id='rev-2a',
389
timestamp=1132586700, timezone=36000,
390
committer='Joe Foo <joe@foo.com>')
391
wt.set_parent_ids(['rev-1', 'rev-2a'])
392
wt.branch.set_last_revision_info(1, 'rev-1')
393
wt.commit('rev-2', rev_id='rev-2b',
394
timestamp=1132586800, timezone=36000,
395
committer='Joe Foo <joe@foo.com>')
396
logfile = self.make_utf8_encoded_stringio()
397
formatter = log.ShortLogFormatter(to_file=logfile)
364
398
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
365
rev = revspec.in_history(wt.branch)
366
self.assertFormatterResult("""\
400
rev = revspec.in_history(wtb)
401
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
402
self.assertEqualDiff("""\
367
403
1.1.1 Joe Foo\t2005-11-22
371
wt.branch, log.ShortLogFormatter,
372
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
375
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
410
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
377
412
def test_short_merge_revs_log_with_merges(self):
378
wt = self._prepare_tree_with_merges()
413
wt = self.make_branch_and_memory_tree('.')
415
self.addCleanup(wt.unlock)
417
wt.commit('rev-1', rev_id='rev-1',
418
timestamp=1132586655, timezone=36000,
419
committer='Joe Foo <joe@foo.com>')
420
wt.commit('rev-merged', rev_id='rev-2a',
421
timestamp=1132586700, timezone=36000,
422
committer='Joe Foo <joe@foo.com>')
423
wt.set_parent_ids(['rev-1', 'rev-2a'])
424
wt.branch.set_last_revision_info(1, 'rev-1')
425
wt.commit('rev-2', rev_id='rev-2b',
426
timestamp=1132586800, timezone=36000,
427
committer='Joe Foo <joe@foo.com>')
428
logfile = self.make_utf8_encoded_stringio()
429
formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
430
log.show_log(wt.branch, formatter)
379
431
# Note that the 1.1.1 indenting is in fact correct given that
380
432
# the revision numbers are right justified within 5 characters
381
433
# for mainline revnos and 9 characters for dotted revnos.
382
self.assertFormatterResult("""\
434
self.assertEqualDiff("""\
383
435
2 Joe Foo\t2005-11-22 [merge]
393
wt.branch, log.ShortLogFormatter,
394
formatter_kwargs=dict(levels=0))
396
447
def test_short_merge_revs_log_single_merge_revision(self):
397
wt = self._prepare_tree_with_merges()
448
wt = self.make_branch_and_memory_tree('.')
450
self.addCleanup(wt.unlock)
452
wt.commit('rev-1', rev_id='rev-1',
453
timestamp=1132586655, timezone=36000,
454
committer='Joe Foo <joe@foo.com>')
455
wt.commit('rev-merged', rev_id='rev-2a',
456
timestamp=1132586700, timezone=36000,
457
committer='Joe Foo <joe@foo.com>')
458
wt.set_parent_ids(['rev-1', 'rev-2a'])
459
wt.branch.set_last_revision_info(1, 'rev-1')
460
wt.commit('rev-2', rev_id='rev-2b',
461
timestamp=1132586800, timezone=36000,
462
committer='Joe Foo <joe@foo.com>')
463
logfile = self.make_utf8_encoded_stringio()
464
formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
398
465
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
399
rev = revspec.in_history(wt.branch)
400
self.assertFormatterResult("""\
467
rev = revspec.in_history(wtb)
468
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
469
self.assertEqualDiff("""\
401
470
1.1.1 Joe Foo\t2005-11-22
405
wt.branch, log.ShortLogFormatter,
406
formatter_kwargs=dict(levels=0),
407
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
410
class TestLongLogFormatter(TestCaseForLogFormatter):
477
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
412
479
def test_verbose_log(self):
413
480
"""Verbose log includes changed files
417
wt = self.make_standard_commit('test_verbose_log', authors=[])
418
self.assertFormatterResult('''\
484
wt = self.make_branch_and_tree('.')
486
self.build_tree(['a'])
488
# XXX: why does a longer nick show up?
489
b.nick = 'test_verbose_log'
490
wt.commit(message='add a',
491
timestamp=1132711707,
493
committer='Lorem Ipsum <test@example.com>')
494
logfile = file('out.tmp', 'w+')
495
formatter = log.LongLogFormatter(to_file=logfile)
496
log.show_log(b, formatter, verbose=True)
499
log_contents = logfile.read()
500
self.assertEqualDiff('''\
419
501
------------------------------------------------------------
421
503
committer: Lorem Ipsum <test@example.com>
422
504
branch nick: test_verbose_log
423
timestamp: Tue 2005-11-22 00:00:00 +0000
505
timestamp: Wed 2005-11-23 12:08:27 +1000
429
wt.branch, log.LongLogFormatter,
430
show_log_kwargs=dict(verbose=True))
432
513
def test_merges_are_indented_by_level(self):
433
514
wt = self.make_branch_and_tree('parent')
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("""\
515
wt.commit('first post')
516
self.run_bzr('branch parent child')
517
self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
518
self.run_bzr('branch child smallerchild')
519
self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
522
self.run_bzr('merge ../smallerchild')
523
self.run_bzr(['commit', '-m', 'merge branch 2'])
524
os.chdir('../parent')
525
self.run_bzr('merge ../child')
526
wt.commit('merge branch 1')
528
sio = self.make_utf8_encoded_stringio()
529
lf = log.LongLogFormatter(to_file=sio, levels=0)
530
log.show_log(b, lf, verbose=True)
531
the_log = normalize_log(sio.getvalue())
532
self.assertEqualDiff("""\
444
533
------------------------------------------------------------
446
committer: Joe Foo <joe@foo.com>
535
committer: Lorem Ipsum <test@example.com>
447
536
branch nick: parent
448
timestamp: Tue 2005-11-22 00:00:04 +0000
451
540
------------------------------------------------------------
452
541
revno: 1.1.2 [merge]
453
committer: Joe Foo <joe@foo.com>
542
committer: Lorem Ipsum <test@example.com>
454
543
branch nick: child
455
timestamp: Tue 2005-11-22 00:00:03 +0000
458
547
------------------------------------------------------------
460
committer: Joe Foo <joe@foo.com>
549
committer: Lorem Ipsum <test@example.com>
461
550
branch nick: smallerchild
462
timestamp: Tue 2005-11-22 00:00:02 +0000
465
554
------------------------------------------------------------
467
committer: Joe Foo <joe@foo.com>
556
committer: Lorem Ipsum <test@example.com>
468
557
branch nick: child
469
timestamp: Tue 2005-11-22 00:00:01 +0000
472
561
------------------------------------------------------------
474
committer: Joe Foo <joe@foo.com>
563
committer: Lorem Ipsum <test@example.com>
475
564
branch nick: parent
476
timestamp: Tue 2005-11-22 00:00:00 +0000
480
wt.branch, log.LongLogFormatter,
481
formatter_kwargs=dict(levels=0),
482
show_log_kwargs=dict(verbose=True))
484
571
def test_verbose_merge_revisions_contain_deltas(self):
485
572
wt = self.make_branch_and_tree('parent')
486
573
self.build_tree(['parent/f1', 'parent/f2'])
487
574
wt.add(['f1','f2'])
488
self.wt_commit(wt, 'first post')
489
child_wt = wt.bzrdir.sprout('child').open_workingtree()
575
wt.commit('first post')
576
self.run_bzr('branch parent child')
490
577
os.unlink('child/f1')
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("""\
578
file('child/f2', 'wb').write('hello\n')
579
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
582
self.run_bzr('merge ../child')
583
wt.commit('merge branch 1')
585
sio = self.make_utf8_encoded_stringio()
586
lf = log.LongLogFormatter(to_file=sio, levels=0)
587
log.show_log(b, lf, verbose=True)
588
the_log = normalize_log(sio.getvalue())
589
self.assertEqualDiff("""\
496
590
------------------------------------------------------------
498
committer: Joe Foo <joe@foo.com>
592
committer: Lorem Ipsum <test@example.com>
499
593
branch nick: parent
500
timestamp: Tue 2005-11-22 00:00:02 +0000
555
651
committer: Joe Foo <joe@foo.com>
556
652
branch nick: test
557
timestamp: Tue 2005-11-22 00:00:00 +0000
653
timestamp: Mon 2005-11-21 09:24:15 -0600
559
655
simple log message
561
b, log.LongLogFormatter)
563
659
def test_author_in_log(self):
564
660
"""Log includes the author name if it's set in
565
661
the revision properties
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("""\
663
wt = self.make_branch_and_tree('.')
665
self.build_tree(['a'])
667
b.nick = 'test_author_log'
668
wt.commit(message='add a',
669
timestamp=1132711707,
671
committer='Lorem Ipsum <test@example.com>',
672
authors=['John Doe <jdoe@example.com>',
673
'Jane Rey <jrey@example.com>'])
675
formatter = log.LongLogFormatter(to_file=sio)
676
log.show_log(b, formatter)
677
self.assertEqualDiff('''\
571
678
------------------------------------------------------------
573
680
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
574
681
committer: Lorem Ipsum <test@example.com>
575
682
branch nick: test_author_log
576
timestamp: Tue 2005-11-22 00:00:00 +0000
683
timestamp: Wed 2005-11-23 12:08:27 +1000
580
wt.branch, log.LongLogFormatter)
582
689
def test_properties_in_log(self):
583
690
"""Log includes the custom properties returned by the registered
586
wt = self.make_standard_commit('test_properties_in_log')
587
def trivial_custom_prop_handler(revision):
588
return {'test_prop':'test_value'}
693
wt = self.make_branch_and_tree('.')
695
self.build_tree(['a'])
697
b.nick = 'test_properties_in_log'
698
wt.commit(message='add a',
699
timestamp=1132711707,
701
committer='Lorem Ipsum <test@example.com>',
702
authors=['John Doe <jdoe@example.com>'])
704
formatter = log.LongLogFormatter(to_file=sio)
706
def trivial_custom_prop_handler(revision):
707
return {'test_prop':'test_value'}
590
# Cleaned up in setUp()
591
log.properties_handler_registry.register(
592
'trivial_custom_prop_handler',
593
trivial_custom_prop_handler)
594
self.assertFormatterResult("""\
709
log.properties_handler_registry.register(
710
'trivial_custom_prop_handler',
711
trivial_custom_prop_handler)
712
log.show_log(b, formatter)
714
log.properties_handler_registry.remove(
715
'trivial_custom_prop_handler')
716
self.assertEqualDiff('''\
595
717
------------------------------------------------------------
597
719
test_prop: test_value
598
720
author: John Doe <jdoe@example.com>
599
721
committer: Lorem Ipsum <test@example.com>
600
722
branch nick: test_properties_in_log
601
timestamp: Tue 2005-11-22 00:00:00 +0000
723
timestamp: Wed 2005-11-23 12:08:27 +1000
605
wt.branch, log.LongLogFormatter)
607
729
def test_properties_in_short_log(self):
608
730
"""Log includes the custom properties returned by the registered
611
wt = self.make_standard_commit('test_properties_in_short_log')
612
def trivial_custom_prop_handler(revision):
613
return {'test_prop':'test_value'}
733
wt = self.make_branch_and_tree('.')
735
self.build_tree(['a'])
737
b.nick = 'test_properties_in_short_log'
738
wt.commit(message='add a',
739
timestamp=1132711707,
741
committer='Lorem Ipsum <test@example.com>',
742
authors=['John Doe <jdoe@example.com>'])
744
formatter = log.ShortLogFormatter(to_file=sio)
746
def trivial_custom_prop_handler(revision):
747
return {'test_prop':'test_value'}
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
749
log.properties_handler_registry.register(
750
'trivial_custom_prop_handler',
751
trivial_custom_prop_handler)
752
log.show_log(b, formatter)
754
log.properties_handler_registry.remove(
755
'trivial_custom_prop_handler')
756
self.assertEqualDiff('''\
757
1 John Doe\t2005-11-23
620
758
test_prop: test_value
624
wt.branch, log.ShortLogFormatter)
626
764
def test_error_in_properties_handler(self):
627
765
"""Log includes the custom properties returned by the registered
630
wt = self.make_standard_commit('error_in_properties_handler',
631
revprops={'first_prop':'first_value'})
632
sio = self.make_utf8_encoded_stringio()
768
wt = self.make_branch_and_tree('.')
770
self.build_tree(['a'])
772
b.nick = 'test_author_log'
773
wt.commit(message='add a',
774
timestamp=1132711707,
776
committer='Lorem Ipsum <test@example.com>',
777
authors=['John Doe <jdoe@example.com>'],
778
revprops={'first_prop':'first_value'})
633
780
formatter = log.LongLogFormatter(to_file=sio)
634
def trivial_custom_prop_handler(revision):
635
raise StandardError("a test error")
782
def trivial_custom_prop_handler(revision):
783
raise StandardError("a test error")
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,)
785
log.properties_handler_registry.register(
786
'trivial_custom_prop_handler',
787
trivial_custom_prop_handler)
788
self.assertRaises(StandardError, log.show_log, b, formatter,)
790
log.properties_handler_registry.remove(
791
'trivial_custom_prop_handler')
642
793
def test_properties_handler_bad_argument(self):
643
wt = self.make_standard_commit('bad_argument',
644
revprops={'a_prop':'test_value'})
645
sio = self.make_utf8_encoded_stringio()
794
wt = self.make_branch_and_tree('.')
796
self.build_tree(['a'])
798
b.nick = 'test_author_log'
799
wt.commit(message='add a',
800
timestamp=1132711707,
802
committer='Lorem Ipsum <test@example.com>',
803
authors=['John Doe <jdoe@example.com>'],
804
revprops={'a_prop':'test_value'})
646
806
formatter = log.LongLogFormatter(to_file=sio)
647
def bad_argument_prop_handler(revision):
648
return {'custom_prop_name':revision.properties['a_prop']}
650
log.properties_handler_registry.register(
651
'bad_argument_prop_handler',
652
bad_argument_prop_handler)
654
self.assertRaises(AttributeError, formatter.show_properties,
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''',
663
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
808
def bad_argument_prop_handler(revision):
809
return {'custom_prop_name':revision.properties['a_prop']}
811
log.properties_handler_registry.register(
812
'bad_argument_prop_handler',
813
bad_argument_prop_handler)
815
self.assertRaises(AttributeError, formatter.show_properties,
818
revision = b.repository.get_revision(b.last_revision())
819
formatter.show_properties(revision, '')
820
self.assertEqualDiff('''custom_prop_name: test_value\n''',
823
log.properties_handler_registry.remove(
824
'bad_argument_prop_handler')
827
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
665
829
def test_long_verbose_log(self):
666
830
"""Verbose log includes changed files
670
wt = self.make_standard_commit('test_long_verbose_log', authors=[])
671
self.assertFormatterResult("""\
834
wt = self.make_branch_and_tree('.')
836
self.build_tree(['a'])
838
# XXX: why does a longer nick show up?
839
b.nick = 'test_verbose_log'
840
wt.commit(message='add a',
841
timestamp=1132711707,
843
committer='Lorem Ipsum <test@example.com>')
844
logfile = file('out.tmp', 'w+')
845
formatter = log.LongLogFormatter(to_file=logfile, levels=1)
846
log.show_log(b, formatter, verbose=True)
849
log_contents = logfile.read()
850
self.assertEqualDiff('''\
672
851
------------------------------------------------------------
674
853
committer: Lorem Ipsum <test@example.com>
675
branch nick: test_long_verbose_log
676
timestamp: Tue 2005-11-22 00:00:00 +0000
854
branch nick: test_verbose_log
855
timestamp: Wed 2005-11-23 12:08:27 +1000
682
wt.branch, log.LongLogFormatter,
683
formatter_kwargs=dict(levels=1),
684
show_log_kwargs=dict(verbose=True))
686
863
def test_long_verbose_contain_deltas(self):
687
864
wt = self.make_branch_and_tree('parent')
688
865
self.build_tree(['parent/f1', 'parent/f2'])
689
866
wt.add(['f1','f2'])
690
self.wt_commit(wt, 'first post')
691
child_wt = wt.bzrdir.sprout('child').open_workingtree()
867
wt.commit('first post')
868
self.run_bzr('branch parent child')
692
869
os.unlink('child/f1')
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("""\
870
file('child/f2', 'wb').write('hello\n')
871
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
874
self.run_bzr('merge ../child')
875
wt.commit('merge branch 1')
877
sio = self.make_utf8_encoded_stringio()
878
lf = log.LongLogFormatter(to_file=sio, levels=1)
879
log.show_log(b, lf, verbose=True)
880
the_log = normalize_log(sio.getvalue())
881
self.assertEqualDiff("""\
698
882
------------------------------------------------------------
700
committer: Joe Foo <joe@foo.com>
884
committer: Lorem Ipsum <test@example.com>
701
885
branch nick: parent
702
timestamp: Tue 2005-11-22 00:00:02 +0000
746
932
committer: Joe Foo <joe@foo.com>
747
933
branch nick: test
748
timestamp: Tue 2005-11-22 00:00:00 +0000
934
timestamp: Mon 2005-11-21 09:24:15 -0600
750
936
simple log message
752
b, log.LongLogFormatter,
753
formatter_kwargs=dict(levels=1))
755
940
def test_long_author_in_log(self):
756
941
"""Log includes the author name if it's set in
757
942
the revision properties
759
wt = self.make_standard_commit('test_author_log')
760
self.assertFormatterResult("""\
944
wt = self.make_branch_and_tree('.')
946
self.build_tree(['a'])
948
b.nick = 'test_author_log'
949
wt.commit(message='add a',
950
timestamp=1132711707,
952
committer='Lorem Ipsum <test@example.com>',
953
authors=['John Doe <jdoe@example.com>'])
955
formatter = log.LongLogFormatter(to_file=sio, levels=1)
956
log.show_log(b, formatter)
957
self.assertEqualDiff('''\
761
958
------------------------------------------------------------
763
960
author: John Doe <jdoe@example.com>
764
961
committer: Lorem Ipsum <test@example.com>
765
962
branch nick: test_author_log
766
timestamp: Tue 2005-11-22 00:00:00 +0000
963
timestamp: Wed 2005-11-23 12:08:27 +1000
770
wt.branch, log.LongLogFormatter,
771
formatter_kwargs=dict(levels=1))
773
969
def test_long_properties_in_log(self):
774
970
"""Log includes the custom properties returned by the registered
777
wt = self.make_standard_commit('test_properties_in_log')
778
def trivial_custom_prop_handler(revision):
779
return {'test_prop':'test_value'}
973
wt = self.make_branch_and_tree('.')
975
self.build_tree(['a'])
977
b.nick = 'test_properties_in_log'
978
wt.commit(message='add a',
979
timestamp=1132711707,
981
committer='Lorem Ipsum <test@example.com>',
982
authors=['John Doe <jdoe@example.com>'])
984
formatter = log.LongLogFormatter(to_file=sio, levels=1)
986
def trivial_custom_prop_handler(revision):
987
return {'test_prop':'test_value'}
781
log.properties_handler_registry.register(
782
'trivial_custom_prop_handler',
783
trivial_custom_prop_handler)
784
self.assertFormatterResult("""\
989
log.properties_handler_registry.register(
990
'trivial_custom_prop_handler',
991
trivial_custom_prop_handler)
992
log.show_log(b, formatter)
994
log.properties_handler_registry.remove(
995
'trivial_custom_prop_handler')
996
self.assertEqualDiff('''\
785
997
------------------------------------------------------------
787
999
test_prop: test_value
788
1000
author: John Doe <jdoe@example.com>
789
1001
committer: Lorem Ipsum <test@example.com>
790
1002
branch nick: test_properties_in_log
791
timestamp: Tue 2005-11-22 00:00:00 +0000
1003
timestamp: Wed 2005-11-23 12:08:27 +1000
795
wt.branch, log.LongLogFormatter,
796
formatter_kwargs=dict(levels=1))
799
class TestLineLogFormatter(TestCaseForLogFormatter):
1010
class TestLineLogFormatter(tests.TestCaseWithTransport):
801
1012
def test_line_log(self):
802
1013
"""Line log should show revno
806
wt = self.make_standard_commit('test-line-log',
807
committer='Line-Log-Formatter Tester <test@line.log>',
809
self.assertFormatterResult("""\
810
1: Line-Log-Formatte... 2005-11-22 add a
812
wt.branch, log.LineLogFormatter)
1017
wt = self.make_branch_and_tree('.')
1019
self.build_tree(['a'])
1021
b.nick = 'test-line-log'
1022
wt.commit(message='add a',
1023
timestamp=1132711707,
1025
committer='Line-Log-Formatter Tester <test@line.log>')
1026
logfile = file('out.tmp', 'w+')
1027
formatter = log.LineLogFormatter(to_file=logfile)
1028
log.show_log(b, formatter)
1031
log_contents = logfile.read()
1032
self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
814
1035
def test_trailing_newlines(self):
815
1036
wt = self.make_branch_and_tree('.')
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
1037
b = make_commits_with_trailing_newlines(wt)
1038
sio = self.make_utf8_encoded_stringio()
1039
lf = log.LineLogFormatter(to_file=sio)
1041
self.assertEqualDiff("""\
1042
3: Joe Foo 2005-11-21 single line with trailing newline
1043
2: Joe Bar 2005-11-21 multiline
1044
1: Joe Foo 2005-11-21 simple log message
822
b, log.LineLogFormatter)
1048
def _prepare_tree_with_merges(self, with_tags=False):
1049
wt = self.make_branch_and_memory_tree('.')
1051
self.addCleanup(wt.unlock)
1053
wt.commit('rev-1', rev_id='rev-1',
1054
timestamp=1132586655, timezone=36000,
1055
committer='Joe Foo <joe@foo.com>')
1056
wt.commit('rev-merged', rev_id='rev-2a',
1057
timestamp=1132586700, timezone=36000,
1058
committer='Joe Foo <joe@foo.com>')
1059
wt.set_parent_ids(['rev-1', 'rev-2a'])
1060
wt.branch.set_last_revision_info(1, 'rev-1')
1061
wt.commit('rev-2', rev_id='rev-2b',
1062
timestamp=1132586800, timezone=36000,
1063
committer='Joe Foo <joe@foo.com>')
1066
branch.tags.set_tag('v0.2', 'rev-2b')
1067
wt.commit('rev-3', rev_id='rev-3',
1068
timestamp=1132586900, timezone=36000,
1069
committer='Jane Foo <jane@foo.com>')
1070
branch.tags.set_tag('v1.0rc1', 'rev-3')
1071
branch.tags.set_tag('v1.0', 'rev-3')
824
1074
def test_line_log_single_merge_revision(self):
825
1075
wt = self._prepare_tree_with_merges()
1076
logfile = self.make_utf8_encoded_stringio()
1077
formatter = log.LineLogFormatter(to_file=logfile)
826
1078
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
827
rev = revspec.in_history(wt.branch)
828
self.assertFormatterResult("""\
1080
rev = revspec.in_history(wtb)
1081
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1082
self.assertEqualDiff("""\
829
1083
1.1.1: Joe Foo 2005-11-22 rev-merged
831
wt.branch, log.LineLogFormatter,
832
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
834
1087
def test_line_log_with_tags(self):
835
1088
wt = self._prepare_tree_with_merges(with_tags=True)
836
self.assertFormatterResult("""\
837
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1089
logfile = self.make_utf8_encoded_stringio()
1090
formatter = log.LineLogFormatter(to_file=logfile)
1091
log.show_log(wt.branch, formatter)
1092
self.assertEqualDiff("""\
1093
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
838
1094
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
839
1095
1: Joe Foo 2005-11-22 rev-1
841
wt.branch, log.LineLogFormatter)
844
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
1099
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
846
1101
def test_line_merge_revs_log(self):
847
1102
"""Line log should show revno
851
wt = self.make_standard_commit('test-line-log',
852
committer='Line-Log-Formatter Tester <test@line.log>',
854
self.assertFormatterResult("""\
855
1: Line-Log-Formatte... 2005-11-22 add a
857
wt.branch, log.LineLogFormatter)
1106
wt = self.make_branch_and_tree('.')
1108
self.build_tree(['a'])
1110
b.nick = 'test-line-log'
1111
wt.commit(message='add a',
1112
timestamp=1132711707,
1114
committer='Line-Log-Formatter Tester <test@line.log>')
1115
logfile = file('out.tmp', 'w+')
1116
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1117
log.show_log(b, formatter)
1120
log_contents = logfile.read()
1121
self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
859
1124
def test_line_merge_revs_log_single_merge_revision(self):
860
wt = self._prepare_tree_with_merges()
1125
wt = self.make_branch_and_memory_tree('.')
1127
self.addCleanup(wt.unlock)
1129
wt.commit('rev-1', rev_id='rev-1',
1130
timestamp=1132586655, timezone=36000,
1131
committer='Joe Foo <joe@foo.com>')
1132
wt.commit('rev-merged', rev_id='rev-2a',
1133
timestamp=1132586700, timezone=36000,
1134
committer='Joe Foo <joe@foo.com>')
1135
wt.set_parent_ids(['rev-1', 'rev-2a'])
1136
wt.branch.set_last_revision_info(1, 'rev-1')
1137
wt.commit('rev-2', rev_id='rev-2b',
1138
timestamp=1132586800, timezone=36000,
1139
committer='Joe Foo <joe@foo.com>')
1140
logfile = self.make_utf8_encoded_stringio()
1141
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
861
1142
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
862
rev = revspec.in_history(wt.branch)
863
self.assertFormatterResult("""\
1144
rev = revspec.in_history(wtb)
1145
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1146
self.assertEqualDiff("""\
864
1147
1.1.1: Joe Foo 2005-11-22 rev-merged
866
wt.branch, log.LineLogFormatter,
867
formatter_kwargs=dict(levels=0),
868
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
870
1151
def test_line_merge_revs_log_with_merges(self):
871
wt = self._prepare_tree_with_merges()
872
self.assertFormatterResult("""\
1152
wt = self.make_branch_and_memory_tree('.')
1154
self.addCleanup(wt.unlock)
1156
wt.commit('rev-1', rev_id='rev-1',
1157
timestamp=1132586655, timezone=36000,
1158
committer='Joe Foo <joe@foo.com>')
1159
wt.commit('rev-merged', rev_id='rev-2a',
1160
timestamp=1132586700, timezone=36000,
1161
committer='Joe Foo <joe@foo.com>')
1162
wt.set_parent_ids(['rev-1', 'rev-2a'])
1163
wt.branch.set_last_revision_info(1, 'rev-1')
1164
wt.commit('rev-2', rev_id='rev-2b',
1165
timestamp=1132586800, timezone=36000,
1166
committer='Joe Foo <joe@foo.com>')
1167
logfile = self.make_utf8_encoded_stringio()
1168
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1169
log.show_log(wt.branch, formatter)
1170
self.assertEqualDiff("""\
873
1171
2: Joe Foo 2005-11-22 [merge] rev-2
874
1172
1.1.1: Joe Foo 2005-11-22 rev-merged
875
1173
1: Joe Foo 2005-11-22 rev-1
877
wt.branch, log.LineLogFormatter,
878
formatter_kwargs=dict(levels=0))
881
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
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>
891
wt.branch, log.GnuChangelogLogFormatter)
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>
903
wt.branch, log.GnuChangelogLogFormatter)
905
def test_verbose(self):
906
wt = self.make_standard_commit('nicky')
907
self.assertFormatterResult('''\
908
2005-11-22 John Doe <jdoe@example.com>
915
wt.branch, log.GnuChangelogLogFormatter,
916
show_log_kwargs=dict(verbose=True))
918
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
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
class TestGetViewRevisions(tests.TestCaseWithTransport):
924
1179
def make_tree_with_commits(self):
925
1180
"""Create a tree with well-known revision ids"""
926
1181
wt = self.make_branch_and_tree('tree1')
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')
1182
wt.commit('commit one', rev_id='1')
1183
wt.commit('commit two', rev_id='2')
1184
wt.commit('commit three', rev_id='3')
930
1185
mainline_revs = [None, '1', '2', '3']
931
1186
rev_nos = {'1': 1, '2': 2, '3': 3}
932
1187
return mainline_revs, rev_nos, wt
935
1190
"""Create a tree with well-known revision ids and a merge"""
936
1191
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
937
1192
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
938
self.wt_commit(tree2, 'four-a', rev_id='4a')
1193
tree2.commit('four-a', rev_id='4a')
939
1194
wt.merge_from_branch(tree2.branch)
940
self.wt_commit(wt, 'four-b', rev_id='4b')
1195
wt.commit('four-b', rev_id='4b')
941
1196
mainline_revs.append('4b')
942
1197
rev_nos['4b'] = 4
944
1199
return mainline_revs, rev_nos, wt
946
def make_branch_with_many_merges(self):
1201
def make_tree_with_many_merges(self):
947
1202
"""Create a tree with well-known revision ids"""
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()
1203
wt = self.make_branch_and_tree('tree1')
1204
self.build_tree_contents([('tree1/f', '1\n')])
1205
wt.add(['f'], ['f-id'])
1206
wt.commit('commit one', rev_id='1')
1207
wt.commit('commit two', rev_id='2')
1209
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
1210
self.build_tree_contents([('tree3/f', '1\n2\n3a\n')])
1211
tree3.commit('commit three a', rev_id='3a')
1213
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1214
tree2.merge_from_branch(tree3.branch)
1215
tree2.commit('commit three b', rev_id='3b')
1217
wt.merge_from_branch(tree2.branch)
1218
wt.commit('commit three c', rev_id='3c')
1219
tree2.commit('four-a', rev_id='4a')
1221
wt.merge_from_branch(tree2.branch)
1222
wt.commit('four-b', rev_id='4b')
976
1224
mainline_revs = [None, '1', '2', '3c', '4b']
977
1225
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
1051
1299
def test_get_view_revisions_merge2(self):
1052
1300
"""Test get_view_revisions when there are merges"""
1053
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1055
self.addCleanup(b.unlock)
1056
revisions = list(self._get_view_revisions(
1057
mainline_revs, rev_nos, b, 'forward'))
1301
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1303
self.addCleanup(wt.unlock)
1304
revisions = list(log.get_view_revisions(
1305
mainline_revs, rev_nos, wt.branch, 'forward'))
1058
1306
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1059
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1307
('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
1060
1308
('4a', '2.2.2', 1)]
1061
1309
self.assertEqual(expected, revisions)
1062
revisions = list(self._get_view_revisions(
1063
mainline_revs, rev_nos, b, 'forward',
1310
revisions = list(log.get_view_revisions(
1311
mainline_revs, rev_nos, wt.branch, 'forward',
1064
1312
include_merges=False))
1065
1313
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1066
1314
('4b', '4', 0)],
1069
1318
def test_file_id_for_range(self):
1070
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1072
self.addCleanup(b.unlock)
1319
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1321
self.addCleanup(wt.unlock)
1074
1323
def rev_from_rev_id(revid, branch):
1075
1324
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1076
1325
return revspec.in_history(branch)
1078
1327
def view_revs(start_rev, end_rev, file_id, direction):
1079
revs = self.applyDeprecated(
1080
symbol_versioning.deprecated_in((2, 2, 0)),
1081
log.calculate_view_revisions,
1328
revs = log.calculate_view_revisions(
1083
1330
start_rev, # start_revision
1084
1331
end_rev, # end_revision
1085
1332
direction, # direction
1275
1513
class TestLogFormatter(tests.TestCase):
1278
super(TestLogFormatter, self).setUp()
1279
self.rev = revision.Revision('a-id')
1280
self.lf = log.LogFormatter(None)
1282
1515
def test_short_committer(self):
1283
def assertCommitter(expected, committer):
1284
self.rev.committer = committer
1285
self.assertEqual(expected, self.lf.short_committer(self.rev))
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')
1516
rev = revision.Revision('a-id')
1517
rev.committer = 'John Doe <jdoe@example.com>'
1518
lf = log.LogFormatter(None)
1519
self.assertEqual('John Doe', lf.short_committer(rev))
1520
rev.committer = 'John Smith <jsmith@example.com>'
1521
self.assertEqual('John Smith', lf.short_committer(rev))
1522
rev.committer = 'John Smith'
1523
self.assertEqual('John Smith', lf.short_committer(rev))
1524
rev.committer = 'jsmith@example.com'
1525
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1526
rev.committer = '<jsmith@example.com>'
1527
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1528
rev.committer = 'John Smith jsmith@example.com'
1529
self.assertEqual('John Smith', lf.short_committer(rev))
1294
1531
def test_short_author(self):
1295
def assertAuthor(expected, author):
1296
self.rev.properties['author'] = author
1297
self.assertEqual(expected, self.lf.short_author(self.rev))
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')
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))
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))
1532
rev = revision.Revision('a-id')
1533
rev.committer = 'John Doe <jdoe@example.com>'
1534
lf = log.LogFormatter(None)
1535
self.assertEqual('John Doe', lf.short_author(rev))
1536
rev.properties['author'] = 'John Smith <jsmith@example.com>'
1537
self.assertEqual('John Smith', lf.short_author(rev))
1538
rev.properties['author'] = 'John Smith'
1539
self.assertEqual('John Smith', lf.short_author(rev))
1540
rev.properties['author'] = 'jsmith@example.com'
1541
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1542
rev.properties['author'] = '<jsmith@example.com>'
1543
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1544
rev.properties['author'] = 'John Smith jsmith@example.com'
1545
self.assertEqual('John Smith', lf.short_author(rev))
1546
del rev.properties['author']
1547
rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1548
'Jane Rey <jrey@example.com>')
1549
self.assertEqual('John Smith', lf.short_author(rev))
1315
1552
class TestReverseByDepth(tests.TestCase):
1461
1698
log.show_branch_change(tree.branch, s, 3, '3b')
1462
1699
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1463
1700
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1467
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1470
TestCaseForLogFormatter.setUp(self)
1471
log.properties_handler_registry.register(
1472
'bugs_properties_handler',
1473
log._bugs_properties_handler)
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'])
1480
self.wt_commit(tree, 'simple log message', rev_id='a1',
1481
revprops={'bugs': 'test://bug/id fixed'})
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'})
1490
def test_long_bugs(self):
1491
tree = self.make_commits_with_bugs()
1492
self.assertFormatterResult("""\
1493
------------------------------------------------------------
1495
fixes bug(s): test://bug/id test://bug/2
1496
author: Joe Bar <joe@bar.com>
1497
committer: Joe Foo <joe@foo.com>
1499
timestamp: Tue 2005-11-22 00:00:01 +0000
1504
------------------------------------------------------------
1506
fixes bug(s): test://bug/id
1507
committer: Joe Foo <joe@foo.com>
1509
timestamp: Tue 2005-11-22 00:00:00 +0000
1513
tree.branch, log.LongLogFormatter)
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
1524
1 Joe Foo\t2005-11-22
1525
fixes bug(s): test://bug/id
1529
tree.branch, log.ShortLogFormatter)
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
1541
tree.branch, log.ShortLogFormatter)
1543
def test_bugs_handler_present(self):
1544
self.properties_handler_registry.get('bugs_properties_handler')
1547
class TestLogForAuthors(TestCaseForLogFormatter):
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>'])
1555
def assertFormatterResult(self, formatter, who, result):
1556
formatter_kwargs = dict()
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)
1563
def test_line_default(self):
1564
self.assertFormatterResult(log.LineLogFormatter, None, """\
1565
1: John Doe 2005-11-22 add a
1568
def test_line_committer(self):
1569
self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
1570
1: Lorem Ipsum 2005-11-22 add a
1573
def test_line_first(self):
1574
self.assertFormatterResult(log.LineLogFormatter, 'first', """\
1575
1: John Doe 2005-11-22 add a
1578
def test_line_all(self):
1579
self.assertFormatterResult(log.LineLogFormatter, 'all', """\
1580
1: John Doe, Jane Rey 2005-11-22 add a
1584
def test_short_default(self):
1585
self.assertFormatterResult(log.ShortLogFormatter, None, """\
1586
1 John Doe\t2005-11-22
1591
def test_short_committer(self):
1592
self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
1593
1 Lorem Ipsum\t2005-11-22
1598
def test_short_first(self):
1599
self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
1600
1 John Doe\t2005-11-22
1605
def test_short_all(self):
1606
self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
1607
1 John Doe, Jane Rey\t2005-11-22
1612
def test_long_default(self):
1613
self.assertFormatterResult(log.LongLogFormatter, None, """\
1614
------------------------------------------------------------
1616
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1617
committer: Lorem Ipsum <test@example.com>
1619
timestamp: Tue 2005-11-22 00:00:00 +0000
1624
def test_long_committer(self):
1625
self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
1626
------------------------------------------------------------
1628
committer: Lorem Ipsum <test@example.com>
1630
timestamp: Tue 2005-11-22 00:00:00 +0000
1635
def test_long_first(self):
1636
self.assertFormatterResult(log.LongLogFormatter, 'first', """\
1637
------------------------------------------------------------
1639
author: John Doe <jdoe@example.com>
1640
committer: Lorem Ipsum <test@example.com>
1642
timestamp: Tue 2005-11-22 00:00:00 +0000
1647
def test_long_all(self):
1648
self.assertFormatterResult(log.LongLogFormatter, 'all', """\
1649
------------------------------------------------------------
1651
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1652
committer: Lorem Ipsum <test@example.com>
1654
timestamp: Tue 2005-11-22 00:00:00 +0000
1659
def test_gnu_changelog_default(self):
1660
self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
1661
2005-11-22 John Doe <jdoe@example.com>
1667
def test_gnu_changelog_committer(self):
1668
self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
1669
2005-11-22 Lorem Ipsum <test@example.com>
1675
def test_gnu_changelog_first(self):
1676
self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
1677
2005-11-22 John Doe <jdoe@example.com>
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>
1691
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
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))
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()
1723
self.addCleanup(br.unlock)
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...
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])
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
1745
self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1746
b, '1.1.1', '3', exclude_common_ancestry=True)
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)