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 import log
21
from bzrlib.tests import BzrTestBase, TestCaseWithTransport
22
from bzrlib.log import (show_log,
29
from bzrlib.branch import Branch
30
from bzrlib.errors import InvalidRevisionNumber
33
class LogCatcher(LogFormatter):
34
"""Pull log messages into list rather than displaying them.
36
For ease of testing we save log messages here rather than actually
37
formatting them, so that we can precisely check the result without
38
being too dependent on the exact formatting.
40
We should also test the LogFormatter.
127
supports_merge_revisions = True
128
43
supports_delta = True
132
def __init__(self, *args, **kwargs):
133
kwargs.update(dict(to_file=None))
134
super(LogCatcher, self).__init__(*args, **kwargs)
46
super(LogCatcher, self).__init__(to_file=None)
137
49
def log_revision(self, revision):
138
self.revisions.append(revision)
141
class TestShowLog(tests.TestCaseWithTransport):
50
self.logs.append(revision)
53
class SimpleLogTest(TestCaseWithTransport):
143
55
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).
56
"""Check the filenames touched by a delta are as expected."""
149
57
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
150
# By default we expect an empty list
151
58
expected = kw.get(n, [])
60
# tests are written with unix paths; fix them up for windows
62
# expected = [x.replace('/', os.sep) for x in expected]
152
64
# strip out only the path components
153
65
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)
66
self.assertEquals(expected, got)
162
68
def test_cur_revno(self):
163
69
wt = self.make_branch_and_tree('.')
167
73
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):
74
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
75
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
76
start_revision=2, end_revision=1)
77
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
78
start_revision=1, end_revision=2)
79
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
80
start_revision=0, end_revision=2)
81
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
82
start_revision=1, end_revision=0)
83
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
84
start_revision=-1, end_revision=1)
85
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
86
start_revision=1, end_revision=-1)
88
def test_simple_log(self):
89
eq = self.assertEquals
180
91
wt = self.make_branch_and_tree('.')
183
log.show_log(wt.branch, lf)
185
self.assertEqual([], lf.revisions)
187
def test_empty_commit(self):
188
wt = self.make_branch_and_tree('.')
190
99
wt.commit('empty commit')
191
100
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)
101
show_log(b, lf, verbose=True)
103
eq(lf.logs[0].revno, '1')
104
eq(lf.logs[0].rev.message, 'empty commit')
106
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
109
self.build_tree(['hello'])
204
wt.commit('add one file',
205
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
206
u'<test@example.com>')
111
wt.commit('add one file')
114
# log using regular thing
115
show_log(b, LongLogFormatter(lf))
117
for l in lf.readlines():
120
# get log as data structure
207
121
lf = LogCatcher()
208
log.show_log(wt.branch, lf, verbose=True)
209
self.assertEqual(2, len(lf.revisions))
122
show_log(b, lf, verbose=True)
124
self.log('log entries:')
125
for logentry in lf.logs:
126
self.log('%4s %s' % (logentry.revno, logentry.rev.message))
210
128
# 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')
129
logentry = lf.logs[0]
130
eq(logentry.revno, '2')
131
eq(logentry.rev.message, 'add one file')
133
self.log('log 2 delta: %r' % d)
134
# self.checkDelta(d, added=['hello'])
136
# commit a log message with control characters
137
msg = "All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
138
self.log("original commit message: %r", msg)
221
140
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)
141
show_log(b, lf, verbose=True)
142
committed_msg = lf.logs[0].rev.message
143
self.log("escaped commit message: %r", committed_msg)
144
self.assert_(msg != committed_msg)
145
self.assert_(len(committed_msg) > len(msg))
230
def test_commit_message_without_control_chars(self):
231
wt = self.make_branch_and_tree('.')
147
# Check that log message with only XML-valid characters isn't
232
148
# escaped. As ElementTree apparently does some kind of
233
149
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
234
150
# included in the test commit message, even though they are
235
151
# valid XML 1.0 characters.
236
152
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
153
self.log("original commit message: %r", msg)
238
155
lf = LogCatcher()
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):
156
show_log(b, lf, verbose=True)
157
committed_msg = lf.logs[0].rev.message
158
self.log("escaped commit message: %r", committed_msg)
159
self.assert_(msg == committed_msg)
285
161
def test_trailing_newlines(self):
286
162
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
165
open('a', 'wb').write('hello moto\n')
167
wt.commit('simple log message', rev_id='a1'
168
, timestamp=1132586655.459960938, timezone=-6*3600
169
, committer='Joe Foo <joe@foo.com>')
170
open('b', 'wb').write('goodbye\n')
172
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
173
, timestamp=1132586842.411175966, timezone=-6*3600
174
, committer='Joe Foo <joe@foo.com>')
176
open('c', 'wb').write('just another manic monday\n')
178
wt.commit('single line with trailing newline\n', rev_id='a3'
179
, timestamp=1132587176.835228920, timezone=-6*3600
180
, committer = 'Joe Foo <joe@foo.com>')
183
lf = ShortLogFormatter(to_file=sio)
185
self.assertEquals(sio.getvalue(), """\
186
3 Joe Foo\t2005-11-21
290
187
single line with trailing newline
292
2 Joe Foo\t2005-11-22
189
2 Joe Foo\t2005-11-21
297
1 Joe Foo\t2005-11-22
194
1 Joe Foo\t2005-11-21
298
195
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):
200
lf = LongLogFormatter(to_file=sio)
202
self.assertEquals(sio.getvalue(), """\
203
------------------------------------------------------------
205
committer: Joe Foo <joe@foo.com>
207
timestamp: Mon 2005-11-21 09:32:56 -0600
209
single line with trailing newline
210
------------------------------------------------------------
212
committer: Joe Foo <joe@foo.com>
214
timestamp: Mon 2005-11-21 09:27:22 -0600
219
------------------------------------------------------------
221
committer: Joe Foo <joe@foo.com>
223
timestamp: Mon 2005-11-21 09:24:15 -0600
411
228
def test_verbose_log(self):
412
229
"""Verbose log includes changed files
416
wt = self.make_standard_commit('test_verbose_log', authors=[])
417
self.assertFormatterResult('''\
233
wt = self.make_branch_and_tree('.')
235
self.build_tree(['a'])
237
# XXX: why does a longer nick show up?
238
b.nick = 'test_verbose_log'
239
wt.commit(message='add a',
240
timestamp=1132711707,
242
committer='Lorem Ipsum <test@example.com>')
243
logfile = file('out.tmp', 'w+')
244
formatter = LongLogFormatter(to_file=logfile)
245
show_log(b, formatter, verbose=True)
248
log_contents = logfile.read()
249
self.assertEqualDiff(log_contents, '''\
418
250
------------------------------------------------------------
420
252
committer: Lorem Ipsum <test@example.com>
421
253
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):
254
timestamp: Wed 2005-11-23 12:08:27 +1000
800
261
def test_line_log(self):
801
262
"""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
266
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)
268
self.build_tree(['a'])
270
b.nick = 'test-line-log'
271
wt.commit(message='add a',
272
timestamp=1132711707,
274
committer='Line-Log-Formatter Tester <test@line.log>')
275
logfile = file('out.tmp', 'w+')
276
formatter = LineLogFormatter(to_file=logfile)
277
show_log(b, formatter)
280
log_contents = logfile.read()
281
self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
283
def test_short_log_with_merges(self):
284
wt = self.make_branch_and_memory_tree('.')
288
wt.commit('rev-1', rev_id='rev-1',
289
timestamp=1132586655, timezone=36000,
290
committer='Joe Foo <joe@foo.com>')
291
wt.commit('rev-merged', rev_id='rev-2a',
292
timestamp=1132586700, timezone=36000,
293
committer='Joe Foo <joe@foo.com>')
294
wt.set_parent_ids(['rev-1', 'rev-2a'])
295
wt.branch.set_last_revision_info(1, 'rev-1')
296
wt.commit('rev-2', rev_id='rev-2b',
297
timestamp=1132586800, timezone=36000,
298
committer='Joe Foo <joe@foo.com>')
300
formatter = ShortLogFormatter(to_file=logfile)
301
show_log(wt.branch, formatter)
303
self.assertEqualDiff("""\
304
2 Joe Foo\t2005-11-22 [merge]
307
1 Joe Foo\t2005-11-22
310
""", logfile.getvalue())
886
314
def make_tree_with_commits(self):
887
315
"""Create a tree with well-known revision ids"""
888
316
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')
317
wt.commit('commit one', rev_id='1')
318
wt.commit('commit two', rev_id='2')
319
wt.commit('commit three', rev_id='3')
892
320
mainline_revs = [None, '1', '2', '3']
893
321
rev_nos = {'1': 1, '2': 2, '3': 3}
894
322
return mainline_revs, rev_nos, wt
897
325
"""Create a tree with well-known revision ids and a merge"""
898
326
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
899
327
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
900
self.wt_commit(tree2, 'four-a', rev_id='4a')
328
tree2.commit('four-a', rev_id='4a')
901
329
wt.merge_from_branch(tree2.branch)
902
self.wt_commit(wt, 'four-b', rev_id='4b')
330
wt.commit('four-b', rev_id='4b')
903
331
mainline_revs.append('4b')
904
332
rev_nos['4b'] = 4
906
334
return mainline_revs, rev_nos, wt
908
def make_branch_with_many_merges(self):
336
def make_tree_with_many_merges(self):
909
337
"""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()
338
wt = self.make_branch_and_tree('tree1')
339
wt.commit('commit one', rev_id='1')
340
wt.commit('commit two', rev_id='2')
341
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
342
tree3.commit('commit three a', rev_id='3a')
343
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
344
tree2.merge_from_branch(tree3.branch)
345
tree2.commit('commit three b', rev_id='3b')
346
wt.merge_from_branch(tree2.branch)
347
wt.commit('commit three c', rev_id='3c')
348
tree2.commit('four-a', rev_id='4a')
349
wt.merge_from_branch(tree2.branch)
350
wt.commit('four-b', rev_id='4b')
938
351
mainline_revs = [None, '1', '2', '3c', '4b']
939
352
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
940
353
full_rev_nos_for_reference = {
943
'3a': '2.1.1', #first commit tree 3
944
'3b': '2.2.1', # first commit tree 2
356
'3a': '2.2.1', #first commit tree 3
357
'3b': '2.1.1', # first commit tree 2
945
358
'3c': '3', #merges 3b to main
946
'4a': '2.2.2', # second commit tree 2
359
'4a': '2.1.2', # second commit tree 2
947
360
'4b': '4', # merges 4a to main
949
return mainline_revs, rev_nos, builder.get_branch()
362
return mainline_revs, rev_nos, wt
951
364
def test_get_view_revisions_forward(self):
952
365
"""Test the get_view_revisions method"""
953
366
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'))
367
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
958
369
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))
371
revisions2 = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
372
'forward', include_merges=False))
963
373
self.assertEqual(revisions, revisions2)
965
375
def test_get_view_revisions_reverse(self):
966
376
"""Test the get_view_revisions with reverse"""
967
377
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'))
378
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
972
380
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))
382
revisions2 = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
383
'reverse', include_merges=False))
977
384
self.assertEqual(revisions, revisions2)
979
386
def test_get_view_revisions_merge(self):
980
387
"""Test get_view_revisions when there are merges"""
981
388
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),
389
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
391
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
392
('4b', '4', 0), ('4a', '3.1.1', 1)],
394
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
395
'forward', include_merges=False))
396
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
996
400
def test_get_view_revisions_merge_reverse(self):
997
401
"""Test get_view_revisions in reverse when there are merges"""
998
402
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'))
403
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
1003
405
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))
406
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
408
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
409
'reverse', include_merges=False))
1009
410
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1013
414
def test_get_view_revisions_merge2(self):
1014
415
"""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'))
416
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
417
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
1020
419
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1021
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
420
('3a', '2.2.1', 1), ('3b', '2.1.1', 1), ('4b', '4', 0),
1023
422
self.assertEqual(expected, revisions)
1024
revisions = list(self._get_view_revisions(
1025
mainline_revs, rev_nos, b, 'forward',
1026
include_merges=False))
423
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
424
'forward', include_merges=False))
1027
425
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)
430
class TestGetRevisionsTouchingFileID(TestCaseWithTransport):
1070
432
def create_tree_with_single_merge(self):
1071
433
"""Create a branch with a moderate layout.
1195
556
def test_file_id_f3(self):
1196
557
tree = self.create_tree_with_single_merge()
1197
558
# 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
559
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')