13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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):
201
def test_merges_nonsupporting_formatter(self):
202
"""Tests that show_log will raise if the formatter doesn't
203
support merge revisions."""
204
wt = self.make_branch_and_memory_tree('.')
206
self.addCleanup(wt.unlock)
208
wt.commit('rev-1', rev_id='rev-1',
209
timestamp=1132586655, timezone=36000,
210
committer='Joe Foo <joe@foo.com>')
211
wt.commit('rev-merged', rev_id='rev-2a',
212
timestamp=1132586700, timezone=36000,
213
committer='Joe Foo <joe@foo.com>')
214
wt.set_parent_ids(['rev-1', 'rev-2a'])
215
wt.branch.set_last_revision_info(1, 'rev-1')
216
wt.commit('rev-2', rev_id='rev-2b',
217
timestamp=1132586800, timezone=36000,
218
committer='Joe Foo <joe@foo.com>')
219
logfile = self.make_utf8_encoded_stringio()
220
formatter = log.ShortLogFormatter(to_file=logfile)
223
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
224
rev = revspec.in_history(wtb)
225
self.assertRaises(errors.BzrCommandError, log.show_log, wtb, lf,
226
start_revision=rev, end_revision=rev)
229
def make_commits_with_trailing_newlines(wt):
230
"""Helper method for LogFormatter tests"""
233
open('a', 'wb').write('hello moto\n')
235
wt.commit('simple log message', rev_id='a1',
236
timestamp=1132586655.459960938, timezone=-6*3600,
237
committer='Joe Foo <joe@foo.com>')
238
open('b', 'wb').write('goodbye\n')
240
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
241
timestamp=1132586842.411175966, timezone=-6*3600,
242
committer='Joe Foo <joe@foo.com>',
243
author='Joe Bar <joe@bar.com>')
245
open('c', 'wb').write('just another manic monday\n')
247
wt.commit('single line with trailing newline\n', rev_id='a3',
248
timestamp=1132587176.835228920, timezone=-6*3600,
249
committer = 'Joe Foo <joe@foo.com>')
253
def normalize_log(log):
254
"""Replaces the variable lines of logs with fixed lines"""
255
author = 'author: Dolor Sit <test@example.com>'
256
committer = 'committer: Lorem Ipsum <test@example.com>'
257
lines = log.splitlines(True)
258
for idx,line in enumerate(lines):
259
stripped_line = line.lstrip()
260
indent = ' ' * (len(line) - len(stripped_line))
261
if stripped_line.startswith('author:'):
262
lines[idx] = indent + author + '\n'
263
elif stripped_line.startswith('committer:'):
264
lines[idx] = indent + committer + '\n'
265
elif stripped_line.startswith('timestamp:'):
266
lines[idx] = indent + 'timestamp: Just now\n'
267
return ''.join(lines)
270
class TestShortLogFormatter(tests.TestCaseWithTransport):
286
272
def test_trailing_newlines(self):
287
273
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
274
b = make_commits_with_trailing_newlines(wt)
275
sio = self.make_utf8_encoded_stringio()
276
lf = log.ShortLogFormatter(to_file=sio)
278
self.assertEqualDiff("""\
279
3 Joe Foo\t2005-11-21
291
280
single line with trailing newline
293
2 Joe Foo\t2005-11-22
282
2 Joe Bar\t2005-11-21
298
1 Joe Foo\t2005-11-22
287
1 Joe Foo\t2005-11-21
299
288
simple log message
302
b, log.ShortLogFormatter)
304
293
def test_short_log_with_merges(self):
305
wt = self._prepare_tree_with_merges()
306
self.assertFormatterResult("""\
307
2 Joe Foo\t2005-11-22 [merge]
310
1 Joe Foo\t2005-11-22
314
wt.branch, log.ShortLogFormatter)
316
def test_short_log_with_merges_and_advice(self):
317
wt = self._prepare_tree_with_merges()
318
self.assertFormatterResult("""\
319
2 Joe Foo\t2005-11-22 [merge]
322
1 Joe Foo\t2005-11-22
325
Use --include-merges or -n0 to see merged revisions.
327
wt.branch, log.ShortLogFormatter,
328
formatter_kwargs=dict(show_advice=True))
330
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')
333
wt.branch.set_last_revision_info(2, 'rev-2b')
334
wt.set_parent_ids(['rev-2b', 'rev-3a'])
335
self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
336
self.assertFormatterResult("""\
337
3 Joe Foo\t2005-11-22 [merge]
340
2 Joe Foo\t2005-11-22 [merge]
344
wt.branch, log.ShortLogFormatter,
345
show_log_kwargs=dict(start_revision=2, end_revision=3))
347
def test_short_log_with_tags(self):
348
wt = self._prepare_tree_with_merges(with_tags=True)
349
self.assertFormatterResult("""\
350
3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
353
2 Joe Foo\t2005-11-22 {v0.2} [merge]
356
1 Joe Foo\t2005-11-22
360
wt.branch, log.ShortLogFormatter)
294
wt = self.make_branch_and_memory_tree('.')
296
self.addCleanup(wt.unlock)
298
wt.commit('rev-1', rev_id='rev-1',
299
timestamp=1132586655, timezone=36000,
300
committer='Joe Foo <joe@foo.com>')
301
wt.commit('rev-merged', rev_id='rev-2a',
302
timestamp=1132586700, timezone=36000,
303
committer='Joe Foo <joe@foo.com>')
304
wt.set_parent_ids(['rev-1', 'rev-2a'])
305
wt.branch.set_last_revision_info(1, 'rev-1')
306
wt.commit('rev-2', rev_id='rev-2b',
307
timestamp=1132586800, timezone=36000,
308
committer='Joe Foo <joe@foo.com>')
309
logfile = self.make_utf8_encoded_stringio()
310
formatter = log.ShortLogFormatter(to_file=logfile)
311
log.show_log(wt.branch, formatter)
312
self.assertEqualDiff("""\
313
2 Joe Foo\t2005-11-22 [merge]
316
1 Joe Foo\t2005-11-22
362
322
def test_short_log_single_merge_revision(self):
363
wt = self._prepare_tree_with_merges()
364
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
365
rev = revspec.in_history(wt.branch)
366
self.assertFormatterResult("""\
367
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):
377
def test_short_merge_revs_log_with_merges(self):
378
wt = self._prepare_tree_with_merges()
379
# Note that the 1.1.1 indenting is in fact correct given that
380
# the revision numbers are right justified within 5 characters
381
# for mainline revnos and 9 characters for dotted revnos.
382
self.assertFormatterResult("""\
383
2 Joe Foo\t2005-11-22 [merge]
386
1.1.1 Joe Foo\t2005-11-22
389
1 Joe Foo\t2005-11-22
393
wt.branch, log.ShortLogFormatter,
394
formatter_kwargs=dict(levels=0))
396
def test_short_merge_revs_log_single_merge_revision(self):
397
wt = self._prepare_tree_with_merges()
398
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
399
rev = revspec.in_history(wt.branch)
400
self.assertFormatterResult("""\
401
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):
323
wt = self.make_branch_and_memory_tree('.')
325
self.addCleanup(wt.unlock)
327
wt.commit('rev-1', rev_id='rev-1',
328
timestamp=1132586655, timezone=36000,
329
committer='Joe Foo <joe@foo.com>')
330
wt.commit('rev-merged', rev_id='rev-2a',
331
timestamp=1132586700, timezone=36000,
332
committer='Joe Foo <joe@foo.com>')
333
wt.set_parent_ids(['rev-1', 'rev-2a'])
334
wt.branch.set_last_revision_info(1, 'rev-1')
335
wt.commit('rev-2', rev_id='rev-2b',
336
timestamp=1132586800, timezone=36000,
337
committer='Joe Foo <joe@foo.com>')
338
logfile = self.make_utf8_encoded_stringio()
339
formatter = log.ShortLogFormatter(to_file=logfile)
340
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
342
rev = revspec.in_history(wtb)
343
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
344
self.assertEqualDiff("""\
345
1.1.1 Joe Foo\t2005-11-22
352
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
412
354
def test_verbose_log(self):
413
355
"""Verbose log includes changed files
417
wt = self.make_standard_commit('test_verbose_log', authors=[])
418
self.assertFormatterResult('''\
359
wt = self.make_branch_and_tree('.')
361
self.build_tree(['a'])
363
# XXX: why does a longer nick show up?
364
b.nick = 'test_verbose_log'
365
wt.commit(message='add a',
366
timestamp=1132711707,
368
committer='Lorem Ipsum <test@example.com>')
369
logfile = file('out.tmp', 'w+')
370
formatter = log.LongLogFormatter(to_file=logfile)
371
log.show_log(b, formatter, verbose=True)
374
log_contents = logfile.read()
375
self.assertEqualDiff('''\
419
376
------------------------------------------------------------
421
378
committer: Lorem Ipsum <test@example.com>
422
379
branch nick: test_verbose_log
423
timestamp: Tue 2005-11-22 00:00:00 +0000
380
timestamp: Wed 2005-11-23 12:08:27 +1000
429
wt.branch, log.LongLogFormatter,
430
show_log_kwargs=dict(verbose=True))
432
388
def test_merges_are_indented_by_level(self):
433
389
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("""\
390
wt.commit('first post')
391
self.run_bzr('branch parent child')
392
self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
393
self.run_bzr('branch child smallerchild')
394
self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
397
self.run_bzr('merge ../smallerchild')
398
self.run_bzr(['commit', '-m', 'merge branch 2'])
399
os.chdir('../parent')
400
self.run_bzr('merge ../child')
401
wt.commit('merge branch 1')
403
sio = self.make_utf8_encoded_stringio()
404
lf = log.LongLogFormatter(to_file=sio)
405
log.show_log(b, lf, verbose=True)
406
the_log = normalize_log(sio.getvalue())
407
self.assertEqualDiff("""\
444
408
------------------------------------------------------------
446
committer: Joe Foo <joe@foo.com>
410
committer: Lorem Ipsum <test@example.com>
447
411
branch nick: parent
448
timestamp: Tue 2005-11-22 00:00:04 +0000
451
415
------------------------------------------------------------
453
committer: Joe Foo <joe@foo.com>
417
committer: Lorem Ipsum <test@example.com>
454
418
branch nick: child
455
timestamp: Tue 2005-11-22 00:00:03 +0000
458
422
------------------------------------------------------------
460
committer: Joe Foo <joe@foo.com>
424
committer: Lorem Ipsum <test@example.com>
461
425
branch nick: smallerchild
462
timestamp: Tue 2005-11-22 00:00:02 +0000
465
429
------------------------------------------------------------
467
committer: Joe Foo <joe@foo.com>
431
committer: Lorem Ipsum <test@example.com>
468
432
branch nick: child
469
timestamp: Tue 2005-11-22 00:00:01 +0000
472
436
------------------------------------------------------------
474
committer: Joe Foo <joe@foo.com>
438
committer: Lorem Ipsum <test@example.com>
475
439
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
446
def test_verbose_merge_revisions_contain_deltas(self):
485
447
wt = self.make_branch_and_tree('parent')
486
448
self.build_tree(['parent/f1', 'parent/f2'])
487
449
wt.add(['f1','f2'])
488
self.wt_commit(wt, 'first post')
489
child_wt = wt.bzrdir.sprout('child').open_workingtree()
450
wt.commit('first post')
451
self.run_bzr('branch parent child')
490
452
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("""\
453
file('child/f2', 'wb').write('hello\n')
454
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
457
self.run_bzr('merge ../child')
458
wt.commit('merge branch 1')
460
sio = self.make_utf8_encoded_stringio()
461
lf = log.LongLogFormatter(to_file=sio)
462
log.show_log(b, lf, verbose=True)
463
the_log = normalize_log(sio.getvalue())
464
self.assertEqualDiff("""\
496
465
------------------------------------------------------------
498
committer: Joe Foo <joe@foo.com>
467
committer: Lorem Ipsum <test@example.com>
499
468
branch nick: parent
500
timestamp: Tue 2005-11-22 00:00:02 +0000
555
526
committer: Joe Foo <joe@foo.com>
556
527
branch nick: test
557
timestamp: Tue 2005-11-22 00:00:00 +0000
528
timestamp: Mon 2005-11-21 09:24:15 -0600
559
530
simple log message
561
b, log.LongLogFormatter)
563
534
def test_author_in_log(self):
564
535
"""Log includes the author name if it's set in
565
536
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("""\
538
wt = self.make_branch_and_tree('.')
540
self.build_tree(['a'])
542
b.nick = 'test_author_log'
543
wt.commit(message='add a',
544
timestamp=1132711707,
546
committer='Lorem Ipsum <test@example.com>',
547
author='John Doe <jdoe@example.com>')
549
formatter = log.LongLogFormatter(to_file=sio)
550
log.show_log(b, formatter)
551
self.assertEqualDiff('''\
571
552
------------------------------------------------------------
573
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
554
author: John Doe <jdoe@example.com>
574
555
committer: Lorem Ipsum <test@example.com>
575
556
branch nick: test_author_log
576
timestamp: Tue 2005-11-22 00:00:00 +0000
557
timestamp: Wed 2005-11-23 12:08:27 +1000
580
wt.branch, log.LongLogFormatter)
582
563
def test_properties_in_log(self):
583
"""Log includes the custom properties returned by the registered
564
"""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'}
567
wt = self.make_branch_and_tree('.')
569
self.build_tree(['a'])
571
b.nick = 'test_properties_in_log'
572
wt.commit(message='add a',
573
timestamp=1132711707,
575
committer='Lorem Ipsum <test@example.com>',
576
author='John Doe <jdoe@example.com>')
578
formatter = log.LongLogFormatter(to_file=sio)
580
def trivial_custom_prop_handler(revision):
581
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("""\
583
log.properties_handler_registry.register(
584
'trivial_custom_prop_handler',
585
trivial_custom_prop_handler)
586
log.show_log(b, formatter)
588
log.properties_handler_registry.remove(
589
'trivial_custom_prop_handler')
590
self.assertEqualDiff('''\
595
591
------------------------------------------------------------
597
593
test_prop: test_value
598
594
author: John Doe <jdoe@example.com>
599
595
committer: Lorem Ipsum <test@example.com>
600
596
branch nick: test_properties_in_log
601
timestamp: Tue 2005-11-22 00:00:00 +0000
597
timestamp: Wed 2005-11-23 12:08:27 +1000
605
wt.branch, log.LongLogFormatter)
607
def test_properties_in_short_log(self):
608
"""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'}
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
620
test_prop: test_value
624
wt.branch, log.ShortLogFormatter)
626
603
def test_error_in_properties_handler(self):
627
"""Log includes the custom properties returned by the registered
604
"""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()
607
wt = self.make_branch_and_tree('.')
609
self.build_tree(['a'])
611
b.nick = 'test_author_log'
612
wt.commit(message='add a',
613
timestamp=1132711707,
615
committer='Lorem Ipsum <test@example.com>',
616
author='John Doe <jdoe@example.com>',
617
revprops={'first_prop':'first_value'})
633
619
formatter = log.LongLogFormatter(to_file=sio)
634
def trivial_custom_prop_handler(revision):
635
raise StandardError("a test error")
621
def trivial_custom_prop_handler(revision):
622
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,)
624
log.properties_handler_registry.register(
625
'trivial_custom_prop_handler',
626
trivial_custom_prop_handler)
627
self.assertRaises(StandardError, log.show_log, b, formatter,)
629
log.properties_handler_registry.remove(
630
'trivial_custom_prop_handler')
642
632
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()
633
wt = self.make_branch_and_tree('.')
635
self.build_tree(['a'])
637
b.nick = 'test_author_log'
638
wt.commit(message='add a',
639
timestamp=1132711707,
641
committer='Lorem Ipsum <test@example.com>',
642
author='John Doe <jdoe@example.com>',
643
revprops={'a_prop':'test_value'})
646
645
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):
665
def test_long_verbose_log(self):
666
"""Verbose log includes changed files
670
wt = self.make_standard_commit('test_long_verbose_log', authors=[])
671
self.assertFormatterResult("""\
672
------------------------------------------------------------
674
committer: Lorem Ipsum <test@example.com>
675
branch nick: test_long_verbose_log
676
timestamp: Tue 2005-11-22 00:00:00 +0000
682
wt.branch, log.LongLogFormatter,
683
formatter_kwargs=dict(levels=1),
684
show_log_kwargs=dict(verbose=True))
686
def test_long_verbose_contain_deltas(self):
687
wt = self.make_branch_and_tree('parent')
688
self.build_tree(['parent/f1', 'parent/f2'])
690
self.wt_commit(wt, 'first post')
691
child_wt = wt.bzrdir.sprout('child').open_workingtree()
692
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("""\
698
------------------------------------------------------------
700
committer: Joe Foo <joe@foo.com>
702
timestamp: Tue 2005-11-22 00:00:02 +0000
709
------------------------------------------------------------
711
committer: Joe Foo <joe@foo.com>
713
timestamp: Tue 2005-11-22 00:00:00 +0000
720
wt.branch, log.LongLogFormatter,
721
formatter_kwargs=dict(levels=1),
722
show_log_kwargs=dict(verbose=True))
724
def test_long_trailing_newlines(self):
725
wt = self.make_branch_and_tree('.')
726
b = self.make_commits_with_trailing_newlines(wt)
727
self.assertFormatterResult("""\
728
------------------------------------------------------------
730
committer: Joe Foo <joe@foo.com>
732
timestamp: Tue 2005-11-22 00:00:02 +0000
734
single line with trailing newline
735
------------------------------------------------------------
737
committer: Joe Foo <joe@foo.com>
739
timestamp: Tue 2005-11-22 00:00:01 +0000
744
------------------------------------------------------------
746
committer: Joe Foo <joe@foo.com>
748
timestamp: Tue 2005-11-22 00:00:00 +0000
752
b, log.LongLogFormatter,
753
formatter_kwargs=dict(levels=1))
755
def test_long_author_in_log(self):
756
"""Log includes the author name if it's set in
757
the revision properties
759
wt = self.make_standard_commit('test_author_log')
760
self.assertFormatterResult("""\
761
------------------------------------------------------------
763
author: John Doe <jdoe@example.com>
764
committer: Lorem Ipsum <test@example.com>
765
branch nick: test_author_log
766
timestamp: Tue 2005-11-22 00:00:00 +0000
770
wt.branch, log.LongLogFormatter,
771
formatter_kwargs=dict(levels=1))
773
def test_long_properties_in_log(self):
774
"""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'}
781
log.properties_handler_registry.register(
782
'trivial_custom_prop_handler',
783
trivial_custom_prop_handler)
784
self.assertFormatterResult("""\
785
------------------------------------------------------------
787
test_prop: test_value
788
author: John Doe <jdoe@example.com>
789
committer: Lorem Ipsum <test@example.com>
790
branch nick: test_properties_in_log
791
timestamp: Tue 2005-11-22 00:00:00 +0000
795
wt.branch, log.LongLogFormatter,
796
formatter_kwargs=dict(levels=1))
799
class TestLineLogFormatter(TestCaseForLogFormatter):
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 = b.repository.get_revision(b.last_revision())
658
formatter.show_properties(revision, '')
659
self.assertEqualDiff('''custom_prop_name: test_value\n''',
662
log.properties_handler_registry.remove(
663
'bad_argument_prop_handler')
666
class TestLineLogFormatter(tests.TestCaseWithTransport):
801
668
def test_line_log(self):
802
669
"""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)
673
wt = self.make_branch_and_tree('.')
675
self.build_tree(['a'])
677
b.nick = 'test-line-log'
678
wt.commit(message='add a',
679
timestamp=1132711707,
681
committer='Line-Log-Formatter Tester <test@line.log>')
682
logfile = file('out.tmp', 'w+')
683
formatter = log.LineLogFormatter(to_file=logfile)
684
log.show_log(b, formatter)
687
log_contents = logfile.read()
688
self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
814
691
def test_trailing_newlines(self):
815
692
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
693
b = make_commits_with_trailing_newlines(wt)
694
sio = self.make_utf8_encoded_stringio()
695
lf = log.LineLogFormatter(to_file=sio)
697
self.assertEqualDiff("""\
698
3: Joe Foo 2005-11-21 single line with trailing newline
699
2: Joe Bar 2005-11-21 multiline
700
1: Joe Foo 2005-11-21 simple log message
822
b, log.LineLogFormatter)
824
704
def test_line_log_single_merge_revision(self):
825
wt = self._prepare_tree_with_merges()
826
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
827
rev = revspec.in_history(wt.branch)
828
self.assertFormatterResult("""\
829
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
def test_line_log_with_tags(self):
835
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
838
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
839
1: Joe Foo 2005-11-22 rev-1
841
wt.branch, log.LineLogFormatter)
844
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
846
def test_line_merge_revs_log(self):
847
"""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)
859
def test_line_merge_revs_log_single_merge_revision(self):
860
wt = self._prepare_tree_with_merges()
861
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
862
rev = revspec.in_history(wt.branch)
863
self.assertFormatterResult("""\
864
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
def test_line_merge_revs_log_with_merges(self):
871
wt = self._prepare_tree_with_merges()
872
self.assertFormatterResult("""\
873
2: Joe Foo 2005-11-22 [merge] rev-2
874
1.1.1: Joe Foo 2005-11-22 rev-merged
875
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)
705
wt = self.make_branch_and_memory_tree('.')
707
self.addCleanup(wt.unlock)
709
wt.commit('rev-1', rev_id='rev-1',
710
timestamp=1132586655, timezone=36000,
711
committer='Joe Foo <joe@foo.com>')
712
wt.commit('rev-merged', rev_id='rev-2a',
713
timestamp=1132586700, timezone=36000,
714
committer='Joe Foo <joe@foo.com>')
715
wt.set_parent_ids(['rev-1', 'rev-2a'])
716
wt.branch.set_last_revision_info(1, 'rev-1')
717
wt.commit('rev-2', rev_id='rev-2b',
718
timestamp=1132586800, timezone=36000,
719
committer='Joe Foo <joe@foo.com>')
720
logfile = self.make_utf8_encoded_stringio()
721
formatter = log.LineLogFormatter(to_file=logfile)
722
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
724
rev = revspec.in_history(wtb)
725
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
726
self.assertEqualDiff("""\
727
1.1.1: Joe Foo 2005-11-22 rev-merged
733
class TestGetViewRevisions(tests.TestCaseWithTransport):
924
735
def make_tree_with_commits(self):
925
736
"""Create a tree with well-known revision ids"""
926
737
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')
738
wt.commit('commit one', rev_id='1')
739
wt.commit('commit two', rev_id='2')
740
wt.commit('commit three', rev_id='3')
930
741
mainline_revs = [None, '1', '2', '3']
931
742
rev_nos = {'1': 1, '2': 2, '3': 3}
932
743
return mainline_revs, rev_nos, wt
1051
855
def test_get_view_revisions_merge2(self):
1052
856
"""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'))
857
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
859
self.addCleanup(wt.unlock)
860
revisions = list(log.get_view_revisions(
861
mainline_revs, rev_nos, wt.branch, 'forward'))
1058
862
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1059
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
863
('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
1060
864
('4a', '2.2.2', 1)]
1061
865
self.assertEqual(expected, revisions)
1062
revisions = list(self._get_view_revisions(
1063
mainline_revs, rev_nos, b, 'forward',
866
revisions = list(log.get_view_revisions(
867
mainline_revs, rev_nos, wt.branch, 'forward',
1064
868
include_merges=False))
1065
869
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1066
870
('4b', '4', 0)],
1069
874
def test_file_id_for_range(self):
1070
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1072
self.addCleanup(b.unlock)
875
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
877
self.addCleanup(wt.unlock)
1074
879
def rev_from_rev_id(revid, branch):
1075
880
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1076
881
return revspec.in_history(branch)
1078
883
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,
884
revs = log.calculate_view_revisions(
1083
886
start_rev, # start_revision
1084
887
end_rev, # end_revision
1085
888
direction, # direction
1086
889
file_id, # specific_fileid
1087
890
True, # generate_merge_revisions
891
True, # allow_single_merge_revision
1091
rev_3a = rev_from_rev_id('3a', b)
1092
rev_4b = rev_from_rev_id('4b', b)
1093
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1094
('3a', '2.1.1', 2)],
895
rev_3a = rev_from_rev_id('3a', wt.branch)
896
rev_4b = rev_from_rev_id('4b', wt.branch)
897
self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
1095
898
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1096
# Note: 3c still appears before 3a here because of depth-based sorting
1097
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1098
('3a', '2.1.1', 2)],
899
# Note that the depth is 0 for 3a because depths are normalized, but
900
# there is still a bug somewhere... most probably in
901
# _filter_revision_range and/or get_view_revisions still around a bad
902
# use of reverse_by_depth
903
self.assertEqual([('3a', '2.1.1', 0)],
1099
904
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1102
907
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1104
def get_view_revisions(self, *args):
1105
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1106
log.get_view_revisions, *args)
1108
909
def create_tree_with_single_merge(self):
1109
910
"""Create a branch with a moderate layout.
1275
1065
class TestLogFormatter(tests.TestCase):
1278
super(TestLogFormatter, self).setUp()
1279
self.rev = revision.Revision('a-id')
1280
self.lf = log.LogFormatter(None)
1282
1067
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')
1068
rev = revision.Revision('a-id')
1069
rev.committer = 'John Doe <jdoe@example.com>'
1070
lf = log.LogFormatter(None)
1071
self.assertEqual('John Doe', lf.short_committer(rev))
1072
rev.committer = 'John Smith <jsmith@example.com>'
1073
self.assertEqual('John Smith', lf.short_committer(rev))
1074
rev.committer = 'John Smith'
1075
self.assertEqual('John Smith', lf.short_committer(rev))
1076
rev.committer = 'jsmith@example.com'
1077
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1078
rev.committer = '<jsmith@example.com>'
1079
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1080
rev.committer = 'John Smith jsmith@example.com'
1081
self.assertEqual('John Smith', lf.short_committer(rev))
1294
1083
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))
1084
rev = revision.Revision('a-id')
1085
rev.committer = 'John Doe <jdoe@example.com>'
1086
lf = log.LogFormatter(None)
1087
self.assertEqual('John Doe', lf.short_author(rev))
1088
rev.properties['author'] = 'John Smith <jsmith@example.com>'
1089
self.assertEqual('John Smith', lf.short_author(rev))
1090
rev.properties['author'] = 'John Smith'
1091
self.assertEqual('John Smith', lf.short_author(rev))
1092
rev.properties['author'] = 'jsmith@example.com'
1093
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1094
rev.properties['author'] = '<jsmith@example.com>'
1095
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1096
rev.properties['author'] = 'John Smith jsmith@example.com'
1097
self.assertEqual('John Smith', lf.short_author(rev))
1315
1100
class TestReverseByDepth(tests.TestCase):
1364
1149
# revisions are not in the same order.
1365
1150
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1366
1151
[('3', 3), ('4', 4), ('2', 2), ('1', 2),])
1369
class TestHistoryChange(tests.TestCaseWithTransport):
1371
def setup_a_tree(self):
1372
tree = self.make_branch_and_tree('tree')
1374
self.addCleanup(tree.unlock)
1375
tree.commit('1a', rev_id='1a')
1376
tree.commit('2a', rev_id='2a')
1377
tree.commit('3a', rev_id='3a')
1380
def setup_ab_tree(self):
1381
tree = self.setup_a_tree()
1382
tree.set_last_revision('1a')
1383
tree.branch.set_last_revision_info(1, '1a')
1384
tree.commit('2b', rev_id='2b')
1385
tree.commit('3b', rev_id='3b')
1388
def setup_ac_tree(self):
1389
tree = self.setup_a_tree()
1390
tree.set_last_revision(revision.NULL_REVISION)
1391
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1392
tree.commit('1c', rev_id='1c')
1393
tree.commit('2c', rev_id='2c')
1394
tree.commit('3c', rev_id='3c')
1397
def test_all_new(self):
1398
tree = self.setup_ab_tree()
1399
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1400
self.assertEqual([], old)
1401
self.assertEqual(['2a', '3a'], new)
1403
def test_all_old(self):
1404
tree = self.setup_ab_tree()
1405
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1406
self.assertEqual([], new)
1407
self.assertEqual(['2a', '3a'], old)
1409
def test_null_old(self):
1410
tree = self.setup_ab_tree()
1411
old, new = log.get_history_change(revision.NULL_REVISION,
1412
'3a', tree.branch.repository)
1413
self.assertEqual([], old)
1414
self.assertEqual(['1a', '2a', '3a'], new)
1416
def test_null_new(self):
1417
tree = self.setup_ab_tree()
1418
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1419
tree.branch.repository)
1420
self.assertEqual([], new)
1421
self.assertEqual(['1a', '2a', '3a'], old)
1423
def test_diverged(self):
1424
tree = self.setup_ab_tree()
1425
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1426
self.assertEqual(old, ['2a', '3a'])
1427
self.assertEqual(new, ['2b', '3b'])
1429
def test_unrelated(self):
1430
tree = self.setup_ac_tree()
1431
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1432
self.assertEqual(old, ['1a', '2a', '3a'])
1433
self.assertEqual(new, ['1c', '2c', '3c'])
1435
def test_show_branch_change(self):
1436
tree = self.setup_ab_tree()
1438
log.show_branch_change(tree.branch, s, 3, '3a')
1439
self.assertContainsRe(s.getvalue(),
1440
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1441
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1443
def test_show_branch_change_no_change(self):
1444
tree = self.setup_ab_tree()
1446
log.show_branch_change(tree.branch, s, 3, '3b')
1447
self.assertEqual(s.getvalue(),
1448
'Nothing seems to have changed\n')
1450
def test_show_branch_change_no_old(self):
1451
tree = self.setup_ab_tree()
1453
log.show_branch_change(tree.branch, s, 2, '2b')
1454
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1455
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1457
def test_show_branch_change_no_new(self):
1458
tree = self.setup_ab_tree()
1459
tree.branch.set_last_revision_info(2, '2b')
1461
log.show_branch_change(tree.branch, s, 3, '3b')
1462
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1463
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')
1546
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1548
def make_branch_with_alternate_ancestries(self, relpath='.'):
1549
# See test_merge_sorted_exclude_ancestry below for the difference with
1550
# bt.per_branch.test_iter_merge_sorted_revision.
1551
# TestIterMergeSortedRevisionsBushyGraph.
1552
# make_branch_with_alternate_ancestries
1553
# and test_merge_sorted_exclude_ancestry
1554
# See the FIXME in assertLogRevnos too.
1555
builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1567
builder.start_series()
1568
builder.build_snapshot('1', None, [
1569
('add', ('', 'TREE_ROOT', 'directory', '')),])
1570
builder.build_snapshot('1.1.1', ['1'], [])
1571
builder.build_snapshot('2', ['1'], [])
1572
builder.build_snapshot('1.2.1', ['1.1.1'], [])
1573
builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
1574
builder.build_snapshot('3', ['2', '1.1.2'], [])
1575
builder.finish_series()
1576
br = builder.get_branch()
1578
self.addCleanup(br.unlock)
1581
def assertLogRevnos(self, expected_revnos, b, start, end,
1582
exclude_common_ancestry):
1583
# FIXME: the layering in log makes it hard to test intermediate levels,
1584
# I wish adding filters with their parameters were easier...
1586
iter_revs = log._calc_view_revisions(
1587
b, start, end, direction='reverse',
1588
generate_merge_revisions=True,
1589
exclude_common_ancestry=exclude_common_ancestry)
1590
self.assertEqual(expected_revnos,
1591
[revid for revid, revno, depth in iter_revs])
1593
def test_merge_sorted_exclude_ancestry(self):
1594
b = self.make_branch_with_alternate_ancestries()
1595
self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1597
# '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1598
# it should be mentioned even if merge_sort order will make it appear
1600
self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1601
b, '1.1.1', '3', True)