1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
from cStringIO import StringIO
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):
53
super(TestCaseForLogFormatter, self).setUp()
54
# keep a reference to the "current" custom prop. handler registry
55
self.properties_handler_registry = log.properties_handler_registry
56
# Use a clean registry for log
57
log.properties_handler_registry = registry.Registry()
60
log.properties_handler_registry = self.properties_handler_registry
61
self.addCleanup(restore)
63
def assertFormatterResult(self, result, branch, formatter_class,
64
formatter_kwargs=None, show_log_kwargs=None):
65
logfile = self.make_utf8_encoded_stringio()
66
if formatter_kwargs is None:
68
formatter = formatter_class(to_file=logfile, **formatter_kwargs)
69
if show_log_kwargs is None:
71
log.show_log(branch, formatter, **show_log_kwargs)
72
self.assertEqualDiff(result, logfile.getvalue())
74
def make_standard_commit(self, branch_nick, **kwargs):
75
wt = self.make_branch_and_tree('.')
77
self.addCleanup(wt.unlock)
78
self.build_tree(['a'])
80
wt.branch.nick = branch_nick
81
kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
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')
101
def _prepare_tree_with_merges(self, with_tags=False):
102
wt = self.make_branch_and_memory_tree('.')
104
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')
108
wt.set_parent_ids(['rev-1', 'rev-2a'])
109
wt.branch.set_last_revision_info(1, 'rev-1')
110
self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
113
branch.tags.set_tag('v0.2', 'rev-2b')
114
self.wt_commit(wt, 'rev-3', rev_id='rev-3')
115
branch.tags.set_tag('v1.0rc1', 'rev-3')
116
branch.tags.set_tag('v1.0', 'rev-3')
119
class LogCatcher(log.LogFormatter):
120
"""Pull log messages into a list rather than displaying them.
122
To simplify testing we save logged revisions here rather than actually
123
formatting anything, so that we can precisely check the result without
124
being dependent on the formatting.
20
from bzrlib.selftest import BzrTestBase, TestCaseInTempDir
21
from bzrlib.log import LogFormatter, show_log, LongLogFormatter
22
from bzrlib.branch import Branch
24
class _LogEntry(object):
25
# should probably move into bzrlib.log?
29
class LogCatcher(LogFormatter):
30
"""Pull log messages into list rather than displaying them.
32
For ease of testing we save log messages here rather than actually
33
formatting them, so that we can precisely check the result without
34
being too dependent on the exact formatting.
36
We should also test the LogFormatter.
127
supports_merge_revisions = True
128
supports_delta = True
132
def __init__(self, *args, **kwargs):
133
kwargs.update(dict(to_file=None))
134
super(LogCatcher, self).__init__(*args, **kwargs)
137
def log_revision(self, revision):
138
self.revisions.append(revision)
141
class TestShowLog(tests.TestCaseWithTransport):
39
super(LogCatcher, self).__init__(to_file=None)
43
def show(self, revno, rev, delta):
51
class SimpleLogTest(TestCaseInTempDir):
143
53
def checkDelta(self, delta, **kw):
144
"""Check the filenames touched by a delta are as expected.
146
Caller only have to pass in the list of files for each part, all
147
unspecified parts are considered empty (and checked as such).
54
"""Check the filenames touched by a delta are as expected."""
149
55
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
150
# By default we expect an empty list
151
56
expected = kw.get(n, [])
58
# tests are written with unix paths; fix them up for windows
60
expected = [x.replace('/', os.sep) for x in expected]
152
62
# strip out only the path components
153
63
got = [x[0] for x in getattr(delta, n)]
154
self.assertEqual(expected, got)
156
def assertInvalidRevisonNumber(self, br, start, end):
158
self.assertRaises(errors.InvalidRevisionNumber,
159
log.show_log, br, lf,
160
start_revision=start, end_revision=end)
162
def test_cur_revno(self):
163
wt = self.make_branch_and_tree('.')
167
wt.commit('empty commit')
168
log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
170
# Since there is a single revision in the branch all the combinations
172
self.assertInvalidRevisonNumber(b, 2, 1)
173
self.assertInvalidRevisonNumber(b, 1, 2)
174
self.assertInvalidRevisonNumber(b, 0, 2)
175
self.assertInvalidRevisonNumber(b, 1, 0)
176
self.assertInvalidRevisonNumber(b, -1, 1)
177
self.assertInvalidRevisonNumber(b, 1, -1)
179
def test_empty_branch(self):
180
wt = self.make_branch_and_tree('.')
183
log.show_log(wt.branch, lf)
64
self.assertEquals(expected, got)
66
def test_simple_log(self):
67
eq = self.assertEquals
69
b = Branch('.', init=True)
185
self.assertEqual([], lf.revisions)
187
def test_empty_commit(self):
188
wt = self.make_branch_and_tree('.')
190
wt.commit('empty commit')
77
b.commit('empty commit')
192
log.show_log(wt.branch, lf, verbose=True)
194
self.assertEqual(1, len(revs))
195
self.assertEqual('1', revs[0].revno)
196
self.assertEqual('empty commit', revs[0].rev.message)
197
self.checkDelta(revs[0].delta)
199
def test_simple_commit(self):
200
wt = self.make_branch_and_tree('.')
201
wt.commit('empty commit')
79
show_log(b, lf, verbose=True)
81
eq(lf.logs[0].revno, 1)
82
eq(lf.logs[0].rev.message, 'empty commit')
84
self.log('log delta: %r' % d)
202
88
self.build_tree(['hello'])
204
wt.commit('add one file',
205
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
206
u'<test@example.com>')
90
b.commit('add one file')
93
# log using regular thing
94
show_log(b, LongLogFormatter(lf))
96
for l in lf.readlines():
99
# get log as data structure
207
100
lf = LogCatcher()
208
log.show_log(wt.branch, lf, verbose=True)
209
self.assertEqual(2, len(lf.revisions))
101
show_log(b, lf, verbose=True)
103
self.log('log entries:')
104
for logentry in lf.logs:
105
self.log('%4d %s' % (logentry.revno, logentry.rev.message))
210
107
# first one is most recent
211
log_entry = lf.revisions[0]
212
self.assertEqual('2', log_entry.revno)
213
self.assertEqual('add one file', log_entry.rev.message)
214
self.checkDelta(log_entry.delta, added=['hello'])
216
def test_commit_message_with_control_chars(self):
217
wt = self.make_branch_and_tree('.')
218
msg = u"All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
219
msg = msg.replace(u'\r', u'\n')
222
log.show_log(wt.branch, lf, verbose=True)
223
committed_msg = lf.revisions[0].rev.message
224
if wt.branch.repository._serializer.squashes_xml_invalid_characters:
225
self.assertNotEqual(msg, committed_msg)
226
self.assertTrue(len(committed_msg) > len(msg))
228
self.assertEqual(msg, committed_msg)
230
def test_commit_message_without_control_chars(self):
231
wt = self.make_branch_and_tree('.')
232
# escaped. As ElementTree apparently does some kind of
233
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
234
# included in the test commit message, even though they are
235
# valid XML 1.0 characters.
236
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
239
log.show_log(wt.branch, lf, verbose=True)
240
committed_msg = lf.revisions[0].rev.message
241
self.assertEqual(msg, committed_msg)
243
def test_deltas_in_merge_revisions(self):
244
"""Check deltas created for both mainline and merge revisions"""
245
wt = self.make_branch_and_tree('parent')
246
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
249
wt.commit(message='add file1 and file2')
250
self.run_bzr('branch parent child')
251
os.unlink('child/file1')
252
file('child/file2', 'wb').write('hello\n')
253
self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
256
self.run_bzr('merge ../child')
257
wt.commit('merge child branch')
261
lf.supports_merge_revisions = True
262
log.show_log(b, lf, verbose=True)
265
self.assertEqual(3, len(revs))
268
self.assertEqual('2', logentry.revno)
269
self.assertEqual('merge child branch', logentry.rev.message)
270
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
273
self.assertEqual('1.1.1', logentry.revno)
274
self.assertEqual('remove file1 and modify file2', logentry.rev.message)
275
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
278
self.assertEqual('1', logentry.revno)
279
self.assertEqual('add file1 and file2', logentry.rev.message)
280
self.checkDelta(logentry.delta, added=['file1', 'file2'])
283
class TestShortLogFormatter(TestCaseForLogFormatter):
285
def test_trailing_newlines(self):
286
wt = self.make_branch_and_tree('.')
287
b = self.make_commits_with_trailing_newlines(wt)
288
self.assertFormatterResult("""\
289
3 Joe Foo\t2005-11-22
290
single line with trailing newline
292
2 Joe Foo\t2005-11-22
297
1 Joe Foo\t2005-11-22
301
b, log.ShortLogFormatter)
303
def test_short_log_with_merges(self):
304
wt = self._prepare_tree_with_merges()
305
self.assertFormatterResult("""\
306
2 Joe Foo\t2005-11-22 [merge]
309
1 Joe Foo\t2005-11-22
313
wt.branch, log.ShortLogFormatter)
315
def test_short_log_with_merges_and_advice(self):
316
wt = self._prepare_tree_with_merges()
317
self.assertFormatterResult("""\
318
2 Joe Foo\t2005-11-22 [merge]
321
1 Joe Foo\t2005-11-22
324
Use --include-merges or -n0 to see merged revisions.
326
wt.branch, log.ShortLogFormatter,
327
formatter_kwargs=dict(show_advice=True))
329
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')
332
wt.branch.set_last_revision_info(2, 'rev-2b')
333
wt.set_parent_ids(['rev-2b', 'rev-3a'])
334
self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
335
self.assertFormatterResult("""\
336
3 Joe Foo\t2005-11-22 [merge]
339
2 Joe Foo\t2005-11-22 [merge]
343
wt.branch, log.ShortLogFormatter,
344
show_log_kwargs=dict(start_revision=2, end_revision=3))
346
def test_short_log_with_tags(self):
347
wt = self._prepare_tree_with_merges(with_tags=True)
348
self.assertFormatterResult("""\
349
3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
352
2 Joe Foo\t2005-11-22 {v0.2} [merge]
355
1 Joe Foo\t2005-11-22
359
wt.branch, log.ShortLogFormatter)
361
def test_short_log_single_merge_revision(self):
362
wt = self._prepare_tree_with_merges()
363
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
364
rev = revspec.in_history(wt.branch)
365
self.assertFormatterResult("""\
366
1.1.1 Joe Foo\t2005-11-22
370
wt.branch, log.ShortLogFormatter,
371
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
376
def test_short_merge_revs_log_with_merges(self):
377
wt = self._prepare_tree_with_merges()
378
# Note that the 1.1.1 indenting is in fact correct given that
379
# the revision numbers are right justified within 5 characters
380
# for mainline revnos and 9 characters for dotted revnos.
381
self.assertFormatterResult("""\
382
2 Joe Foo\t2005-11-22 [merge]
385
1.1.1 Joe Foo\t2005-11-22
388
1 Joe Foo\t2005-11-22
392
wt.branch, log.ShortLogFormatter,
393
formatter_kwargs=dict(levels=0))
395
def test_short_merge_revs_log_single_merge_revision(self):
396
wt = self._prepare_tree_with_merges()
397
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
398
rev = revspec.in_history(wt.branch)
399
self.assertFormatterResult("""\
400
1.1.1 Joe Foo\t2005-11-22
404
wt.branch, log.ShortLogFormatter,
405
formatter_kwargs=dict(levels=0),
406
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
409
class TestLongLogFormatter(TestCaseForLogFormatter):
411
def test_verbose_log(self):
412
"""Verbose log includes changed files
416
wt = self.make_standard_commit('test_verbose_log', authors=[])
417
self.assertFormatterResult('''\
418
------------------------------------------------------------
420
committer: Lorem Ipsum <test@example.com>
421
branch nick: test_verbose_log
422
timestamp: Tue 2005-11-22 00:00:00 +0000
428
wt.branch, log.LongLogFormatter,
429
show_log_kwargs=dict(verbose=True))
431
def test_merges_are_indented_by_level(self):
432
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')
442
self.assertFormatterResult("""\
443
------------------------------------------------------------
445
committer: Joe Foo <joe@foo.com>
447
timestamp: Tue 2005-11-22 00:00:04 +0000
450
------------------------------------------------------------
452
committer: Joe Foo <joe@foo.com>
454
timestamp: Tue 2005-11-22 00:00:03 +0000
457
------------------------------------------------------------
459
committer: Joe Foo <joe@foo.com>
460
branch nick: smallerchild
461
timestamp: Tue 2005-11-22 00:00:02 +0000
464
------------------------------------------------------------
466
committer: Joe Foo <joe@foo.com>
468
timestamp: Tue 2005-11-22 00:00:01 +0000
471
------------------------------------------------------------
473
committer: Joe Foo <joe@foo.com>
475
timestamp: Tue 2005-11-22 00:00:00 +0000
479
wt.branch, log.LongLogFormatter,
480
formatter_kwargs=dict(levels=0),
481
show_log_kwargs=dict(verbose=True))
483
def test_verbose_merge_revisions_contain_deltas(self):
484
wt = self.make_branch_and_tree('parent')
485
self.build_tree(['parent/f1', 'parent/f2'])
487
self.wt_commit(wt, 'first post')
488
child_wt = wt.bzrdir.sprout('child').open_workingtree()
489
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')
494
self.assertFormatterResult("""\
495
------------------------------------------------------------
497
committer: Joe Foo <joe@foo.com>
499
timestamp: Tue 2005-11-22 00:00:02 +0000
506
------------------------------------------------------------
508
committer: Joe Foo <joe@foo.com>
510
timestamp: Tue 2005-11-22 00:00:01 +0000
512
removed f1 and modified f2
517
------------------------------------------------------------
519
committer: Joe Foo <joe@foo.com>
521
timestamp: Tue 2005-11-22 00:00:00 +0000
528
wt.branch, log.LongLogFormatter,
529
formatter_kwargs=dict(levels=0),
530
show_log_kwargs=dict(verbose=True))
532
def test_trailing_newlines(self):
533
wt = self.make_branch_and_tree('.')
534
b = self.make_commits_with_trailing_newlines(wt)
535
self.assertFormatterResult("""\
536
------------------------------------------------------------
538
committer: Joe Foo <joe@foo.com>
540
timestamp: Tue 2005-11-22 00:00:02 +0000
542
single line with trailing newline
543
------------------------------------------------------------
545
committer: Joe Foo <joe@foo.com>
547
timestamp: Tue 2005-11-22 00:00:01 +0000
552
------------------------------------------------------------
554
committer: Joe Foo <joe@foo.com>
556
timestamp: Tue 2005-11-22 00:00:00 +0000
560
b, log.LongLogFormatter)
562
def test_author_in_log(self):
563
"""Log includes the author name if it's set in
564
the revision properties
566
wt = self.make_standard_commit('test_author_log',
567
authors=['John Doe <jdoe@example.com>',
568
'Jane Rey <jrey@example.com>'])
569
self.assertFormatterResult("""\
570
------------------------------------------------------------
572
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
573
committer: Lorem Ipsum <test@example.com>
574
branch nick: test_author_log
575
timestamp: Tue 2005-11-22 00:00:00 +0000
579
wt.branch, log.LongLogFormatter)
581
def test_properties_in_log(self):
582
"""Log includes the custom properties returned by the registered
585
wt = self.make_standard_commit('test_properties_in_log')
586
def trivial_custom_prop_handler(revision):
587
return {'test_prop':'test_value'}
589
# Cleaned up in setUp()
590
log.properties_handler_registry.register(
591
'trivial_custom_prop_handler',
592
trivial_custom_prop_handler)
593
self.assertFormatterResult("""\
594
------------------------------------------------------------
596
test_prop: test_value
597
author: John Doe <jdoe@example.com>
598
committer: Lorem Ipsum <test@example.com>
599
branch nick: test_properties_in_log
600
timestamp: Tue 2005-11-22 00:00:00 +0000
604
wt.branch, log.LongLogFormatter)
606
def test_properties_in_short_log(self):
607
"""Log includes the custom properties returned by the registered
610
wt = self.make_standard_commit('test_properties_in_short_log')
611
def trivial_custom_prop_handler(revision):
612
return {'test_prop':'test_value'}
614
log.properties_handler_registry.register(
615
'trivial_custom_prop_handler',
616
trivial_custom_prop_handler)
617
self.assertFormatterResult("""\
618
1 John Doe\t2005-11-22
619
test_prop: test_value
623
wt.branch, log.ShortLogFormatter)
625
def test_error_in_properties_handler(self):
626
"""Log includes the custom properties returned by the registered
629
wt = self.make_standard_commit('error_in_properties_handler',
630
revprops={'first_prop':'first_value'})
631
sio = self.make_utf8_encoded_stringio()
632
formatter = log.LongLogFormatter(to_file=sio)
633
def trivial_custom_prop_handler(revision):
634
raise StandardError("a test error")
636
log.properties_handler_registry.register(
637
'trivial_custom_prop_handler',
638
trivial_custom_prop_handler)
639
self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
641
def test_properties_handler_bad_argument(self):
642
wt = self.make_standard_commit('bad_argument',
643
revprops={'a_prop':'test_value'})
644
sio = self.make_utf8_encoded_stringio()
645
formatter = log.LongLogFormatter(to_file=sio)
646
def bad_argument_prop_handler(revision):
647
return {'custom_prop_name':revision.properties['a_prop']}
649
log.properties_handler_registry.register(
650
'bad_argument_prop_handler',
651
bad_argument_prop_handler)
653
self.assertRaises(AttributeError, formatter.show_properties,
656
revision = wt.branch.repository.get_revision(wt.branch.last_revision())
657
formatter.show_properties(revision, '')
658
self.assertEqualDiff('''custom_prop_name: test_value\n''',
662
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
664
def test_long_verbose_log(self):
665
"""Verbose log includes changed files
669
wt = self.make_standard_commit('test_long_verbose_log', authors=[])
670
self.assertFormatterResult("""\
671
------------------------------------------------------------
673
committer: Lorem Ipsum <test@example.com>
674
branch nick: test_long_verbose_log
675
timestamp: Tue 2005-11-22 00:00:00 +0000
681
wt.branch, log.LongLogFormatter,
682
formatter_kwargs=dict(levels=1),
683
show_log_kwargs=dict(verbose=True))
685
def test_long_verbose_contain_deltas(self):
686
wt = self.make_branch_and_tree('parent')
687
self.build_tree(['parent/f1', 'parent/f2'])
689
self.wt_commit(wt, 'first post')
690
child_wt = wt.bzrdir.sprout('child').open_workingtree()
691
os.unlink('child/f1')
692
self.build_tree_contents([('child/f2', 'hello\n')])
693
self.wt_commit(child_wt, 'removed f1 and modified f2')
694
wt.merge_from_branch(child_wt.branch)
695
self.wt_commit(wt, 'merge branch 1')
696
self.assertFormatterResult("""\
697
------------------------------------------------------------
699
committer: Joe Foo <joe@foo.com>
701
timestamp: Tue 2005-11-22 00:00:02 +0000
708
------------------------------------------------------------
710
committer: Joe Foo <joe@foo.com>
712
timestamp: Tue 2005-11-22 00:00:00 +0000
719
wt.branch, log.LongLogFormatter,
720
formatter_kwargs=dict(levels=1),
721
show_log_kwargs=dict(verbose=True))
723
def test_long_trailing_newlines(self):
724
wt = self.make_branch_and_tree('.')
725
b = self.make_commits_with_trailing_newlines(wt)
726
self.assertFormatterResult("""\
727
------------------------------------------------------------
729
committer: Joe Foo <joe@foo.com>
731
timestamp: Tue 2005-11-22 00:00:02 +0000
733
single line with trailing newline
734
------------------------------------------------------------
736
committer: Joe Foo <joe@foo.com>
738
timestamp: Tue 2005-11-22 00:00:01 +0000
743
------------------------------------------------------------
745
committer: Joe Foo <joe@foo.com>
747
timestamp: Tue 2005-11-22 00:00:00 +0000
751
b, log.LongLogFormatter,
752
formatter_kwargs=dict(levels=1))
754
def test_long_author_in_log(self):
755
"""Log includes the author name if it's set in
756
the revision properties
758
wt = self.make_standard_commit('test_author_log')
759
self.assertFormatterResult("""\
760
------------------------------------------------------------
762
author: John Doe <jdoe@example.com>
763
committer: Lorem Ipsum <test@example.com>
764
branch nick: test_author_log
765
timestamp: Tue 2005-11-22 00:00:00 +0000
769
wt.branch, log.LongLogFormatter,
770
formatter_kwargs=dict(levels=1))
772
def test_long_properties_in_log(self):
773
"""Log includes the custom properties returned by the registered
776
wt = self.make_standard_commit('test_properties_in_log')
777
def trivial_custom_prop_handler(revision):
778
return {'test_prop':'test_value'}
780
log.properties_handler_registry.register(
781
'trivial_custom_prop_handler',
782
trivial_custom_prop_handler)
783
self.assertFormatterResult("""\
784
------------------------------------------------------------
786
test_prop: test_value
787
author: John Doe <jdoe@example.com>
788
committer: Lorem Ipsum <test@example.com>
789
branch nick: test_properties_in_log
790
timestamp: Tue 2005-11-22 00:00:00 +0000
794
wt.branch, log.LongLogFormatter,
795
formatter_kwargs=dict(levels=1))
798
class TestLineLogFormatter(TestCaseForLogFormatter):
800
def test_line_log(self):
801
"""Line log should show revno
805
wt = self.make_standard_commit('test-line-log',
806
committer='Line-Log-Formatter Tester <test@line.log>',
808
self.assertFormatterResult("""\
809
1: Line-Log-Formatte... 2005-11-22 add a
811
wt.branch, log.LineLogFormatter)
813
def test_trailing_newlines(self):
814
wt = self.make_branch_and_tree('.')
815
b = self.make_commits_with_trailing_newlines(wt)
816
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
821
b, log.LineLogFormatter)
823
def test_line_log_single_merge_revision(self):
824
wt = self._prepare_tree_with_merges()
825
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
826
rev = revspec.in_history(wt.branch)
827
self.assertFormatterResult("""\
828
1.1.1: Joe Foo 2005-11-22 rev-merged
830
wt.branch, log.LineLogFormatter,
831
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
833
def test_line_log_with_tags(self):
834
wt = self._prepare_tree_with_merges(with_tags=True)
835
self.assertFormatterResult("""\
836
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
837
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
838
1: Joe Foo 2005-11-22 rev-1
840
wt.branch, log.LineLogFormatter)
843
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
845
def test_line_merge_revs_log(self):
846
"""Line log should show revno
850
wt = self.make_standard_commit('test-line-log',
851
committer='Line-Log-Formatter Tester <test@line.log>',
853
self.assertFormatterResult("""\
854
1: Line-Log-Formatte... 2005-11-22 add a
856
wt.branch, log.LineLogFormatter)
858
def test_line_merge_revs_log_single_merge_revision(self):
859
wt = self._prepare_tree_with_merges()
860
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
861
rev = revspec.in_history(wt.branch)
862
self.assertFormatterResult("""\
863
1.1.1: Joe Foo 2005-11-22 rev-merged
865
wt.branch, log.LineLogFormatter,
866
formatter_kwargs=dict(levels=0),
867
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
869
def test_line_merge_revs_log_with_merges(self):
870
wt = self._prepare_tree_with_merges()
871
self.assertFormatterResult("""\
872
2: Joe Foo 2005-11-22 [merge] rev-2
873
1.1.1: Joe Foo 2005-11-22 rev-merged
874
1: Joe Foo 2005-11-22 rev-1
876
wt.branch, log.LineLogFormatter,
877
formatter_kwargs=dict(levels=0))
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)
923
def make_tree_with_commits(self):
924
"""Create a tree with well-known revision ids"""
925
wt = self.make_branch_and_tree('tree1')
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')
929
mainline_revs = [None, '1', '2', '3']
930
rev_nos = {'1': 1, '2': 2, '3': 3}
931
return mainline_revs, rev_nos, wt
933
def make_tree_with_merges(self):
934
"""Create a tree with well-known revision ids and a merge"""
935
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
936
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
937
self.wt_commit(tree2, 'four-a', rev_id='4a')
938
wt.merge_from_branch(tree2.branch)
939
self.wt_commit(wt, 'four-b', rev_id='4b')
940
mainline_revs.append('4b')
943
return mainline_revs, rev_nos, wt
945
def make_branch_with_many_merges(self):
946
"""Create a tree with well-known revision ids"""
947
builder = self.make_branch_builder('tree1')
948
builder.start_series()
949
builder.build_snapshot('1', None, [
950
('add', ('', 'TREE_ROOT', 'directory', '')),
951
('add', ('f', 'f-id', 'file', '1\n'))])
952
builder.build_snapshot('2', ['1'], [])
953
builder.build_snapshot('3a', ['2'], [
954
('modify', ('f-id', '1\n2\n3a\n'))])
955
builder.build_snapshot('3b', ['2', '3a'], [
956
('modify', ('f-id', '1\n2\n3a\n'))])
957
builder.build_snapshot('3c', ['2', '3b'], [
958
('modify', ('f-id', '1\n2\n3a\n'))])
959
builder.build_snapshot('4a', ['3b'], [])
960
builder.build_snapshot('4b', ['3c', '4a'], [])
961
builder.finish_series()
975
mainline_revs = [None, '1', '2', '3c', '4b']
976
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
977
full_rev_nos_for_reference = {
980
'3a': '2.1.1', #first commit tree 3
981
'3b': '2.2.1', # first commit tree 2
982
'3c': '3', #merges 3b to main
983
'4a': '2.2.2', # second commit tree 2
984
'4b': '4', # merges 4a to main
986
return mainline_revs, rev_nos, builder.get_branch()
988
def test_get_view_revisions_forward(self):
989
"""Test the get_view_revisions method"""
990
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
992
self.addCleanup(wt.unlock)
993
revisions = list(self._get_view_revisions(
994
mainline_revs, rev_nos, wt.branch, 'forward'))
995
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
997
revisions2 = list(self._get_view_revisions(
998
mainline_revs, rev_nos, wt.branch, 'forward',
999
include_merges=False))
1000
self.assertEqual(revisions, revisions2)
1002
def test_get_view_revisions_reverse(self):
1003
"""Test the get_view_revisions with reverse"""
1004
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1006
self.addCleanup(wt.unlock)
1007
revisions = list(self._get_view_revisions(
1008
mainline_revs, rev_nos, wt.branch, 'reverse'))
1009
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1011
revisions2 = list(self._get_view_revisions(
1012
mainline_revs, rev_nos, wt.branch, 'reverse',
1013
include_merges=False))
1014
self.assertEqual(revisions, revisions2)
1016
def test_get_view_revisions_merge(self):
1017
"""Test get_view_revisions when there are merges"""
1018
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1020
self.addCleanup(wt.unlock)
1021
revisions = list(self._get_view_revisions(
1022
mainline_revs, rev_nos, wt.branch, 'forward'))
1023
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1024
('4b', '4', 0), ('4a', '3.1.1', 1)],
1026
revisions = list(self._get_view_revisions(
1027
mainline_revs, rev_nos, wt.branch, 'forward',
1028
include_merges=False))
1029
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1033
def test_get_view_revisions_merge_reverse(self):
1034
"""Test get_view_revisions in reverse when there are merges"""
1035
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1037
self.addCleanup(wt.unlock)
1038
revisions = list(self._get_view_revisions(
1039
mainline_revs, rev_nos, wt.branch, 'reverse'))
1040
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1041
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1043
revisions = list(self._get_view_revisions(
1044
mainline_revs, rev_nos, wt.branch, 'reverse',
1045
include_merges=False))
1046
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1050
def test_get_view_revisions_merge2(self):
1051
"""Test get_view_revisions when there are merges"""
1052
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1054
self.addCleanup(b.unlock)
1055
revisions = list(self._get_view_revisions(
1056
mainline_revs, rev_nos, b, 'forward'))
1057
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1058
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1060
self.assertEqual(expected, revisions)
1061
revisions = list(self._get_view_revisions(
1062
mainline_revs, rev_nos, b, 'forward',
1063
include_merges=False))
1064
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1068
def test_file_id_for_range(self):
1069
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1071
self.addCleanup(b.unlock)
1073
def rev_from_rev_id(revid, branch):
1074
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1075
return revspec.in_history(branch)
1077
def view_revs(start_rev, end_rev, file_id, direction):
1078
revs = self.applyDeprecated(
1079
symbol_versioning.deprecated_in((2, 2, 0)),
1080
log.calculate_view_revisions,
1082
start_rev, # start_revision
1083
end_rev, # end_revision
1084
direction, # direction
1085
file_id, # specific_fileid
1086
True, # generate_merge_revisions
1090
rev_3a = rev_from_rev_id('3a', b)
1091
rev_4b = rev_from_rev_id('4b', b)
1092
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1093
('3a', '2.1.1', 2)],
1094
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1095
# Note: 3c still appears before 3a here because of depth-based sorting
1096
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1097
('3a', '2.1.1', 2)],
1098
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
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)
1107
def create_tree_with_single_merge(self):
1108
"""Create a branch with a moderate layout.
1110
The revision graph looks like:
1118
In this graph, A introduced files f1 and f2 and f3.
1119
B modifies f1 and f3, and C modifies f2 and f3.
1120
D merges the changes from B and C and resolves the conflict for f3.
1122
# TODO: jam 20070218 This seems like it could really be done
1123
# with make_branch_and_memory_tree() if we could just
1124
# create the content of those files.
1125
# TODO: jam 20070218 Another alternative is that we would really
1126
# like to only create this tree 1 time for all tests that
1127
# use it. Since 'log' only uses the tree in a readonly
1128
# fashion, it seems a shame to regenerate an identical
1129
# tree for each test.
1130
# TODO: vila 20100122 One way to address the shame above will be to
1131
# create a memory tree during test parametrization and give a
1132
# *copy* of this tree to each test. Copying a memory tree ought
1133
# to be cheap, at least cheaper than creating them with such
1135
tree = self.make_branch_and_tree('tree')
1137
self.addCleanup(tree.unlock)
1139
self.build_tree_contents([('tree/f1', 'A\n'),
1143
tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1144
tree.commit('A', rev_id='A')
1146
self.build_tree_contents([('tree/f2', 'A\nC\n'),
1147
('tree/f3', 'A\nC\n'),
1149
tree.commit('C', rev_id='C')
1150
# Revert back to A to build the other history.
1151
tree.set_last_revision('A')
1152
tree.branch.set_last_revision_info(1, 'A')
1153
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1155
('tree/f3', 'A\nB\n'),
1157
tree.commit('B', rev_id='B')
1158
tree.set_parent_ids(['B', 'C'])
1159
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1160
('tree/f2', 'A\nC\n'),
1161
('tree/f3', 'A\nB\nC\n'),
1163
tree.commit('D', rev_id='D')
1165
# Switch to a read lock for this tree.
1166
# We still have an addCleanup(tree.unlock) pending
1171
def check_delta(self, delta, **kw):
1172
"""Check the filenames touched by a delta are as expected.
1174
Caller only have to pass in the list of files for each part, all
1175
unspecified parts are considered empty (and checked as such).
1177
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1178
# By default we expect an empty list
1179
expected = kw.get(n, [])
1180
# strip out only the path components
1181
got = [x[0] for x in getattr(delta, n)]
1182
self.assertEqual(expected, got)
1184
def test_tree_with_single_merge(self):
1185
"""Make sure the tree layout is correct."""
1186
tree = self.create_tree_with_single_merge()
1187
rev_A_tree = tree.branch.repository.revision_tree('A')
1188
rev_B_tree = tree.branch.repository.revision_tree('B')
1189
rev_C_tree = tree.branch.repository.revision_tree('C')
1190
rev_D_tree = tree.branch.repository.revision_tree('D')
1192
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1193
modified=['f1', 'f3'])
1195
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1196
modified=['f2', 'f3'])
1198
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1199
modified=['f2', 'f3'])
1201
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1202
modified=['f1', 'f3'])
1204
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
1205
"""Ensure _filter_revisions_touching_file_id returns the right values.
1207
Get the return value from _filter_revisions_touching_file_id and make
1208
sure they are correct.
1210
# The api for _filter_revisions_touching_file_id is a little crazy.
1211
# So we do the setup here.
1212
mainline = tree.branch.revision_history()
1213
mainline.insert(0, None)
1214
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1215
view_revs_iter = self.get_view_revisions(
1216
mainline, revnos, tree.branch, 'reverse', True)
1217
actual_revs = log._filter_revisions_touching_file_id(
1218
tree.branch, file_id, list(view_revs_iter))
1219
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1221
def test_file_id_f1(self):
1222
tree = self.create_tree_with_single_merge()
1223
# f1 should be marked as modified by revisions A and B
1224
self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1226
def test_file_id_f2(self):
1227
tree = self.create_tree_with_single_merge()
1228
# f2 should be marked as modified by revisions A, C, and D
1229
# because D merged the changes from C.
1230
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1232
def test_file_id_f3(self):
1233
tree = self.create_tree_with_single_merge()
1234
# f3 should be marked as modified by revisions A, B, C, and D
1235
self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1237
def test_file_id_with_ghosts(self):
1238
# This is testing bug #209948, where having a ghost would cause
1239
# _filter_revisions_touching_file_id() to fail.
1240
tree = self.create_tree_with_single_merge()
1241
# We need to add a revision, so switch back to a write-locked tree
1242
# (still a single addCleanup(tree.unlock) pending).
1245
first_parent = tree.last_revision()
1246
tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1247
self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1248
tree.commit('commit with a ghost', rev_id='XX')
1249
self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1250
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1252
def test_unknown_file_id(self):
1253
tree = self.create_tree_with_single_merge()
1254
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1256
def test_empty_branch_unknown_file_id(self):
1257
tree = self.make_branch_and_tree('tree')
1258
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1261
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1263
def test_show_changed_revisions_verbose(self):
1264
tree = self.make_branch_and_tree('tree_a')
1265
self.build_tree(['tree_a/foo'])
1267
tree.commit('bar', rev_id='bar-id')
1268
s = self.make_utf8_encoded_stringio()
1269
log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1270
self.assertContainsRe(s.getvalue(), 'bar')
1271
self.assertNotContainsRe(s.getvalue(), 'foo')
1274
class TestLogFormatter(tests.TestCase):
1277
super(TestLogFormatter, self).setUp()
1278
self.rev = revision.Revision('a-id')
1279
self.lf = log.LogFormatter(None)
1281
def test_short_committer(self):
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')
1293
def test_short_author(self):
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))
1314
class TestReverseByDepth(tests.TestCase):
1315
"""Test reverse_by_depth behavior.
1317
This is used to present revisions in forward (oldest first) order in a nice
1320
The tests use lighter revision description to ease reading.
1323
def assertReversed(self, forward, backward):
1324
# Transform the descriptions to suit the API: tests use (revno, depth),
1325
# while the API expects (revid, revno, depth)
1326
def complete_revisions(l):
1327
"""Transform the description to suit the API.
1329
Tests use (revno, depth) whil the API expects (revid, revno, depth).
1330
Since the revid is arbitrary, we just duplicate revno
1332
return [ (r, r, d) for r, d in l]
1333
forward = complete_revisions(forward)
1334
backward= complete_revisions(backward)
1335
self.assertEqual(forward, log.reverse_by_depth(backward))
1338
def test_mainline_revisions(self):
1339
self.assertReversed([( '1', 0), ('2', 0)],
1340
[('2', 0), ('1', 0)])
1342
def test_merged_revisions(self):
1343
self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1344
[('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
1345
def test_shifted_merged_revisions(self):
1346
"""Test irregular layout.
1348
Requesting revisions touching a file can produce "holes" in the depths.
1350
self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1351
[('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
1353
def test_merged_without_child_revisions(self):
1354
"""Test irregular layout.
1356
Revision ranges can produce "holes" in the depths.
1358
# When a revision of higher depth doesn't follow one of lower depth, we
1359
# assume a lower depth one is virtually there
1360
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1361
[('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1362
# So we get the same order after reversing below even if the original
1363
# revisions are not in the same order.
1364
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1365
[('3', 3), ('4', 4), ('2', 2), ('1', 2),])
1368
class TestHistoryChange(tests.TestCaseWithTransport):
1370
def setup_a_tree(self):
1371
tree = self.make_branch_and_tree('tree')
1373
self.addCleanup(tree.unlock)
1374
tree.commit('1a', rev_id='1a')
1375
tree.commit('2a', rev_id='2a')
1376
tree.commit('3a', rev_id='3a')
1379
def setup_ab_tree(self):
1380
tree = self.setup_a_tree()
1381
tree.set_last_revision('1a')
1382
tree.branch.set_last_revision_info(1, '1a')
1383
tree.commit('2b', rev_id='2b')
1384
tree.commit('3b', rev_id='3b')
1387
def setup_ac_tree(self):
1388
tree = self.setup_a_tree()
1389
tree.set_last_revision(revision.NULL_REVISION)
1390
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1391
tree.commit('1c', rev_id='1c')
1392
tree.commit('2c', rev_id='2c')
1393
tree.commit('3c', rev_id='3c')
1396
def test_all_new(self):
1397
tree = self.setup_ab_tree()
1398
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1399
self.assertEqual([], old)
1400
self.assertEqual(['2a', '3a'], new)
1402
def test_all_old(self):
1403
tree = self.setup_ab_tree()
1404
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1405
self.assertEqual([], new)
1406
self.assertEqual(['2a', '3a'], old)
1408
def test_null_old(self):
1409
tree = self.setup_ab_tree()
1410
old, new = log.get_history_change(revision.NULL_REVISION,
1411
'3a', tree.branch.repository)
1412
self.assertEqual([], old)
1413
self.assertEqual(['1a', '2a', '3a'], new)
1415
def test_null_new(self):
1416
tree = self.setup_ab_tree()
1417
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1418
tree.branch.repository)
1419
self.assertEqual([], new)
1420
self.assertEqual(['1a', '2a', '3a'], old)
1422
def test_diverged(self):
1423
tree = self.setup_ab_tree()
1424
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1425
self.assertEqual(old, ['2a', '3a'])
1426
self.assertEqual(new, ['2b', '3b'])
1428
def test_unrelated(self):
1429
tree = self.setup_ac_tree()
1430
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1431
self.assertEqual(old, ['1a', '2a', '3a'])
1432
self.assertEqual(new, ['1c', '2c', '3c'])
1434
def test_show_branch_change(self):
1435
tree = self.setup_ab_tree()
1437
log.show_branch_change(tree.branch, s, 3, '3a')
1438
self.assertContainsRe(s.getvalue(),
1439
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1440
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1442
def test_show_branch_change_no_change(self):
1443
tree = self.setup_ab_tree()
1445
log.show_branch_change(tree.branch, s, 3, '3b')
1446
self.assertEqual(s.getvalue(),
1447
'Nothing seems to have changed\n')
1449
def test_show_branch_change_no_old(self):
1450
tree = self.setup_ab_tree()
1452
log.show_branch_change(tree.branch, s, 2, '2b')
1453
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1454
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1456
def test_show_branch_change_no_new(self):
1457
tree = self.setup_ab_tree()
1458
tree.branch.set_last_revision_info(2, '2b')
1460
log.show_branch_change(tree.branch, s, 3, '3b')
1461
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1462
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1466
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1469
TestCaseForLogFormatter.setUp(self)
1470
log.properties_handler_registry.register(
1471
'bugs_properties_handler',
1472
log._bugs_properties_handler)
1474
def make_commits_with_bugs(self):
1475
"""Helper method for LogFormatter tests"""
1476
tree = self.make_branch_and_tree(u'.')
1477
self.build_tree(['a', 'b'])
1479
self.wt_commit(tree, 'simple log message', rev_id='a1',
1480
revprops={'bugs': 'test://bug/id 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'})
1489
def test_long_bugs(self):
1490
tree = self.make_commits_with_bugs()
1491
self.assertFormatterResult("""\
1492
------------------------------------------------------------
1494
fixes bug(s): test://bug/id test://bug/2
1495
author: Joe Bar <joe@bar.com>
1496
committer: Joe Foo <joe@foo.com>
1498
timestamp: Tue 2005-11-22 00:00:01 +0000
1503
------------------------------------------------------------
1505
fixes bug(s): test://bug/id
1506
committer: Joe Foo <joe@foo.com>
1508
timestamp: Tue 2005-11-22 00:00:00 +0000
1512
tree.branch, log.LongLogFormatter)
1514
def test_short_bugs(self):
1515
tree = self.make_commits_with_bugs()
1516
self.assertFormatterResult("""\
1517
2 Joe Bar\t2005-11-22
1518
fixes bug(s): test://bug/id test://bug/2
1523
1 Joe Foo\t2005-11-22
1524
fixes bug(s): test://bug/id
1528
tree.branch, log.ShortLogFormatter)
1530
def test_wrong_bugs_property(self):
1531
tree = self.make_branch_and_tree(u'.')
1532
self.build_tree(['foo'])
1533
self.wt_commit(tree, 'simple log message', rev_id='a1',
1534
revprops={'bugs': 'test://bug/id invalid_value'})
1535
self.assertFormatterResult("""\
1536
1 Joe Foo\t2005-11-22
1540
tree.branch, log.ShortLogFormatter)
1542
def test_bugs_handler_present(self):
1543
self.properties_handler_registry.get('bugs_properties_handler')
108
logentry = lf.logs[0]
109
eq(logentry.revno, 2)
110
eq(logentry.rev.message, 'add one file')
112
self.log('log 2 delta: %r' % d)
113
# self.checkDelta(d, added=['hello'])