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):
30
class TestCaseForLogFormatter(tests.TestCaseWithTransport):
53
33
super(TestCaseForLogFormatter, self).setUp()
78
62
self.build_tree(['a'])
80
64
wt.branch.nick = branch_nick
66
kwargs.setdefault('message', 'add a')
67
kwargs.setdefault('timestamp', 1132711707)
68
kwargs.setdefault('timezone', 36000)
81
69
kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
82
70
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')
101
74
def _prepare_tree_with_merges(self, with_tags=False):
102
75
wt = self.make_branch_and_memory_tree('.')
104
77
self.addCleanup(wt.unlock)
106
self.wt_commit(wt, 'rev-1', rev_id='rev-1')
107
self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
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>')
108
85
wt.set_parent_ids(['rev-1', 'rev-2a'])
109
86
wt.branch.set_last_revision_info(1, 'rev-1')
110
self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
87
wt.commit('rev-2', rev_id='rev-2b',
88
timestamp=1132586800, timezone=36000,
89
committer='Joe Foo <joe@foo.com>')
112
91
branch = wt.branch
113
92
branch.tags.set_tag('v0.2', 'rev-2b')
114
self.wt_commit(wt, 'rev-3', rev_id='rev-3')
93
wt.commit('rev-3', rev_id='rev-3',
94
timestamp=1132586900, timezone=36000,
95
committer='Jane Foo <jane@foo.com>')
115
96
branch.tags.set_tag('v1.0rc1', 'rev-3')
116
97
branch.tags.set_tag('v1.0', 'rev-3')
119
103
class LogCatcher(log.LogFormatter):
120
104
"""Pull log messages into a list rather than displaying them.
280
260
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)
283
304
class TestShortLogFormatter(TestCaseForLogFormatter):
285
306
def test_trailing_newlines(self):
286
307
wt = self.make_branch_and_tree('.')
287
b = self.make_commits_with_trailing_newlines(wt)
308
b = make_commits_with_trailing_newlines(wt)
288
309
self.assertFormatterResult("""\
289
3 Joe Foo\t2005-11-22
310
3 Joe Foo\t2005-11-21
290
311
single line with trailing newline
292
2 Joe Foo\t2005-11-22
313
2 Joe Bar\t2005-11-21
297
1 Joe Foo\t2005-11-22
318
1 Joe Foo\t2005-11-21
298
319
simple log message
327
348
formatter_kwargs=dict(show_advice=True))
329
350
def test_short_log_with_merges_and_range(self):
330
wt = self._prepare_tree_with_merges()
331
self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
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>')
332
369
wt.branch.set_last_revision_info(2, 'rev-2b')
333
370
wt.set_parent_ids(['rev-2b', 'rev-3a'])
334
self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
371
wt.commit('rev-3b', rev_id='rev-3b',
372
timestamp=1132586800, timezone=36000,
373
committer='Joe Foo <joe@foo.com>')
335
374
self.assertFormatterResult("""\
336
375
3 Joe Foo\t2005-11-22 [merge]
339
378
2 Joe Foo\t2005-11-22 [merge]
343
382
wt.branch, log.ShortLogFormatter,
359
398
wt.branch, log.ShortLogFormatter)
361
400
def test_short_log_single_merge_revision(self):
362
wt = self._prepare_tree_with_merges()
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>')
363
416
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
364
417
rev = revspec.in_history(wt.branch)
365
418
self.assertFormatterResult("""\
374
427
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
376
429
def test_short_merge_revs_log_with_merges(self):
377
wt = self._prepare_tree_with_merges()
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>')
378
445
# Note that the 1.1.1 indenting is in fact correct given that
379
446
# the revision numbers are right justified within 5 characters
380
447
# for mainline revnos and 9 characters for dotted revnos.
393
460
formatter_kwargs=dict(levels=0))
395
462
def test_short_merge_revs_log_single_merge_revision(self):
396
wt = self._prepare_tree_with_merges()
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>')
397
478
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
398
479
rev = revspec.in_history(wt.branch)
399
480
self.assertFormatterResult("""\
431
512
def test_merges_are_indented_by_level(self):
432
513
wt = self.make_branch_and_tree('parent')
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')
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')
442
526
self.assertFormatterResult("""\
443
527
------------------------------------------------------------
445
committer: Joe Foo <joe@foo.com>
529
committer: Lorem Ipsum <test@example.com>
446
530
branch nick: parent
447
timestamp: Tue 2005-11-22 00:00:04 +0000
450
534
------------------------------------------------------------
451
535
revno: 1.1.2 [merge]
452
committer: Joe Foo <joe@foo.com>
536
committer: Lorem Ipsum <test@example.com>
453
537
branch nick: child
454
timestamp: Tue 2005-11-22 00:00:03 +0000
457
541
------------------------------------------------------------
459
committer: Joe Foo <joe@foo.com>
543
committer: Lorem Ipsum <test@example.com>
460
544
branch nick: smallerchild
461
timestamp: Tue 2005-11-22 00:00:02 +0000
464
548
------------------------------------------------------------
466
committer: Joe Foo <joe@foo.com>
550
committer: Lorem Ipsum <test@example.com>
467
551
branch nick: child
468
timestamp: Tue 2005-11-22 00:00:01 +0000
471
555
------------------------------------------------------------
473
committer: Joe Foo <joe@foo.com>
557
committer: Lorem Ipsum <test@example.com>
474
558
branch nick: parent
475
timestamp: Tue 2005-11-22 00:00:00 +0000
479
563
wt.branch, log.LongLogFormatter,
480
564
formatter_kwargs=dict(levels=0),
481
show_log_kwargs=dict(verbose=True))
565
show_log_kwargs=dict(verbose=True),
483
568
def test_verbose_merge_revisions_contain_deltas(self):
484
569
wt = self.make_branch_and_tree('parent')
485
570
self.build_tree(['parent/f1', 'parent/f2'])
486
571
wt.add(['f1','f2'])
487
self.wt_commit(wt, 'first post')
488
child_wt = wt.bzrdir.sprout('child').open_workingtree()
572
wt.commit('first post')
573
self.run_bzr('branch parent child')
489
574
os.unlink('child/f1')
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')
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')
494
581
self.assertFormatterResult("""\
495
582
------------------------------------------------------------
497
committer: Joe Foo <joe@foo.com>
584
committer: Lorem Ipsum <test@example.com>
498
585
branch nick: parent
499
timestamp: Tue 2005-11-22 00:00:02 +0000
528
615
wt.branch, log.LongLogFormatter,
529
616
formatter_kwargs=dict(levels=0),
530
show_log_kwargs=dict(verbose=True))
617
show_log_kwargs=dict(verbose=True),
532
620
def test_trailing_newlines(self):
533
621
wt = self.make_branch_and_tree('.')
534
b = self.make_commits_with_trailing_newlines(wt)
622
b = make_commits_with_trailing_newlines(wt)
535
623
self.assertFormatterResult("""\
536
624
------------------------------------------------------------
538
626
committer: Joe Foo <joe@foo.com>
539
627
branch nick: test
540
timestamp: Tue 2005-11-22 00:00:02 +0000
628
timestamp: Mon 2005-11-21 09:32:56 -0600
542
630
single line with trailing newline
543
631
------------------------------------------------------------
633
author: Joe Bar <joe@bar.com>
545
634
committer: Joe Foo <joe@foo.com>
546
635
branch nick: test
547
timestamp: Tue 2005-11-22 00:00:01 +0000
636
timestamp: Mon 2005-11-21 09:27:22 -0600
686
775
wt = self.make_branch_and_tree('parent')
687
776
self.build_tree(['parent/f1', 'parent/f2'])
688
777
wt.add(['f1','f2'])
689
self.wt_commit(wt, 'first post')
778
wt.commit('first post')
690
779
child_wt = wt.bzrdir.sprout('child').open_workingtree()
691
780
os.unlink('child/f1')
692
781
self.build_tree_contents([('child/f2', 'hello\n')])
693
self.wt_commit(child_wt, 'removed f1 and modified f2')
782
child_wt.commit('removed f1 and modified f2')
694
783
wt.merge_from_branch(child_wt.branch)
695
self.wt_commit(wt, 'merge branch 1')
784
wt.commit('merge branch 1')
696
785
self.assertFormatterResult("""\
697
786
------------------------------------------------------------
699
committer: Joe Foo <joe@foo.com>
788
committer: Lorem Ipsum <test@example.com>
700
789
branch nick: parent
701
timestamp: Tue 2005-11-22 00:00:02 +0000
719
808
wt.branch, log.LongLogFormatter,
720
809
formatter_kwargs=dict(levels=1),
721
show_log_kwargs=dict(verbose=True))
810
show_log_kwargs=dict(verbose=True),
723
813
def test_long_trailing_newlines(self):
724
814
wt = self.make_branch_and_tree('.')
725
b = self.make_commits_with_trailing_newlines(wt)
815
b = make_commits_with_trailing_newlines(wt)
726
816
self.assertFormatterResult("""\
727
817
------------------------------------------------------------
729
819
committer: Joe Foo <joe@foo.com>
730
820
branch nick: test
731
timestamp: Tue 2005-11-22 00:00:02 +0000
821
timestamp: Mon 2005-11-21 09:32:56 -0600
733
823
single line with trailing newline
734
824
------------------------------------------------------------
826
author: Joe Bar <joe@bar.com>
736
827
committer: Joe Foo <joe@foo.com>
737
828
branch nick: test
738
timestamp: Tue 2005-11-22 00:00:01 +0000
829
timestamp: Mon 2005-11-21 09:27:22 -0600
806
897
committer='Line-Log-Formatter Tester <test@line.log>',
808
899
self.assertFormatterResult("""\
809
1: Line-Log-Formatte... 2005-11-22 add a
900
1: Line-Log-Formatte... 2005-11-23 add a
811
902
wt.branch, log.LineLogFormatter)
813
904
def test_trailing_newlines(self):
814
905
wt = self.make_branch_and_tree('.')
815
b = self.make_commits_with_trailing_newlines(wt)
906
b = make_commits_with_trailing_newlines(wt)
816
907
self.assertFormatterResult("""\
817
3: Joe Foo 2005-11-22 single line with trailing newline
818
2: Joe Foo 2005-11-22 multiline
819
1: Joe Foo 2005-11-22 simple log message
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
821
912
b, log.LineLogFormatter)
851
942
committer='Line-Log-Formatter Tester <test@line.log>',
853
944
self.assertFormatterResult("""\
854
1: Line-Log-Formatte... 2005-11-22 add a
945
1: Line-Log-Formatte... 2005-11-23 add a
856
947
wt.branch, log.LineLogFormatter)
858
949
def test_line_merge_revs_log_single_merge_revision(self):
859
wt = self._prepare_tree_with_merges()
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>')
860
965
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
861
966
rev = revspec.in_history(wt.branch)
862
967
self.assertFormatterResult("""\
867
972
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
869
974
def test_line_merge_revs_log_with_merges(self):
870
wt = self._prepare_tree_with_merges()
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>')
871
990
self.assertFormatterResult("""\
872
991
2: Joe Foo 2005-11-22 [merge] rev-2
873
992
1.1.1: Joe Foo 2005-11-22 rev-merged
877
996
formatter_kwargs=dict(levels=0))
880
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
882
def _get_view_revisions(self, *args, **kwargs):
883
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
884
log.get_view_revisions, *args, **kwargs)
999
class TestGetViewRevisions(tests.TestCaseWithTransport):
886
1001
def make_tree_with_commits(self):
887
1002
"""Create a tree with well-known revision ids"""
888
1003
wt = self.make_branch_and_tree('tree1')
889
self.wt_commit(wt, 'commit one', rev_id='1')
890
self.wt_commit(wt, 'commit two', rev_id='2')
891
self.wt_commit(wt, 'commit three', rev_id='3')
1004
wt.commit('commit one', rev_id='1')
1005
wt.commit('commit two', rev_id='2')
1006
wt.commit('commit three', rev_id='3')
892
1007
mainline_revs = [None, '1', '2', '3']
893
1008
rev_nos = {'1': 1, '2': 2, '3': 3}
894
1009
return mainline_revs, rev_nos, wt
897
1012
"""Create a tree with well-known revision ids and a merge"""
898
1013
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
899
1014
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
900
self.wt_commit(tree2, 'four-a', rev_id='4a')
1015
tree2.commit('four-a', rev_id='4a')
901
1016
wt.merge_from_branch(tree2.branch)
902
self.wt_commit(wt, 'four-b', rev_id='4b')
1017
wt.commit('four-b', rev_id='4b')
903
1018
mainline_revs.append('4b')
904
1019
rev_nos['4b'] = 4
953
1068
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
955
1070
self.addCleanup(wt.unlock)
956
revisions = list(self._get_view_revisions(
1071
revisions = list(log.get_view_revisions(
957
1072
mainline_revs, rev_nos, wt.branch, 'forward'))
958
1073
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
960
revisions2 = list(self._get_view_revisions(
1075
revisions2 = list(log.get_view_revisions(
961
1076
mainline_revs, rev_nos, wt.branch, 'forward',
962
1077
include_merges=False))
963
1078
self.assertEqual(revisions, revisions2)
967
1082
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
969
1084
self.addCleanup(wt.unlock)
970
revisions = list(self._get_view_revisions(
1085
revisions = list(log.get_view_revisions(
971
1086
mainline_revs, rev_nos, wt.branch, 'reverse'))
972
1087
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
974
revisions2 = list(self._get_view_revisions(
1089
revisions2 = list(log.get_view_revisions(
975
1090
mainline_revs, rev_nos, wt.branch, 'reverse',
976
1091
include_merges=False))
977
1092
self.assertEqual(revisions, revisions2)
981
1096
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
983
1098
self.addCleanup(wt.unlock)
984
revisions = list(self._get_view_revisions(
1099
revisions = list(log.get_view_revisions(
985
1100
mainline_revs, rev_nos, wt.branch, 'forward'))
986
1101
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
987
1102
('4b', '4', 0), ('4a', '3.1.1', 1)],
989
revisions = list(self._get_view_revisions(
1104
revisions = list(log.get_view_revisions(
990
1105
mainline_revs, rev_nos, wt.branch, 'forward',
991
1106
include_merges=False))
992
1107
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
998
1113
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1000
1115
self.addCleanup(wt.unlock)
1001
revisions = list(self._get_view_revisions(
1116
revisions = list(log.get_view_revisions(
1002
1117
mainline_revs, rev_nos, wt.branch, 'reverse'))
1003
1118
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1004
1119
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1006
revisions = list(self._get_view_revisions(
1121
revisions = list(log.get_view_revisions(
1007
1122
mainline_revs, rev_nos, wt.branch, 'reverse',
1008
1123
include_merges=False))
1009
1124
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1015
1130
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1017
1132
self.addCleanup(b.unlock)
1018
revisions = list(self._get_view_revisions(
1133
revisions = list(log.get_view_revisions(
1019
1134
mainline_revs, rev_nos, b, 'forward'))
1020
1135
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1021
1136
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1022
1137
('4a', '2.2.2', 1)]
1023
1138
self.assertEqual(expected, revisions)
1024
revisions = list(self._get_view_revisions(
1139
revisions = list(log.get_view_revisions(
1025
1140
mainline_revs, rev_nos, b, 'forward',
1026
1141
include_merges=False))
1027
1142
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1028
1143
('4b', '4', 0)],
1031
1147
def test_file_id_for_range(self):
1032
1148
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1053
1167
rev_3a = rev_from_rev_id('3a', b)
1054
1168
rev_4b = rev_from_rev_id('4b', b)
1055
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1056
('3a', '2.1.1', 2)],
1169
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1057
1170
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1058
1171
# Note: 3c still appears before 3a here because of depth-based sorting
1059
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1060
('3a', '2.1.1', 2)],
1172
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1061
1173
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1064
1176
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1066
def get_view_revisions(self, *args):
1067
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1068
log.get_view_revisions, *args)
1070
1178
def create_tree_with_single_merge(self):
1071
1179
"""Create a branch with a moderate layout.
1175
1278
mainline = tree.branch.revision_history()
1176
1279
mainline.insert(0, None)
1177
1280
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1178
view_revs_iter = self.get_view_revisions(
1179
mainline, revnos, tree.branch, 'reverse', True)
1281
view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1180
1283
actual_revs = log._filter_revisions_touching_file_id(
1181
tree.branch, file_id, list(view_revs_iter))
1286
list(view_revs_iter))
1182
1287
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1184
1289
def test_file_id_f1(self):
1237
1342
class TestLogFormatter(tests.TestCase):
1240
super(TestLogFormatter, self).setUp()
1241
self.rev = revision.Revision('a-id')
1242
self.lf = log.LogFormatter(None)
1244
1344
def test_short_committer(self):
1245
def assertCommitter(expected, committer):
1246
self.rev.committer = committer
1247
self.assertEqual(expected, self.lf.short_committer(self.rev))
1249
assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1250
assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1251
assertCommitter('John Smith', 'John Smith')
1252
assertCommitter('jsmith@example.com', 'jsmith@example.com')
1253
assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1254
assertCommitter('John Smith', 'John Smith jsmith@example.com')
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))
1256
1360
def test_short_author(self):
1257
def assertAuthor(expected, author):
1258
self.rev.properties['author'] = author
1259
self.assertEqual(expected, self.lf.short_author(self.rev))
1261
assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1262
assertAuthor('John Smith', 'John Smith')
1263
assertAuthor('jsmith@example.com', 'jsmith@example.com')
1264
assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1265
assertAuthor('John Smith', 'John Smith jsmith@example.com')
1267
def test_short_author_from_committer(self):
1268
self.rev.committer = 'John Doe <jdoe@example.com>'
1269
self.assertEqual('John Doe', self.lf.short_author(self.rev))
1271
def test_short_author_from_authors(self):
1272
self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1273
'Jane Rey <jrey@example.com>')
1274
self.assertEqual('John Smith', self.lf.short_author(self.rev))
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))
1277
1381
class TestReverseByDepth(tests.TestCase):
1439
1543
tree = self.make_branch_and_tree(u'.')
1440
1544
self.build_tree(['a', 'b'])
1442
self.wt_commit(tree, 'simple log message', rev_id='a1',
1443
revprops={'bugs': 'test://bug/id fixed'})
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'})
1445
self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1446
authors=['Joe Bar <joe@bar.com>'],
1447
revprops={'bugs': 'test://bug/id fixed\n'
1448
'test://bug/2 fixed'})
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'})
1493
1601
def test_wrong_bugs_property(self):
1494
1602
tree = self.make_branch_and_tree(u'.')
1495
1603
self.build_tree(['foo'])
1496
self.wt_commit(tree, 'simple log message', rev_id='a1',
1497
revprops={'bugs': 'test://bug/id invalid_value'})
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'})
1498
1608
self.assertFormatterResult("""\
1499
1 Joe Foo\t2005-11-22
1609
1 Joe Foo\t2005-11-21
1500
1610
simple log message