1
# Copyright (C) 2005-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
from cStringIO import StringIO
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):
54
super(TestCaseForLogFormatter, self).setUp()
55
# keep a reference to the "current" custom prop. handler registry
56
self.properties_handler_registry = log.properties_handler_registry
57
# Use a clean registry for log
58
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')
120
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.
128
supports_merge_revisions = True
129
supports_delta = True
133
def __init__(self, *args, **kwargs):
134
kwargs.update(dict(to_file=None))
135
super(LogCatcher, self).__init__(*args, **kwargs)
138
def log_revision(self, revision):
139
self.revisions.append(revision)
142
class TestShowLog(tests.TestCaseWithTransport):
144
def checkDelta(self, delta, **kw):
145
"""Check the filenames touched by a delta are as expected.
147
Caller only have to pass in the list of files for each part, all
148
unspecified parts are considered empty (and checked as such).
150
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
151
# By default we expect an empty list
152
expected = kw.get(n, [])
153
# strip out only the path components
154
got = [x[0] for x in getattr(delta, n)]
155
self.assertEqual(expected, got)
157
def assertInvalidRevisonNumber(self, br, start, end):
159
self.assertRaises(errors.InvalidRevisionNumber,
160
log.show_log, br, lf,
161
start_revision=start, end_revision=end)
163
def test_cur_revno(self):
164
wt = self.make_branch_and_tree('.')
168
wt.commit('empty commit')
169
log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
171
# Since there is a single revision in the branch all the combinations
173
self.assertInvalidRevisonNumber(b, 2, 1)
174
self.assertInvalidRevisonNumber(b, 1, 2)
175
self.assertInvalidRevisonNumber(b, 0, 2)
176
self.assertInvalidRevisonNumber(b, 1, 0)
177
self.assertInvalidRevisonNumber(b, -1, 1)
178
self.assertInvalidRevisonNumber(b, 1, -1)
180
def test_empty_branch(self):
181
wt = self.make_branch_and_tree('.')
184
log.show_log(wt.branch, lf)
186
self.assertEqual([], lf.revisions)
188
def test_empty_commit(self):
189
wt = self.make_branch_and_tree('.')
191
wt.commit('empty commit')
193
log.show_log(wt.branch, lf, verbose=True)
195
self.assertEqual(1, len(revs))
196
self.assertEqual('1', revs[0].revno)
197
self.assertEqual('empty commit', revs[0].rev.message)
198
self.checkDelta(revs[0].delta)
200
def test_simple_commit(self):
201
wt = self.make_branch_and_tree('.')
202
wt.commit('empty commit')
203
self.build_tree(['hello'])
205
wt.commit('add one file',
206
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
207
u'<test@example.com>')
209
log.show_log(wt.branch, lf, verbose=True)
210
self.assertEqual(2, len(lf.revisions))
211
# first one is most recent
212
log_entry = lf.revisions[0]
213
self.assertEqual('2', log_entry.revno)
214
self.assertEqual('add one file', log_entry.rev.message)
215
self.checkDelta(log_entry.delta, added=['hello'])
217
def test_commit_message_with_control_chars(self):
218
wt = self.make_branch_and_tree('.')
219
msg = u"All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
220
msg = msg.replace(u'\r', u'\n')
223
log.show_log(wt.branch, lf, verbose=True)
224
committed_msg = lf.revisions[0].rev.message
225
if wt.branch.repository._serializer.squashes_xml_invalid_characters:
226
self.assertNotEqual(msg, committed_msg)
227
self.assertTrue(len(committed_msg) > len(msg))
229
self.assertEqual(msg, committed_msg)
231
def test_commit_message_without_control_chars(self):
232
wt = self.make_branch_and_tree('.')
233
# escaped. As ElementTree apparently does some kind of
234
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
235
# included in the test commit message, even though they are
236
# valid XML 1.0 characters.
237
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
240
log.show_log(wt.branch, lf, verbose=True)
241
committed_msg = lf.revisions[0].rev.message
242
self.assertEqual(msg, committed_msg)
244
def test_deltas_in_merge_revisions(self):
245
"""Check deltas created for both mainline and merge revisions"""
246
wt = self.make_branch_and_tree('parent')
247
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
250
wt.commit(message='add file1 and file2')
251
self.run_bzr('branch parent child')
252
os.unlink('child/file1')
253
file('child/file2', 'wb').write('hello\n')
254
self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
257
self.run_bzr('merge ../child')
258
wt.commit('merge child branch')
262
lf.supports_merge_revisions = True
263
log.show_log(b, lf, verbose=True)
266
self.assertEqual(3, len(revs))
269
self.assertEqual('2', logentry.revno)
270
self.assertEqual('merge child branch', logentry.rev.message)
271
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
274
self.assertEqual('1.1.1', logentry.revno)
275
self.assertEqual('remove file1 and modify file2', logentry.rev.message)
276
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
279
self.assertEqual('1', logentry.revno)
280
self.assertEqual('add file1 and file2', logentry.rev.message)
281
self.checkDelta(logentry.delta, added=['file1', 'file2'])
284
class TestShortLogFormatter(TestCaseForLogFormatter):
286
def test_trailing_newlines(self):
287
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
291
single line with trailing newline
293
2 Joe Foo\t2005-11-22
298
1 Joe Foo\t2005-11-22
302
b, log.ShortLogFormatter)
304
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)
362
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):
412
def test_verbose_log(self):
413
"""Verbose log includes changed files
417
wt = self.make_standard_commit('test_verbose_log', authors=[])
418
self.assertFormatterResult('''\
419
------------------------------------------------------------
421
committer: Lorem Ipsum <test@example.com>
422
branch nick: test_verbose_log
423
timestamp: Tue 2005-11-22 00:00:00 +0000
429
wt.branch, log.LongLogFormatter,
430
show_log_kwargs=dict(verbose=True))
432
def test_merges_are_indented_by_level(self):
433
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("""\
444
------------------------------------------------------------
446
committer: Joe Foo <joe@foo.com>
448
timestamp: Tue 2005-11-22 00:00:04 +0000
451
------------------------------------------------------------
453
committer: Joe Foo <joe@foo.com>
455
timestamp: Tue 2005-11-22 00:00:03 +0000
458
------------------------------------------------------------
460
committer: Joe Foo <joe@foo.com>
461
branch nick: smallerchild
462
timestamp: Tue 2005-11-22 00:00:02 +0000
465
------------------------------------------------------------
467
committer: Joe Foo <joe@foo.com>
469
timestamp: Tue 2005-11-22 00:00:01 +0000
472
------------------------------------------------------------
474
committer: Joe Foo <joe@foo.com>
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
def test_verbose_merge_revisions_contain_deltas(self):
485
wt = self.make_branch_and_tree('parent')
486
self.build_tree(['parent/f1', 'parent/f2'])
488
self.wt_commit(wt, 'first post')
489
child_wt = wt.bzrdir.sprout('child').open_workingtree()
490
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("""\
496
------------------------------------------------------------
498
committer: Joe Foo <joe@foo.com>
500
timestamp: Tue 2005-11-22 00:00:02 +0000
507
------------------------------------------------------------
509
committer: Joe Foo <joe@foo.com>
511
timestamp: Tue 2005-11-22 00:00:01 +0000
513
removed f1 and modified f2
518
------------------------------------------------------------
520
committer: Joe Foo <joe@foo.com>
522
timestamp: Tue 2005-11-22 00:00:00 +0000
529
wt.branch, log.LongLogFormatter,
530
formatter_kwargs=dict(levels=0),
531
show_log_kwargs=dict(verbose=True))
533
def test_trailing_newlines(self):
534
wt = self.make_branch_and_tree('.')
535
b = self.make_commits_with_trailing_newlines(wt)
536
self.assertFormatterResult("""\
537
------------------------------------------------------------
539
committer: Joe Foo <joe@foo.com>
541
timestamp: Tue 2005-11-22 00:00:02 +0000
543
single line with trailing newline
544
------------------------------------------------------------
546
committer: Joe Foo <joe@foo.com>
548
timestamp: Tue 2005-11-22 00:00:01 +0000
553
------------------------------------------------------------
555
committer: Joe Foo <joe@foo.com>
557
timestamp: Tue 2005-11-22 00:00:00 +0000
561
b, log.LongLogFormatter)
563
def test_author_in_log(self):
564
"""Log includes the author name if it's set in
565
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("""\
571
------------------------------------------------------------
573
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
574
committer: Lorem Ipsum <test@example.com>
575
branch nick: test_author_log
576
timestamp: Tue 2005-11-22 00:00:00 +0000
580
wt.branch, log.LongLogFormatter)
582
def test_properties_in_log(self):
583
"""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'}
590
# Cleaned up in setUp()
591
log.properties_handler_registry.register(
592
'trivial_custom_prop_handler',
593
trivial_custom_prop_handler)
594
self.assertFormatterResult("""\
595
------------------------------------------------------------
597
test_prop: test_value
598
author: John Doe <jdoe@example.com>
599
committer: Lorem Ipsum <test@example.com>
600
branch nick: test_properties_in_log
601
timestamp: Tue 2005-11-22 00:00:00 +0000
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
def test_error_in_properties_handler(self):
627
"""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()
633
formatter = log.LongLogFormatter(to_file=sio)
634
def trivial_custom_prop_handler(revision):
635
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,)
642
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()
646
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):
801
def test_line_log(self):
802
"""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)
814
def test_trailing_newlines(self):
815
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
822
b, log.LineLogFormatter)
824
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)
924
def make_tree_with_commits(self):
925
"""Create a tree with well-known revision ids"""
926
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')
930
mainline_revs = [None, '1', '2', '3']
931
rev_nos = {'1': 1, '2': 2, '3': 3}
932
return mainline_revs, rev_nos, wt
934
def make_tree_with_merges(self):
935
"""Create a tree with well-known revision ids and a merge"""
936
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
937
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
938
self.wt_commit(tree2, 'four-a', rev_id='4a')
939
wt.merge_from_branch(tree2.branch)
940
self.wt_commit(wt, 'four-b', rev_id='4b')
941
mainline_revs.append('4b')
944
return mainline_revs, rev_nos, wt
946
def make_branch_with_many_merges(self):
947
"""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()
976
mainline_revs = [None, '1', '2', '3c', '4b']
977
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
978
full_rev_nos_for_reference = {
981
'3a': '2.1.1', #first commit tree 3
982
'3b': '2.2.1', # first commit tree 2
983
'3c': '3', #merges 3b to main
984
'4a': '2.2.2', # second commit tree 2
985
'4b': '4', # merges 4a to main
987
return mainline_revs, rev_nos, builder.get_branch()
989
def test_get_view_revisions_forward(self):
990
"""Test the get_view_revisions method"""
991
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
993
self.addCleanup(wt.unlock)
994
revisions = list(self._get_view_revisions(
995
mainline_revs, rev_nos, wt.branch, 'forward'))
996
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
998
revisions2 = list(self._get_view_revisions(
999
mainline_revs, rev_nos, wt.branch, 'forward',
1000
include_merges=False))
1001
self.assertEqual(revisions, revisions2)
1003
def test_get_view_revisions_reverse(self):
1004
"""Test the get_view_revisions with reverse"""
1005
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1007
self.addCleanup(wt.unlock)
1008
revisions = list(self._get_view_revisions(
1009
mainline_revs, rev_nos, wt.branch, 'reverse'))
1010
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1012
revisions2 = list(self._get_view_revisions(
1013
mainline_revs, rev_nos, wt.branch, 'reverse',
1014
include_merges=False))
1015
self.assertEqual(revisions, revisions2)
1017
def test_get_view_revisions_merge(self):
1018
"""Test get_view_revisions when there are merges"""
1019
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1021
self.addCleanup(wt.unlock)
1022
revisions = list(self._get_view_revisions(
1023
mainline_revs, rev_nos, wt.branch, 'forward'))
1024
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1025
('4b', '4', 0), ('4a', '3.1.1', 1)],
1027
revisions = list(self._get_view_revisions(
1028
mainline_revs, rev_nos, wt.branch, 'forward',
1029
include_merges=False))
1030
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1034
def test_get_view_revisions_merge_reverse(self):
1035
"""Test get_view_revisions in reverse when there are merges"""
1036
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1038
self.addCleanup(wt.unlock)
1039
revisions = list(self._get_view_revisions(
1040
mainline_revs, rev_nos, wt.branch, 'reverse'))
1041
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1042
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1044
revisions = list(self._get_view_revisions(
1045
mainline_revs, rev_nos, wt.branch, 'reverse',
1046
include_merges=False))
1047
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1051
def test_get_view_revisions_merge2(self):
1052
"""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'))
1058
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1059
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1061
self.assertEqual(expected, revisions)
1062
revisions = list(self._get_view_revisions(
1063
mainline_revs, rev_nos, b, 'forward',
1064
include_merges=False))
1065
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1069
def test_file_id_for_range(self):
1070
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1072
self.addCleanup(b.unlock)
1074
def rev_from_rev_id(revid, branch):
1075
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1076
return revspec.in_history(branch)
1078
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,
1083
start_rev, # start_revision
1084
end_rev, # end_revision
1085
direction, # direction
1086
file_id, # specific_fileid
1087
True, # generate_merge_revisions
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)],
1095
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)],
1099
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1102
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
def create_tree_with_single_merge(self):
1109
"""Create a branch with a moderate layout.
1111
The revision graph looks like:
1119
In this graph, A introduced files f1 and f2 and f3.
1120
B modifies f1 and f3, and C modifies f2 and f3.
1121
D merges the changes from B and C and resolves the conflict for f3.
1123
# TODO: jam 20070218 This seems like it could really be done
1124
# with make_branch_and_memory_tree() if we could just
1125
# create the content of those files.
1126
# TODO: jam 20070218 Another alternative is that we would really
1127
# like to only create this tree 1 time for all tests that
1128
# use it. Since 'log' only uses the tree in a readonly
1129
# fashion, it seems a shame to regenerate an identical
1130
# tree for each test.
1131
# TODO: vila 20100122 One way to address the shame above will be to
1132
# create a memory tree during test parametrization and give a
1133
# *copy* of this tree to each test. Copying a memory tree ought
1134
# to be cheap, at least cheaper than creating them with such
1136
tree = self.make_branch_and_tree('tree')
1138
self.addCleanup(tree.unlock)
1140
self.build_tree_contents([('tree/f1', 'A\n'),
1144
tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1145
tree.commit('A', rev_id='A')
1147
self.build_tree_contents([('tree/f2', 'A\nC\n'),
1148
('tree/f3', 'A\nC\n'),
1150
tree.commit('C', rev_id='C')
1151
# Revert back to A to build the other history.
1152
tree.set_last_revision('A')
1153
tree.branch.set_last_revision_info(1, 'A')
1154
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1156
('tree/f3', 'A\nB\n'),
1158
tree.commit('B', rev_id='B')
1159
tree.set_parent_ids(['B', 'C'])
1160
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1161
('tree/f2', 'A\nC\n'),
1162
('tree/f3', 'A\nB\nC\n'),
1164
tree.commit('D', rev_id='D')
1166
# Switch to a read lock for this tree.
1167
# We still have an addCleanup(tree.unlock) pending
1172
def check_delta(self, delta, **kw):
1173
"""Check the filenames touched by a delta are as expected.
1175
Caller only have to pass in the list of files for each part, all
1176
unspecified parts are considered empty (and checked as such).
1178
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1179
# By default we expect an empty list
1180
expected = kw.get(n, [])
1181
# strip out only the path components
1182
got = [x[0] for x in getattr(delta, n)]
1183
self.assertEqual(expected, got)
1185
def test_tree_with_single_merge(self):
1186
"""Make sure the tree layout is correct."""
1187
tree = self.create_tree_with_single_merge()
1188
rev_A_tree = tree.branch.repository.revision_tree('A')
1189
rev_B_tree = tree.branch.repository.revision_tree('B')
1190
rev_C_tree = tree.branch.repository.revision_tree('C')
1191
rev_D_tree = tree.branch.repository.revision_tree('D')
1193
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1194
modified=['f1', 'f3'])
1196
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1197
modified=['f2', 'f3'])
1199
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1200
modified=['f2', 'f3'])
1202
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1203
modified=['f1', 'f3'])
1205
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
1206
"""Ensure _filter_revisions_touching_file_id returns the right values.
1208
Get the return value from _filter_revisions_touching_file_id and make
1209
sure they are correct.
1211
# The api for _filter_revisions_touching_file_id is a little crazy.
1212
# So we do the setup here.
1213
mainline = tree.branch.revision_history()
1214
mainline.insert(0, None)
1215
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1216
view_revs_iter = self.get_view_revisions(
1217
mainline, revnos, tree.branch, 'reverse', True)
1218
actual_revs = log._filter_revisions_touching_file_id(
1219
tree.branch, file_id, list(view_revs_iter))
1220
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1222
def test_file_id_f1(self):
1223
tree = self.create_tree_with_single_merge()
1224
# f1 should be marked as modified by revisions A and B
1225
self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1227
def test_file_id_f2(self):
1228
tree = self.create_tree_with_single_merge()
1229
# f2 should be marked as modified by revisions A, C, and D
1230
# because D merged the changes from C.
1231
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1233
def test_file_id_f3(self):
1234
tree = self.create_tree_with_single_merge()
1235
# f3 should be marked as modified by revisions A, B, C, and D
1236
self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1238
def test_file_id_with_ghosts(self):
1239
# This is testing bug #209948, where having a ghost would cause
1240
# _filter_revisions_touching_file_id() to fail.
1241
tree = self.create_tree_with_single_merge()
1242
# We need to add a revision, so switch back to a write-locked tree
1243
# (still a single addCleanup(tree.unlock) pending).
1246
first_parent = tree.last_revision()
1247
tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1248
self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1249
tree.commit('commit with a ghost', rev_id='XX')
1250
self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1251
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1253
def test_unknown_file_id(self):
1254
tree = self.create_tree_with_single_merge()
1255
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1257
def test_empty_branch_unknown_file_id(self):
1258
tree = self.make_branch_and_tree('tree')
1259
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1262
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1264
def test_show_changed_revisions_verbose(self):
1265
tree = self.make_branch_and_tree('tree_a')
1266
self.build_tree(['tree_a/foo'])
1268
tree.commit('bar', rev_id='bar-id')
1269
s = self.make_utf8_encoded_stringio()
1270
log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1271
self.assertContainsRe(s.getvalue(), 'bar')
1272
self.assertNotContainsRe(s.getvalue(), 'foo')
1275
class TestLogFormatter(tests.TestCase):
1278
super(TestLogFormatter, self).setUp()
1279
self.rev = revision.Revision('a-id')
1280
self.lf = log.LogFormatter(None)
1282
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')
1294
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))
1315
class TestReverseByDepth(tests.TestCase):
1316
"""Test reverse_by_depth behavior.
1318
This is used to present revisions in forward (oldest first) order in a nice
1321
The tests use lighter revision description to ease reading.
1324
def assertReversed(self, forward, backward):
1325
# Transform the descriptions to suit the API: tests use (revno, depth),
1326
# while the API expects (revid, revno, depth)
1327
def complete_revisions(l):
1328
"""Transform the description to suit the API.
1330
Tests use (revno, depth) whil the API expects (revid, revno, depth).
1331
Since the revid is arbitrary, we just duplicate revno
1333
return [ (r, r, d) for r, d in l]
1334
forward = complete_revisions(forward)
1335
backward= complete_revisions(backward)
1336
self.assertEqual(forward, log.reverse_by_depth(backward))
1339
def test_mainline_revisions(self):
1340
self.assertReversed([( '1', 0), ('2', 0)],
1341
[('2', 0), ('1', 0)])
1343
def test_merged_revisions(self):
1344
self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1345
[('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
1346
def test_shifted_merged_revisions(self):
1347
"""Test irregular layout.
1349
Requesting revisions touching a file can produce "holes" in the depths.
1351
self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1352
[('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
1354
def test_merged_without_child_revisions(self):
1355
"""Test irregular layout.
1357
Revision ranges can produce "holes" in the depths.
1359
# When a revision of higher depth doesn't follow one of lower depth, we
1360
# assume a lower depth one is virtually there
1361
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1362
[('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1363
# So we get the same order after reversing below even if the original
1364
# revisions are not in the same order.
1365
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1366
[('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')
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)