30
class TestCaseForLogFormatter(tests.TestCaseWithTransport):
31
class TestLogMixin(object):
33
def wt_commit(self, wt, message, **kwargs):
34
"""Use some mostly fixed values for commits to simplify tests.
36
Tests can use this function to get some commit attributes. The time
37
stamp is incremented at each commit.
39
if getattr(self, 'timestamp', None) is None:
40
self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
42
self.timestamp += 1 # 1 second between each commit
43
kwargs.setdefault('timestamp', self.timestamp)
44
kwargs.setdefault('timezone', 0) # UTC
45
kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
47
return wt.commit(message, **kwargs)
50
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
33
53
super(TestCaseForLogFormatter, self).setUp()
62
78
self.build_tree(['a'])
64
80
wt.branch.nick = branch_nick
66
kwargs.setdefault('message', 'add a')
67
kwargs.setdefault('timestamp', 1132711707)
68
kwargs.setdefault('timezone', 36000)
69
81
kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
70
82
kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
83
self.wt_commit(wt, 'add a', **kwargs)
86
def make_commits_with_trailing_newlines(self, wt):
87
"""Helper method for LogFormatter tests"""
90
self.build_tree_contents([('a', 'hello moto\n')])
91
self.wt_commit(wt, 'simple log message', rev_id='a1')
92
self.build_tree_contents([('b', 'goodbye\n')])
94
self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
96
self.build_tree_contents([('c', 'just another manic monday\n')])
98
self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
74
101
def _prepare_tree_with_merges(self, with_tags=False):
75
102
wt = self.make_branch_and_memory_tree('.')
77
104
self.addCleanup(wt.unlock)
79
wt.commit('rev-1', rev_id='rev-1',
80
timestamp=1132586655, timezone=36000,
81
committer='Joe Foo <joe@foo.com>')
82
wt.commit('rev-merged', rev_id='rev-2a',
83
timestamp=1132586700, timezone=36000,
84
committer='Joe Foo <joe@foo.com>')
106
self.wt_commit(wt, 'rev-1', rev_id='rev-1')
107
self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
85
108
wt.set_parent_ids(['rev-1', 'rev-2a'])
86
109
wt.branch.set_last_revision_info(1, 'rev-1')
87
wt.commit('rev-2', rev_id='rev-2b',
88
timestamp=1132586800, timezone=36000,
89
committer='Joe Foo <joe@foo.com>')
110
self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
91
112
branch = wt.branch
92
113
branch.tags.set_tag('v0.2', 'rev-2b')
93
wt.commit('rev-3', rev_id='rev-3',
94
timestamp=1132586900, timezone=36000,
95
committer='Jane Foo <jane@foo.com>')
114
self.wt_commit(wt, 'rev-3', rev_id='rev-3')
96
115
branch.tags.set_tag('v1.0rc1', 'rev-3')
97
116
branch.tags.set_tag('v1.0', 'rev-3')
103
119
class LogCatcher(log.LogFormatter):
104
120
"""Pull log messages into a list rather than displaying them.
260
280
self.checkDelta(logentry.delta, added=['file1', 'file2'])
263
def make_commits_with_trailing_newlines(wt):
264
"""Helper method for LogFormatter tests"""
267
open('a', 'wb').write('hello moto\n')
269
wt.commit('simple log message', rev_id='a1',
270
timestamp=1132586655.459960938, timezone=-6*3600,
271
committer='Joe Foo <joe@foo.com>')
272
open('b', 'wb').write('goodbye\n')
274
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
275
timestamp=1132586842.411175966, timezone=-6*3600,
276
committer='Joe Foo <joe@foo.com>',
277
authors=['Joe Bar <joe@bar.com>'])
279
open('c', 'wb').write('just another manic monday\n')
281
wt.commit('single line with trailing newline\n', rev_id='a3',
282
timestamp=1132587176.835228920, timezone=-6*3600,
283
committer = 'Joe Foo <joe@foo.com>')
287
def normalize_log(log):
288
"""Replaces the variable lines of logs with fixed lines"""
289
author = 'author: Dolor Sit <test@example.com>'
290
committer = 'committer: Lorem Ipsum <test@example.com>'
291
lines = log.splitlines(True)
292
for idx,line in enumerate(lines):
293
stripped_line = line.lstrip()
294
indent = ' ' * (len(line) - len(stripped_line))
295
if stripped_line.startswith('author:'):
296
lines[idx] = indent + author + '\n'
297
elif stripped_line.startswith('committer:'):
298
lines[idx] = indent + committer + '\n'
299
elif stripped_line.startswith('timestamp:'):
300
lines[idx] = indent + 'timestamp: Just now\n'
301
return ''.join(lines)
304
283
class TestShortLogFormatter(TestCaseForLogFormatter):
306
285
def test_trailing_newlines(self):
307
286
wt = self.make_branch_and_tree('.')
308
b = make_commits_with_trailing_newlines(wt)
287
b = self.make_commits_with_trailing_newlines(wt)
309
288
self.assertFormatterResult("""\
310
3 Joe Foo\t2005-11-21
289
3 Joe Foo\t2005-11-22
311
290
single line with trailing newline
313
2 Joe Bar\t2005-11-21
292
2 Joe Foo\t2005-11-22
318
1 Joe Foo\t2005-11-21
297
1 Joe Foo\t2005-11-22
319
298
simple log message
348
327
formatter_kwargs=dict(show_advice=True))
350
329
def test_short_log_with_merges_and_range(self):
351
wt = self.make_branch_and_memory_tree('.')
353
self.addCleanup(wt.unlock)
355
wt.commit('rev-1', rev_id='rev-1',
356
timestamp=1132586655, timezone=36000,
357
committer='Joe Foo <joe@foo.com>')
358
wt.commit('rev-merged', rev_id='rev-2a',
359
timestamp=1132586700, timezone=36000,
360
committer='Joe Foo <joe@foo.com>')
361
wt.branch.set_last_revision_info(1, 'rev-1')
362
wt.set_parent_ids(['rev-1', 'rev-2a'])
363
wt.commit('rev-2b', rev_id='rev-2b',
364
timestamp=1132586800, timezone=36000,
365
committer='Joe Foo <joe@foo.com>')
366
wt.commit('rev-3a', rev_id='rev-3a',
367
timestamp=1132586800, timezone=36000,
368
committer='Joe Foo <joe@foo.com>')
330
wt = self._prepare_tree_with_merges()
331
self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
369
332
wt.branch.set_last_revision_info(2, 'rev-2b')
370
333
wt.set_parent_ids(['rev-2b', 'rev-3a'])
371
wt.commit('rev-3b', rev_id='rev-3b',
372
timestamp=1132586800, timezone=36000,
373
committer='Joe Foo <joe@foo.com>')
334
self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
374
335
self.assertFormatterResult("""\
375
336
3 Joe Foo\t2005-11-22 [merge]
378
339
2 Joe Foo\t2005-11-22 [merge]
382
343
wt.branch, log.ShortLogFormatter,
398
359
wt.branch, log.ShortLogFormatter)
400
361
def test_short_log_single_merge_revision(self):
401
wt = self.make_branch_and_memory_tree('.')
403
self.addCleanup(wt.unlock)
405
wt.commit('rev-1', rev_id='rev-1',
406
timestamp=1132586655, timezone=36000,
407
committer='Joe Foo <joe@foo.com>')
408
wt.commit('rev-merged', rev_id='rev-2a',
409
timestamp=1132586700, timezone=36000,
410
committer='Joe Foo <joe@foo.com>')
411
wt.set_parent_ids(['rev-1', 'rev-2a'])
412
wt.branch.set_last_revision_info(1, 'rev-1')
413
wt.commit('rev-2', rev_id='rev-2b',
414
timestamp=1132586800, timezone=36000,
415
committer='Joe Foo <joe@foo.com>')
362
wt = self._prepare_tree_with_merges()
416
363
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
417
364
rev = revspec.in_history(wt.branch)
418
365
self.assertFormatterResult("""\
427
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
429
376
def test_short_merge_revs_log_with_merges(self):
430
wt = self.make_branch_and_memory_tree('.')
432
self.addCleanup(wt.unlock)
434
wt.commit('rev-1', rev_id='rev-1',
435
timestamp=1132586655, timezone=36000,
436
committer='Joe Foo <joe@foo.com>')
437
wt.commit('rev-merged', rev_id='rev-2a',
438
timestamp=1132586700, timezone=36000,
439
committer='Joe Foo <joe@foo.com>')
440
wt.set_parent_ids(['rev-1', 'rev-2a'])
441
wt.branch.set_last_revision_info(1, 'rev-1')
442
wt.commit('rev-2', rev_id='rev-2b',
443
timestamp=1132586800, timezone=36000,
444
committer='Joe Foo <joe@foo.com>')
377
wt = self._prepare_tree_with_merges()
445
378
# Note that the 1.1.1 indenting is in fact correct given that
446
379
# the revision numbers are right justified within 5 characters
447
380
# for mainline revnos and 9 characters for dotted revnos.
460
393
formatter_kwargs=dict(levels=0))
462
395
def test_short_merge_revs_log_single_merge_revision(self):
463
wt = self.make_branch_and_memory_tree('.')
465
self.addCleanup(wt.unlock)
467
wt.commit('rev-1', rev_id='rev-1',
468
timestamp=1132586655, timezone=36000,
469
committer='Joe Foo <joe@foo.com>')
470
wt.commit('rev-merged', rev_id='rev-2a',
471
timestamp=1132586700, timezone=36000,
472
committer='Joe Foo <joe@foo.com>')
473
wt.set_parent_ids(['rev-1', 'rev-2a'])
474
wt.branch.set_last_revision_info(1, 'rev-1')
475
wt.commit('rev-2', rev_id='rev-2b',
476
timestamp=1132586800, timezone=36000,
477
committer='Joe Foo <joe@foo.com>')
396
wt = self._prepare_tree_with_merges()
478
397
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
479
398
rev = revspec.in_history(wt.branch)
480
399
self.assertFormatterResult("""\
512
431
def test_merges_are_indented_by_level(self):
513
432
wt = self.make_branch_and_tree('parent')
514
wt.commit('first post')
515
self.run_bzr('branch parent child')
516
self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
517
self.run_bzr('branch child smallerchild')
518
self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
521
self.run_bzr('merge ../smallerchild')
522
self.run_bzr(['commit', '-m', 'merge branch 2'])
523
os.chdir('../parent')
524
self.run_bzr('merge ../child')
525
wt.commit('merge branch 1')
433
self.wt_commit(wt, 'first post')
434
child_wt = wt.bzrdir.sprout('child').open_workingtree()
435
self.wt_commit(child_wt, 'branch 1')
436
smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
437
self.wt_commit(smallerchild_wt, 'branch 2')
438
child_wt.merge_from_branch(smallerchild_wt.branch)
439
self.wt_commit(child_wt, 'merge branch 2')
440
wt.merge_from_branch(child_wt.branch)
441
self.wt_commit(wt, 'merge branch 1')
526
442
self.assertFormatterResult("""\
527
443
------------------------------------------------------------
529
committer: Lorem Ipsum <test@example.com>
445
committer: Joe Foo <joe@foo.com>
530
446
branch nick: parent
447
timestamp: Tue 2005-11-22 00:00:04 +0000
534
450
------------------------------------------------------------
535
451
revno: 1.1.2 [merge]
536
committer: Lorem Ipsum <test@example.com>
452
committer: Joe Foo <joe@foo.com>
537
453
branch nick: child
454
timestamp: Tue 2005-11-22 00:00:03 +0000
541
457
------------------------------------------------------------
543
committer: Lorem Ipsum <test@example.com>
459
committer: Joe Foo <joe@foo.com>
544
460
branch nick: smallerchild
461
timestamp: Tue 2005-11-22 00:00:02 +0000
548
464
------------------------------------------------------------
550
committer: Lorem Ipsum <test@example.com>
466
committer: Joe Foo <joe@foo.com>
551
467
branch nick: child
468
timestamp: Tue 2005-11-22 00:00:01 +0000
555
471
------------------------------------------------------------
557
committer: Lorem Ipsum <test@example.com>
473
committer: Joe Foo <joe@foo.com>
558
474
branch nick: parent
475
timestamp: Tue 2005-11-22 00:00:00 +0000
563
479
wt.branch, log.LongLogFormatter,
564
480
formatter_kwargs=dict(levels=0),
565
show_log_kwargs=dict(verbose=True),
481
show_log_kwargs=dict(verbose=True))
568
483
def test_verbose_merge_revisions_contain_deltas(self):
569
484
wt = self.make_branch_and_tree('parent')
570
485
self.build_tree(['parent/f1', 'parent/f2'])
571
486
wt.add(['f1','f2'])
572
wt.commit('first post')
573
self.run_bzr('branch parent child')
487
self.wt_commit(wt, 'first post')
488
child_wt = wt.bzrdir.sprout('child').open_workingtree()
574
489
os.unlink('child/f1')
575
file('child/f2', 'wb').write('hello\n')
576
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
579
self.run_bzr('merge ../child')
580
wt.commit('merge branch 1')
490
self.build_tree_contents([('child/f2', 'hello\n')])
491
self.wt_commit(child_wt, 'removed f1 and modified f2')
492
wt.merge_from_branch(child_wt.branch)
493
self.wt_commit(wt, 'merge branch 1')
581
494
self.assertFormatterResult("""\
582
495
------------------------------------------------------------
584
committer: Lorem Ipsum <test@example.com>
497
committer: Joe Foo <joe@foo.com>
585
498
branch nick: parent
499
timestamp: Tue 2005-11-22 00:00:02 +0000
615
528
wt.branch, log.LongLogFormatter,
616
529
formatter_kwargs=dict(levels=0),
617
show_log_kwargs=dict(verbose=True),
530
show_log_kwargs=dict(verbose=True))
620
532
def test_trailing_newlines(self):
621
533
wt = self.make_branch_and_tree('.')
622
b = make_commits_with_trailing_newlines(wt)
534
b = self.make_commits_with_trailing_newlines(wt)
623
535
self.assertFormatterResult("""\
624
536
------------------------------------------------------------
626
538
committer: Joe Foo <joe@foo.com>
627
539
branch nick: test
628
timestamp: Mon 2005-11-21 09:32:56 -0600
540
timestamp: Tue 2005-11-22 00:00:02 +0000
630
542
single line with trailing newline
631
543
------------------------------------------------------------
633
author: Joe Bar <joe@bar.com>
634
545
committer: Joe Foo <joe@foo.com>
635
546
branch nick: test
636
timestamp: Mon 2005-11-21 09:27:22 -0600
547
timestamp: Tue 2005-11-22 00:00:01 +0000
775
686
wt = self.make_branch_and_tree('parent')
776
687
self.build_tree(['parent/f1', 'parent/f2'])
777
688
wt.add(['f1','f2'])
778
wt.commit('first post')
689
self.wt_commit(wt, 'first post')
779
690
child_wt = wt.bzrdir.sprout('child').open_workingtree()
780
691
os.unlink('child/f1')
781
692
self.build_tree_contents([('child/f2', 'hello\n')])
782
child_wt.commit('removed f1 and modified f2')
693
self.wt_commit(child_wt, 'removed f1 and modified f2')
783
694
wt.merge_from_branch(child_wt.branch)
784
wt.commit('merge branch 1')
695
self.wt_commit(wt, 'merge branch 1')
785
696
self.assertFormatterResult("""\
786
697
------------------------------------------------------------
788
committer: Lorem Ipsum <test@example.com>
699
committer: Joe Foo <joe@foo.com>
789
700
branch nick: parent
701
timestamp: Tue 2005-11-22 00:00:02 +0000
808
719
wt.branch, log.LongLogFormatter,
809
720
formatter_kwargs=dict(levels=1),
810
show_log_kwargs=dict(verbose=True),
721
show_log_kwargs=dict(verbose=True))
813
723
def test_long_trailing_newlines(self):
814
724
wt = self.make_branch_and_tree('.')
815
b = make_commits_with_trailing_newlines(wt)
725
b = self.make_commits_with_trailing_newlines(wt)
816
726
self.assertFormatterResult("""\
817
727
------------------------------------------------------------
819
729
committer: Joe Foo <joe@foo.com>
820
730
branch nick: test
821
timestamp: Mon 2005-11-21 09:32:56 -0600
731
timestamp: Tue 2005-11-22 00:00:02 +0000
823
733
single line with trailing newline
824
734
------------------------------------------------------------
826
author: Joe Bar <joe@bar.com>
827
736
committer: Joe Foo <joe@foo.com>
828
737
branch nick: test
829
timestamp: Mon 2005-11-21 09:27:22 -0600
738
timestamp: Tue 2005-11-22 00:00:01 +0000
897
806
committer='Line-Log-Formatter Tester <test@line.log>',
899
808
self.assertFormatterResult("""\
900
1: Line-Log-Formatte... 2005-11-23 add a
809
1: Line-Log-Formatte... 2005-11-22 add a
902
811
wt.branch, log.LineLogFormatter)
904
813
def test_trailing_newlines(self):
905
814
wt = self.make_branch_and_tree('.')
906
b = make_commits_with_trailing_newlines(wt)
815
b = self.make_commits_with_trailing_newlines(wt)
907
816
self.assertFormatterResult("""\
908
3: Joe Foo 2005-11-21 single line with trailing newline
909
2: Joe Bar 2005-11-21 multiline
910
1: Joe Foo 2005-11-21 simple log message
817
3: Joe Foo 2005-11-22 single line with trailing newline
818
2: Joe Foo 2005-11-22 multiline
819
1: Joe Foo 2005-11-22 simple log message
912
821
b, log.LineLogFormatter)
942
851
committer='Line-Log-Formatter Tester <test@line.log>',
944
853
self.assertFormatterResult("""\
945
1: Line-Log-Formatte... 2005-11-23 add a
854
1: Line-Log-Formatte... 2005-11-22 add a
947
856
wt.branch, log.LineLogFormatter)
949
858
def test_line_merge_revs_log_single_merge_revision(self):
950
wt = self.make_branch_and_memory_tree('.')
952
self.addCleanup(wt.unlock)
954
wt.commit('rev-1', rev_id='rev-1',
955
timestamp=1132586655, timezone=36000,
956
committer='Joe Foo <joe@foo.com>')
957
wt.commit('rev-merged', rev_id='rev-2a',
958
timestamp=1132586700, timezone=36000,
959
committer='Joe Foo <joe@foo.com>')
960
wt.set_parent_ids(['rev-1', 'rev-2a'])
961
wt.branch.set_last_revision_info(1, 'rev-1')
962
wt.commit('rev-2', rev_id='rev-2b',
963
timestamp=1132586800, timezone=36000,
964
committer='Joe Foo <joe@foo.com>')
859
wt = self._prepare_tree_with_merges()
965
860
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
966
861
rev = revspec.in_history(wt.branch)
967
862
self.assertFormatterResult("""\
972
867
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
974
869
def test_line_merge_revs_log_with_merges(self):
975
wt = self.make_branch_and_memory_tree('.')
977
self.addCleanup(wt.unlock)
979
wt.commit('rev-1', rev_id='rev-1',
980
timestamp=1132586655, timezone=36000,
981
committer='Joe Foo <joe@foo.com>')
982
wt.commit('rev-merged', rev_id='rev-2a',
983
timestamp=1132586700, timezone=36000,
984
committer='Joe Foo <joe@foo.com>')
985
wt.set_parent_ids(['rev-1', 'rev-2a'])
986
wt.branch.set_last_revision_info(1, 'rev-1')
987
wt.commit('rev-2', rev_id='rev-2b',
988
timestamp=1132586800, timezone=36000,
989
committer='Joe Foo <joe@foo.com>')
870
wt = self._prepare_tree_with_merges()
990
871
self.assertFormatterResult("""\
991
872
2: Joe Foo 2005-11-22 [merge] rev-2
992
873
1.1.1: Joe Foo 2005-11-22 rev-merged
996
877
formatter_kwargs=dict(levels=0))
999
class TestGetViewRevisions(tests.TestCaseWithTransport):
880
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
882
def test_gnu_changelog(self):
883
wt = self.make_standard_commit('nicky', authors=[])
884
self.assertFormatterResult('''\
885
2005-11-22 Lorem Ipsum <test@example.com>
890
wt.branch, log.GnuChangelogLogFormatter)
892
def test_with_authors(self):
893
wt = self.make_standard_commit('nicky',
894
authors=['Fooa Fooz <foo@example.com>',
895
'Bari Baro <bar@example.com>'])
896
self.assertFormatterResult('''\
897
2005-11-22 Fooa Fooz <foo@example.com>
902
wt.branch, log.GnuChangelogLogFormatter)
904
def test_verbose(self):
905
wt = self.make_standard_commit('nicky')
906
self.assertFormatterResult('''\
907
2005-11-22 John Doe <jdoe@example.com>
914
wt.branch, log.GnuChangelogLogFormatter,
915
show_log_kwargs=dict(verbose=True))
917
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
919
def _get_view_revisions(self, *args, **kwargs):
920
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
921
log.get_view_revisions, *args, **kwargs)
1001
923
def make_tree_with_commits(self):
1002
924
"""Create a tree with well-known revision ids"""
1003
925
wt = self.make_branch_and_tree('tree1')
1004
wt.commit('commit one', rev_id='1')
1005
wt.commit('commit two', rev_id='2')
1006
wt.commit('commit three', rev_id='3')
926
self.wt_commit(wt, 'commit one', rev_id='1')
927
self.wt_commit(wt, 'commit two', rev_id='2')
928
self.wt_commit(wt, 'commit three', rev_id='3')
1007
929
mainline_revs = [None, '1', '2', '3']
1008
930
rev_nos = {'1': 1, '2': 2, '3': 3}
1009
931
return mainline_revs, rev_nos, wt
1012
934
"""Create a tree with well-known revision ids and a merge"""
1013
935
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1014
936
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1015
tree2.commit('four-a', rev_id='4a')
937
self.wt_commit(tree2, 'four-a', rev_id='4a')
1016
938
wt.merge_from_branch(tree2.branch)
1017
wt.commit('four-b', rev_id='4b')
939
self.wt_commit(wt, 'four-b', rev_id='4b')
1018
940
mainline_revs.append('4b')
1019
941
rev_nos['4b'] = 4
1068
990
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1070
992
self.addCleanup(wt.unlock)
1071
revisions = list(log.get_view_revisions(
993
revisions = list(self._get_view_revisions(
1072
994
mainline_revs, rev_nos, wt.branch, 'forward'))
1073
995
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1075
revisions2 = list(log.get_view_revisions(
997
revisions2 = list(self._get_view_revisions(
1076
998
mainline_revs, rev_nos, wt.branch, 'forward',
1077
999
include_merges=False))
1078
1000
self.assertEqual(revisions, revisions2)
1082
1004
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1084
1006
self.addCleanup(wt.unlock)
1085
revisions = list(log.get_view_revisions(
1007
revisions = list(self._get_view_revisions(
1086
1008
mainline_revs, rev_nos, wt.branch, 'reverse'))
1087
1009
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1089
revisions2 = list(log.get_view_revisions(
1011
revisions2 = list(self._get_view_revisions(
1090
1012
mainline_revs, rev_nos, wt.branch, 'reverse',
1091
1013
include_merges=False))
1092
1014
self.assertEqual(revisions, revisions2)
1096
1018
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1098
1020
self.addCleanup(wt.unlock)
1099
revisions = list(log.get_view_revisions(
1021
revisions = list(self._get_view_revisions(
1100
1022
mainline_revs, rev_nos, wt.branch, 'forward'))
1101
1023
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1102
1024
('4b', '4', 0), ('4a', '3.1.1', 1)],
1104
revisions = list(log.get_view_revisions(
1026
revisions = list(self._get_view_revisions(
1105
1027
mainline_revs, rev_nos, wt.branch, 'forward',
1106
1028
include_merges=False))
1107
1029
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1113
1035
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1115
1037
self.addCleanup(wt.unlock)
1116
revisions = list(log.get_view_revisions(
1038
revisions = list(self._get_view_revisions(
1117
1039
mainline_revs, rev_nos, wt.branch, 'reverse'))
1118
1040
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1119
1041
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1121
revisions = list(log.get_view_revisions(
1043
revisions = list(self._get_view_revisions(
1122
1044
mainline_revs, rev_nos, wt.branch, 'reverse',
1123
1045
include_merges=False))
1124
1046
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1130
1052
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1132
1054
self.addCleanup(b.unlock)
1133
revisions = list(log.get_view_revisions(
1055
revisions = list(self._get_view_revisions(
1134
1056
mainline_revs, rev_nos, b, 'forward'))
1135
1057
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1136
1058
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1137
1059
('4a', '2.2.2', 1)]
1138
1060
self.assertEqual(expected, revisions)
1139
revisions = list(log.get_view_revisions(
1061
revisions = list(self._get_view_revisions(
1140
1062
mainline_revs, rev_nos, b, 'forward',
1141
1063
include_merges=False))
1142
1064
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1143
1065
('4b', '4', 0)],
1147
1068
def test_file_id_for_range(self):
1148
1069
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1167
1090
rev_3a = rev_from_rev_id('3a', b)
1168
1091
rev_4b = rev_from_rev_id('4b', b)
1169
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1092
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1093
('3a', '2.1.1', 2)],
1170
1094
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1171
1095
# Note: 3c still appears before 3a here because of depth-based sorting
1172
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1096
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1097
('3a', '2.1.1', 2)],
1173
1098
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1176
1101
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1103
def get_view_revisions(self, *args):
1104
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1105
log.get_view_revisions, *args)
1178
1107
def create_tree_with_single_merge(self):
1179
1108
"""Create a branch with a moderate layout.
1278
1212
mainline = tree.branch.revision_history()
1279
1213
mainline.insert(0, None)
1280
1214
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1281
view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1215
view_revs_iter = self.get_view_revisions(
1216
mainline, revnos, tree.branch, 'reverse', True)
1283
1217
actual_revs = log._filter_revisions_touching_file_id(
1286
list(view_revs_iter))
1218
tree.branch, file_id, list(view_revs_iter))
1287
1219
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1289
1221
def test_file_id_f1(self):
1342
1274
class TestLogFormatter(tests.TestCase):
1277
super(TestLogFormatter, self).setUp()
1278
self.rev = revision.Revision('a-id')
1279
self.lf = log.LogFormatter(None)
1344
1281
def test_short_committer(self):
1345
rev = revision.Revision('a-id')
1346
rev.committer = 'John Doe <jdoe@example.com>'
1347
lf = log.LogFormatter(None)
1348
self.assertEqual('John Doe', lf.short_committer(rev))
1349
rev.committer = 'John Smith <jsmith@example.com>'
1350
self.assertEqual('John Smith', lf.short_committer(rev))
1351
rev.committer = 'John Smith'
1352
self.assertEqual('John Smith', lf.short_committer(rev))
1353
rev.committer = 'jsmith@example.com'
1354
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1355
rev.committer = '<jsmith@example.com>'
1356
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1357
rev.committer = 'John Smith jsmith@example.com'
1358
self.assertEqual('John Smith', lf.short_committer(rev))
1282
def assertCommitter(expected, committer):
1283
self.rev.committer = committer
1284
self.assertEqual(expected, self.lf.short_committer(self.rev))
1286
assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1287
assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1288
assertCommitter('John Smith', 'John Smith')
1289
assertCommitter('jsmith@example.com', 'jsmith@example.com')
1290
assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1291
assertCommitter('John Smith', 'John Smith jsmith@example.com')
1360
1293
def test_short_author(self):
1361
rev = revision.Revision('a-id')
1362
rev.committer = 'John Doe <jdoe@example.com>'
1363
lf = log.LogFormatter(None)
1364
self.assertEqual('John Doe', lf.short_author(rev))
1365
rev.properties['author'] = 'John Smith <jsmith@example.com>'
1366
self.assertEqual('John Smith', lf.short_author(rev))
1367
rev.properties['author'] = 'John Smith'
1368
self.assertEqual('John Smith', lf.short_author(rev))
1369
rev.properties['author'] = 'jsmith@example.com'
1370
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1371
rev.properties['author'] = '<jsmith@example.com>'
1372
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1373
rev.properties['author'] = 'John Smith jsmith@example.com'
1374
self.assertEqual('John Smith', lf.short_author(rev))
1375
del rev.properties['author']
1376
rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1377
'Jane Rey <jrey@example.com>')
1378
self.assertEqual('John Smith', lf.short_author(rev))
1294
def assertAuthor(expected, author):
1295
self.rev.properties['author'] = author
1296
self.assertEqual(expected, self.lf.short_author(self.rev))
1298
assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1299
assertAuthor('John Smith', 'John Smith')
1300
assertAuthor('jsmith@example.com', 'jsmith@example.com')
1301
assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1302
assertAuthor('John Smith', 'John Smith jsmith@example.com')
1304
def test_short_author_from_committer(self):
1305
self.rev.committer = 'John Doe <jdoe@example.com>'
1306
self.assertEqual('John Doe', self.lf.short_author(self.rev))
1308
def test_short_author_from_authors(self):
1309
self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1310
'Jane Rey <jrey@example.com>')
1311
self.assertEqual('John Smith', self.lf.short_author(self.rev))
1381
1314
class TestReverseByDepth(tests.TestCase):
1543
1476
tree = self.make_branch_and_tree(u'.')
1544
1477
self.build_tree(['a', 'b'])
1546
tree.commit('simple log message', rev_id='a1',
1547
timestamp=1132586655.459960938, timezone=-6*3600,
1548
committer='Joe Foo <joe@foo.com>',
1549
revprops={'bugs': 'test://bug/id fixed'})
1479
self.wt_commit(tree, 'simple log message', rev_id='a1',
1480
revprops={'bugs': 'test://bug/id fixed'})
1551
tree.commit('multiline\nlog\nmessage\n', rev_id='a2',
1552
timestamp=1132586842.411175966, timezone=-6*3600,
1553
committer='Joe Foo <joe@foo.com>',
1554
authors=['Joe Bar <joe@bar.com>'],
1555
revprops={'bugs': 'test://bug/id fixed\n'
1556
'test://bug/2 fixed'})
1482
self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1483
authors=['Joe Bar <joe@bar.com>'],
1484
revprops={'bugs': 'test://bug/id fixed\n'
1485
'test://bug/2 fixed'})
1601
1530
def test_wrong_bugs_property(self):
1602
1531
tree = self.make_branch_and_tree(u'.')
1603
1532
self.build_tree(['foo'])
1604
tree.commit('simple log message', rev_id='a1',
1605
timestamp=1132586655.459960938, timezone=-6*3600,
1606
committer='Joe Foo <joe@foo.com>',
1607
revprops={'bugs': 'test://bug/id invalid_value'})
1533
self.wt_commit(tree, 'simple log message', rev_id='a1',
1534
revprops={'bugs': 'test://bug/id invalid_value'})
1608
1535
self.assertFormatterResult("""\
1609
1 Joe Foo\t2005-11-21
1536
1 Joe Foo\t2005-11-22
1610
1537
simple log message