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.tests import BzrTestBase, TestCaseInTempDir
21
from bzrlib.log import LogFormatter, show_log, LongLogFormatter, ShortLogFormatter
22
from bzrlib.branch import Branch
23
from bzrlib.errors import InvalidRevisionNumber
25
class _LogEntry(object):
26
# should probably move into bzrlib.log?
30
class LogCatcher(LogFormatter):
31
"""Pull log messages into list rather than displaying them.
33
For ease of testing we save log messages here rather than actually
34
formatting them, so that we can precisely check the result without
35
being too dependent on the exact formatting.
37
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):
40
super(LogCatcher, self).__init__(to_file=None)
44
def show(self, revno, rev, delta):
52
class SimpleLogTest(TestCaseInTempDir):
143
54
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).
55
"""Check the filenames touched by a delta are as expected."""
149
56
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
150
# By default we expect an empty list
151
57
expected = kw.get(n, [])
59
# tests are written with unix paths; fix them up for windows
61
expected = [x.replace('/', os.sep) for x in expected]
152
63
# strip out only the path components
153
64
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)
65
self.assertEquals(expected, got)
67
def test_cur_revno(self):
68
b = Branch('.', init=True)
71
b.working_tree().commit('empty commit')
72
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
73
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
74
start_revision=2, end_revision=1)
75
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
76
start_revision=1, end_revision=2)
77
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
78
start_revision=0, end_revision=2)
79
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
80
start_revision=1, end_revision=0)
81
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
82
start_revision=-1, end_revision=1)
83
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
84
start_revision=1, end_revision=-1)
86
def test_cur_revno(self):
87
b = Branch.initialize('.')
90
b.working_tree().commit('empty commit')
91
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
92
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
93
start_revision=2, end_revision=1)
94
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
95
start_revision=1, end_revision=2)
96
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
97
start_revision=0, end_revision=2)
98
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
99
start_revision=1, end_revision=0)
100
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
101
start_revision=-1, end_revision=1)
102
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
103
start_revision=1, end_revision=-1)
105
def test_simple_log(self):
106
eq = self.assertEquals
108
b = Branch.initialize('.')
185
self.assertEqual([], lf.revisions)
187
def test_empty_commit(self):
188
wt = self.make_branch_and_tree('.')
190
wt.commit('empty commit')
115
b.working_tree().commit('empty commit')
191
116
lf = LogCatcher()
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)
117
show_log(b, lf, verbose=True)
119
eq(lf.logs[0].revno, 1)
120
eq(lf.logs[0].rev.message, 'empty commit')
122
self.log('log delta: %r' % d)
199
def test_simple_commit(self):
200
wt = self.make_branch_and_tree('.')
201
wt.commit('empty commit')
202
125
self.build_tree(['hello'])
204
wt.commit('add one file',
205
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
206
u'<test@example.com>')
126
b.working_tree().add('hello')
127
b.working_tree().commit('add one file')
130
# log using regular thing
131
show_log(b, LongLogFormatter(lf))
133
for l in lf.readlines():
136
# get log as data structure
207
137
lf = LogCatcher()
208
log.show_log(wt.branch, lf, verbose=True)
209
self.assertEqual(2, len(lf.revisions))
138
show_log(b, lf, verbose=True)
140
self.log('log entries:')
141
for logentry in lf.logs:
142
self.log('%4d %s' % (logentry.revno, logentry.rev.message))
210
144
# 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')
145
logentry = lf.logs[0]
146
eq(logentry.revno, 2)
147
eq(logentry.rev.message, 'add one file')
149
self.log('log 2 delta: %r' % d)
150
# self.checkDelta(d, added=['hello'])
152
# commit a log message with control characters
153
msg = "All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
154
self.log("original commit message: %r", msg)
155
b.working_tree().commit(msg)
221
156
lf = LogCatcher()
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)
157
show_log(b, lf, verbose=True)
158
committed_msg = lf.logs[0].rev.message
159
self.log("escaped commit message: %r", committed_msg)
160
self.assert_(msg != committed_msg)
161
self.assert_(len(committed_msg) > len(msg))
230
def test_commit_message_without_control_chars(self):
231
wt = self.make_branch_and_tree('.')
163
# Check that log message with only XML-valid characters isn't
232
164
# escaped. As ElementTree apparently does some kind of
233
165
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
234
166
# included in the test commit message, even though they are
235
167
# valid XML 1.0 characters.
236
168
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):
169
self.log("original commit message: %r", msg)
170
b.working_tree().commit(msg)
172
show_log(b, lf, verbose=True)
173
committed_msg = lf.logs[0].rev.message
174
self.log("escaped commit message: %r", committed_msg)
175
self.assert_(msg == committed_msg)
285
177
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
178
b = Branch.initialize('.')
180
wt = b.working_tree()
181
open('a', 'wb').write('hello moto\n')
183
wt.commit('simple log message', rev_id='a1'
184
, timestamp=1132586655.459960938, timezone=-6*3600
185
, committer='Joe Foo <joe@foo.com>')
186
open('b', 'wb').write('goodbye\n')
188
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
189
, timestamp=1132586842.411175966, timezone=-6*3600
190
, committer='Joe Foo <joe@foo.com>')
192
open('c', 'wb').write('just another manic monday\n')
194
wt.commit('single line with trailing newline\n', rev_id='a3'
195
, timestamp=1132587176.835228920, timezone=-6*3600
196
, committer = 'Joe Foo <joe@foo.com>')
199
lf = ShortLogFormatter(to_file=sio)
201
self.assertEquals(sio.getvalue(), """\
202
3 Joe Foo\t2005-11-21
290
203
single line with trailing newline
292
2 Joe Foo\t2005-11-22
205
2 Joe Foo\t2005-11-21
297
1 Joe Foo\t2005-11-22
210
1 Joe Foo\t2005-11-21
298
211
simple log message
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):
216
lf = LongLogFormatter(to_file=sio)
218
self.assertEquals(sio.getvalue(), """\
219
------------------------------------------------------------
221
committer: Joe Foo <joe@foo.com>
223
timestamp: Mon 2005-11-21 09:32:56 -0600
225
single line with trailing newline
226
------------------------------------------------------------
228
committer: Joe Foo <joe@foo.com>
230
timestamp: Mon 2005-11-21 09:27:22 -0600
235
------------------------------------------------------------
237
committer: Joe Foo <joe@foo.com>
239
timestamp: Mon 2005-11-21 09:24:15 -0600
411
244
def test_verbose_log(self):
412
245
"""Verbose log includes changed files
416
wt = self.make_standard_commit('test_verbose_log', authors=[])
417
self.assertFormatterResult('''\
249
b = Branch.initialize('.')
250
self.build_tree(['a'])
251
wt = b.working_tree()
253
# XXX: why does a longer nick show up?
254
b.nick = 'test_verbose_log'
255
wt.commit(message='add a',
256
timestamp=1132711707,
258
committer='Lorem Ipsum <test@example.com>')
259
logfile = file('out.tmp', 'w+')
260
formatter = LongLogFormatter(to_file=logfile)
261
show_log(b, formatter, verbose=True)
264
log_contents = logfile.read()
265
self.assertEqualDiff(log_contents, '''\
418
266
------------------------------------------------------------
420
268
committer: Lorem Ipsum <test@example.com>
421
269
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 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)
886
def make_tree_with_commits(self):
887
"""Create a tree with well-known revision ids"""
888
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')
892
mainline_revs = [None, '1', '2', '3']
893
rev_nos = {'1': 1, '2': 2, '3': 3}
894
return mainline_revs, rev_nos, wt
896
def make_tree_with_merges(self):
897
"""Create a tree with well-known revision ids and a merge"""
898
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
899
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
900
self.wt_commit(tree2, 'four-a', rev_id='4a')
901
wt.merge_from_branch(tree2.branch)
902
self.wt_commit(wt, 'four-b', rev_id='4b')
903
mainline_revs.append('4b')
906
return mainline_revs, rev_nos, wt
908
def make_branch_with_many_merges(self):
909
"""Create a tree with well-known revision ids"""
910
builder = self.make_branch_builder('tree1')
911
builder.start_series()
912
builder.build_snapshot('1', None, [
913
('add', ('', 'TREE_ROOT', 'directory', '')),
914
('add', ('f', 'f-id', 'file', '1\n'))])
915
builder.build_snapshot('2', ['1'], [])
916
builder.build_snapshot('3a', ['2'], [
917
('modify', ('f-id', '1\n2\n3a\n'))])
918
builder.build_snapshot('3b', ['2', '3a'], [
919
('modify', ('f-id', '1\n2\n3a\n'))])
920
builder.build_snapshot('3c', ['2', '3b'], [
921
('modify', ('f-id', '1\n2\n3a\n'))])
922
builder.build_snapshot('4a', ['3b'], [])
923
builder.build_snapshot('4b', ['3c', '4a'], [])
924
builder.finish_series()
938
mainline_revs = [None, '1', '2', '3c', '4b']
939
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
940
full_rev_nos_for_reference = {
943
'3a': '2.1.1', #first commit tree 3
944
'3b': '2.2.1', # first commit tree 2
945
'3c': '3', #merges 3b to main
946
'4a': '2.2.2', # second commit tree 2
947
'4b': '4', # merges 4a to main
949
return mainline_revs, rev_nos, builder.get_branch()
951
def test_get_view_revisions_forward(self):
952
"""Test the get_view_revisions method"""
953
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
955
self.addCleanup(wt.unlock)
956
revisions = list(self._get_view_revisions(
957
mainline_revs, rev_nos, wt.branch, 'forward'))
958
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
960
revisions2 = list(self._get_view_revisions(
961
mainline_revs, rev_nos, wt.branch, 'forward',
962
include_merges=False))
963
self.assertEqual(revisions, revisions2)
965
def test_get_view_revisions_reverse(self):
966
"""Test the get_view_revisions with reverse"""
967
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
969
self.addCleanup(wt.unlock)
970
revisions = list(self._get_view_revisions(
971
mainline_revs, rev_nos, wt.branch, 'reverse'))
972
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
974
revisions2 = list(self._get_view_revisions(
975
mainline_revs, rev_nos, wt.branch, 'reverse',
976
include_merges=False))
977
self.assertEqual(revisions, revisions2)
979
def test_get_view_revisions_merge(self):
980
"""Test get_view_revisions when there are merges"""
981
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
983
self.addCleanup(wt.unlock)
984
revisions = list(self._get_view_revisions(
985
mainline_revs, rev_nos, wt.branch, 'forward'))
986
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
987
('4b', '4', 0), ('4a', '3.1.1', 1)],
989
revisions = list(self._get_view_revisions(
990
mainline_revs, rev_nos, wt.branch, 'forward',
991
include_merges=False))
992
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
996
def test_get_view_revisions_merge_reverse(self):
997
"""Test get_view_revisions in reverse when there are merges"""
998
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1000
self.addCleanup(wt.unlock)
1001
revisions = list(self._get_view_revisions(
1002
mainline_revs, rev_nos, wt.branch, 'reverse'))
1003
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1004
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1006
revisions = list(self._get_view_revisions(
1007
mainline_revs, rev_nos, wt.branch, 'reverse',
1008
include_merges=False))
1009
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1013
def test_get_view_revisions_merge2(self):
1014
"""Test get_view_revisions when there are merges"""
1015
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1017
self.addCleanup(b.unlock)
1018
revisions = list(self._get_view_revisions(
1019
mainline_revs, rev_nos, b, 'forward'))
1020
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1021
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1023
self.assertEqual(expected, revisions)
1024
revisions = list(self._get_view_revisions(
1025
mainline_revs, rev_nos, b, 'forward',
1026
include_merges=False))
1027
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1031
def test_file_id_for_range(self):
1032
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1034
self.addCleanup(b.unlock)
1036
def rev_from_rev_id(revid, branch):
1037
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1038
return revspec.in_history(branch)
1040
def view_revs(start_rev, end_rev, file_id, direction):
1041
revs = self.applyDeprecated(
1042
symbol_versioning.deprecated_in((2, 2, 0)),
1043
log.calculate_view_revisions,
1045
start_rev, # start_revision
1046
end_rev, # end_revision
1047
direction, # direction
1048
file_id, # specific_fileid
1049
True, # generate_merge_revisions
1053
rev_3a = rev_from_rev_id('3a', b)
1054
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)],
1057
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1058
# 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)],
1061
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1064
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
def create_tree_with_single_merge(self):
1071
"""Create a branch with a moderate layout.
1073
The revision graph looks like:
1081
In this graph, A introduced files f1 and f2 and f3.
1082
B modifies f1 and f3, and C modifies f2 and f3.
1083
D merges the changes from B and C and resolves the conflict for f3.
1085
# TODO: jam 20070218 This seems like it could really be done
1086
# with make_branch_and_memory_tree() if we could just
1087
# create the content of those files.
1088
# TODO: jam 20070218 Another alternative is that we would really
1089
# like to only create this tree 1 time for all tests that
1090
# use it. Since 'log' only uses the tree in a readonly
1091
# fashion, it seems a shame to regenerate an identical
1092
# tree for each test.
1093
# TODO: vila 20100122 One way to address the shame above will be to
1094
# create a memory tree during test parametrization and give a
1095
# *copy* of this tree to each test. Copying a memory tree ought
1096
# to be cheap, at least cheaper than creating them with such
1098
tree = self.make_branch_and_tree('tree')
1100
self.addCleanup(tree.unlock)
1102
self.build_tree_contents([('tree/f1', 'A\n'),
1106
tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1107
tree.commit('A', rev_id='A')
1109
self.build_tree_contents([('tree/f2', 'A\nC\n'),
1110
('tree/f3', 'A\nC\n'),
1112
tree.commit('C', rev_id='C')
1113
# Revert back to A to build the other history.
1114
tree.set_last_revision('A')
1115
tree.branch.set_last_revision_info(1, 'A')
1116
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1118
('tree/f3', 'A\nB\n'),
1120
tree.commit('B', rev_id='B')
1121
tree.set_parent_ids(['B', 'C'])
1122
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1123
('tree/f2', 'A\nC\n'),
1124
('tree/f3', 'A\nB\nC\n'),
1126
tree.commit('D', rev_id='D')
1128
# Switch to a read lock for this tree.
1129
# We still have an addCleanup(tree.unlock) pending
1134
def check_delta(self, delta, **kw):
1135
"""Check the filenames touched by a delta are as expected.
1137
Caller only have to pass in the list of files for each part, all
1138
unspecified parts are considered empty (and checked as such).
1140
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1141
# By default we expect an empty list
1142
expected = kw.get(n, [])
1143
# strip out only the path components
1144
got = [x[0] for x in getattr(delta, n)]
1145
self.assertEqual(expected, got)
1147
def test_tree_with_single_merge(self):
1148
"""Make sure the tree layout is correct."""
1149
tree = self.create_tree_with_single_merge()
1150
rev_A_tree = tree.branch.repository.revision_tree('A')
1151
rev_B_tree = tree.branch.repository.revision_tree('B')
1152
rev_C_tree = tree.branch.repository.revision_tree('C')
1153
rev_D_tree = tree.branch.repository.revision_tree('D')
1155
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1156
modified=['f1', 'f3'])
1158
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1159
modified=['f2', 'f3'])
1161
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1162
modified=['f2', 'f3'])
1164
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1165
modified=['f1', 'f3'])
1167
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
1168
"""Ensure _filter_revisions_touching_file_id returns the right values.
1170
Get the return value from _filter_revisions_touching_file_id and make
1171
sure they are correct.
1173
# The api for _filter_revisions_touching_file_id is a little crazy.
1174
# So we do the setup here.
1175
mainline = tree.branch.revision_history()
1176
mainline.insert(0, None)
1177
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)
1180
actual_revs = log._filter_revisions_touching_file_id(
1181
tree.branch, file_id, list(view_revs_iter))
1182
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1184
def test_file_id_f1(self):
1185
tree = self.create_tree_with_single_merge()
1186
# f1 should be marked as modified by revisions A and B
1187
self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1189
def test_file_id_f2(self):
1190
tree = self.create_tree_with_single_merge()
1191
# f2 should be marked as modified by revisions A, C, and D
1192
# because D merged the changes from C.
1193
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1195
def test_file_id_f3(self):
1196
tree = self.create_tree_with_single_merge()
1197
# f3 should be marked as modified by revisions A, B, C, and D
1198
self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1200
def test_file_id_with_ghosts(self):
1201
# This is testing bug #209948, where having a ghost would cause
1202
# _filter_revisions_touching_file_id() to fail.
1203
tree = self.create_tree_with_single_merge()
1204
# We need to add a revision, so switch back to a write-locked tree
1205
# (still a single addCleanup(tree.unlock) pending).
1208
first_parent = tree.last_revision()
1209
tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1210
self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1211
tree.commit('commit with a ghost', rev_id='XX')
1212
self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1213
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1215
def test_unknown_file_id(self):
1216
tree = self.create_tree_with_single_merge()
1217
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1219
def test_empty_branch_unknown_file_id(self):
1220
tree = self.make_branch_and_tree('tree')
1221
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1224
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1226
def test_show_changed_revisions_verbose(self):
1227
tree = self.make_branch_and_tree('tree_a')
1228
self.build_tree(['tree_a/foo'])
1230
tree.commit('bar', rev_id='bar-id')
1231
s = self.make_utf8_encoded_stringio()
1232
log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1233
self.assertContainsRe(s.getvalue(), 'bar')
1234
self.assertNotContainsRe(s.getvalue(), 'foo')
1237
class TestLogFormatter(tests.TestCase):
1240
super(TestLogFormatter, self).setUp()
1241
self.rev = revision.Revision('a-id')
1242
self.lf = log.LogFormatter(None)
1244
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')
1256
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))
1277
class TestReverseByDepth(tests.TestCase):
1278
"""Test reverse_by_depth behavior.
1280
This is used to present revisions in forward (oldest first) order in a nice
1283
The tests use lighter revision description to ease reading.
1286
def assertReversed(self, forward, backward):
1287
# Transform the descriptions to suit the API: tests use (revno, depth),
1288
# while the API expects (revid, revno, depth)
1289
def complete_revisions(l):
1290
"""Transform the description to suit the API.
1292
Tests use (revno, depth) whil the API expects (revid, revno, depth).
1293
Since the revid is arbitrary, we just duplicate revno
1295
return [ (r, r, d) for r, d in l]
1296
forward = complete_revisions(forward)
1297
backward= complete_revisions(backward)
1298
self.assertEqual(forward, log.reverse_by_depth(backward))
1301
def test_mainline_revisions(self):
1302
self.assertReversed([( '1', 0), ('2', 0)],
1303
[('2', 0), ('1', 0)])
1305
def test_merged_revisions(self):
1306
self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1307
[('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
1308
def test_shifted_merged_revisions(self):
1309
"""Test irregular layout.
1311
Requesting revisions touching a file can produce "holes" in the depths.
1313
self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1314
[('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
1316
def test_merged_without_child_revisions(self):
1317
"""Test irregular layout.
1319
Revision ranges can produce "holes" in the depths.
1321
# When a revision of higher depth doesn't follow one of lower depth, we
1322
# assume a lower depth one is virtually there
1323
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1324
[('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1325
# So we get the same order after reversing below even if the original
1326
# revisions are not in the same order.
1327
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1328
[('3', 3), ('4', 4), ('2', 2), ('1', 2),])
1331
class TestHistoryChange(tests.TestCaseWithTransport):
1333
def setup_a_tree(self):
1334
tree = self.make_branch_and_tree('tree')
1336
self.addCleanup(tree.unlock)
1337
tree.commit('1a', rev_id='1a')
1338
tree.commit('2a', rev_id='2a')
1339
tree.commit('3a', rev_id='3a')
1342
def setup_ab_tree(self):
1343
tree = self.setup_a_tree()
1344
tree.set_last_revision('1a')
1345
tree.branch.set_last_revision_info(1, '1a')
1346
tree.commit('2b', rev_id='2b')
1347
tree.commit('3b', rev_id='3b')
1350
def setup_ac_tree(self):
1351
tree = self.setup_a_tree()
1352
tree.set_last_revision(revision.NULL_REVISION)
1353
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1354
tree.commit('1c', rev_id='1c')
1355
tree.commit('2c', rev_id='2c')
1356
tree.commit('3c', rev_id='3c')
1359
def test_all_new(self):
1360
tree = self.setup_ab_tree()
1361
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1362
self.assertEqual([], old)
1363
self.assertEqual(['2a', '3a'], new)
1365
def test_all_old(self):
1366
tree = self.setup_ab_tree()
1367
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1368
self.assertEqual([], new)
1369
self.assertEqual(['2a', '3a'], old)
1371
def test_null_old(self):
1372
tree = self.setup_ab_tree()
1373
old, new = log.get_history_change(revision.NULL_REVISION,
1374
'3a', tree.branch.repository)
1375
self.assertEqual([], old)
1376
self.assertEqual(['1a', '2a', '3a'], new)
1378
def test_null_new(self):
1379
tree = self.setup_ab_tree()
1380
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1381
tree.branch.repository)
1382
self.assertEqual([], new)
1383
self.assertEqual(['1a', '2a', '3a'], old)
1385
def test_diverged(self):
1386
tree = self.setup_ab_tree()
1387
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1388
self.assertEqual(old, ['2a', '3a'])
1389
self.assertEqual(new, ['2b', '3b'])
1391
def test_unrelated(self):
1392
tree = self.setup_ac_tree()
1393
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1394
self.assertEqual(old, ['1a', '2a', '3a'])
1395
self.assertEqual(new, ['1c', '2c', '3c'])
1397
def test_show_branch_change(self):
1398
tree = self.setup_ab_tree()
1400
log.show_branch_change(tree.branch, s, 3, '3a')
1401
self.assertContainsRe(s.getvalue(),
1402
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1403
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1405
def test_show_branch_change_no_change(self):
1406
tree = self.setup_ab_tree()
1408
log.show_branch_change(tree.branch, s, 3, '3b')
1409
self.assertEqual(s.getvalue(),
1410
'Nothing seems to have changed\n')
1412
def test_show_branch_change_no_old(self):
1413
tree = self.setup_ab_tree()
1415
log.show_branch_change(tree.branch, s, 2, '2b')
1416
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1417
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1419
def test_show_branch_change_no_new(self):
1420
tree = self.setup_ab_tree()
1421
tree.branch.set_last_revision_info(2, '2b')
1423
log.show_branch_change(tree.branch, s, 3, '3b')
1424
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1425
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1429
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1432
TestCaseForLogFormatter.setUp(self)
1433
log.properties_handler_registry.register(
1434
'bugs_properties_handler',
1435
log._bugs_properties_handler)
1437
def make_commits_with_bugs(self):
1438
"""Helper method for LogFormatter tests"""
1439
tree = self.make_branch_and_tree(u'.')
1440
self.build_tree(['a', 'b'])
1442
self.wt_commit(tree, 'simple log message', rev_id='a1',
1443
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'})
1452
def test_long_bugs(self):
1453
tree = self.make_commits_with_bugs()
1454
self.assertFormatterResult("""\
1455
------------------------------------------------------------
1457
fixes bug(s): test://bug/id test://bug/2
1458
author: Joe Bar <joe@bar.com>
1459
committer: Joe Foo <joe@foo.com>
1461
timestamp: Tue 2005-11-22 00:00:01 +0000
1466
------------------------------------------------------------
1468
fixes bug(s): test://bug/id
1469
committer: Joe Foo <joe@foo.com>
1471
timestamp: Tue 2005-11-22 00:00:00 +0000
1475
tree.branch, log.LongLogFormatter)
1477
def test_short_bugs(self):
1478
tree = self.make_commits_with_bugs()
1479
self.assertFormatterResult("""\
1480
2 Joe Bar\t2005-11-22
1481
fixes bug(s): test://bug/id test://bug/2
1486
1 Joe Foo\t2005-11-22
1487
fixes bug(s): test://bug/id
1491
tree.branch, log.ShortLogFormatter)
1493
def test_wrong_bugs_property(self):
1494
tree = self.make_branch_and_tree(u'.')
1495
self.build_tree(['foo'])
1496
self.wt_commit(tree, 'simple log message', rev_id='a1',
1497
revprops={'bugs': 'test://bug/id invalid_value'})
1498
self.assertFormatterResult("""\
1499
1 Joe Foo\t2005-11-22
1503
tree.branch, log.ShortLogFormatter)
1505
def test_bugs_handler_present(self):
1506
self.properties_handler_registry.get('bugs_properties_handler')
270
timestamp: Wed 2005-11-23 12:08:27 +1000