13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
20
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.
22
from bzrlib.tests import BzrTestBase, TestCaseWithTransport
23
from bzrlib.log import (show_log,
29
from bzrlib.branch import Branch
30
from bzrlib.errors import InvalidRevisionNumber
33
class _LogEntry(object):
34
# should probably move into bzrlib.log?
38
class LogCatcher(LogFormatter):
39
"""Pull log messages into list rather than displaying them.
41
For ease of testing we save log messages here rather than actually
42
formatting them, so that we can precisely check the result without
43
being too dependent on the exact formatting.
45
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):
48
super(LogCatcher, self).__init__(to_file=None)
51
def show(self, revno, rev, delta):
59
class SimpleLogTest(TestCaseWithTransport):
143
61
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).
62
"""Check the filenames touched by a delta are as expected."""
149
63
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
150
# By default we expect an empty list
151
64
expected = kw.get(n, [])
66
# tests are written with unix paths; fix them up for windows
68
# expected = [x.replace('/', os.sep) for x in expected]
152
70
# strip out only the path components
153
71
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)
72
self.assertEquals(expected, got)
74
def test_cur_revno(self):
75
wt = self.make_branch_and_tree('.')
79
wt.commit('empty commit')
80
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
81
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
82
start_revision=2, end_revision=1)
83
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
84
start_revision=1, end_revision=2)
85
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
86
start_revision=0, end_revision=2)
87
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
88
start_revision=1, end_revision=0)
89
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
90
start_revision=-1, end_revision=1)
91
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
92
start_revision=1, end_revision=-1)
94
def test_cur_revno(self):
95
wt = self.make_branch_and_tree('.')
99
wt.commit('empty commit')
100
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
101
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
102
start_revision=2, end_revision=1)
103
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
104
start_revision=1, end_revision=2)
105
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
106
start_revision=0, end_revision=2)
107
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
108
start_revision=1, end_revision=0)
109
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
110
start_revision=-1, end_revision=1)
111
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
112
start_revision=1, end_revision=-1)
114
def test_simple_log(self):
115
eq = self.assertEquals
117
wt = self.make_branch_and_tree('.')
185
self.assertEqual([], lf.revisions)
187
def test_empty_commit(self):
188
wt = self.make_branch_and_tree('.')
190
125
wt.commit('empty commit')
191
126
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)
127
show_log(b, lf, verbose=True)
129
eq(lf.logs[0].revno, 1)
130
eq(lf.logs[0].rev.message, 'empty commit')
132
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
135
self.build_tree(['hello'])
204
wt.commit('add one file',
205
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
206
u'<test@example.com>')
137
wt.commit('add one file')
140
# log using regular thing
141
show_log(b, LongLogFormatter(lf))
143
for l in lf.readlines():
146
# get log as data structure
207
147
lf = LogCatcher()
208
log.show_log(wt.branch, lf, verbose=True)
209
self.assertEqual(2, len(lf.revisions))
148
show_log(b, lf, verbose=True)
150
self.log('log entries:')
151
for logentry in lf.logs:
152
self.log('%4d %s' % (logentry.revno, logentry.rev.message))
210
154
# 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')
155
logentry = lf.logs[0]
156
eq(logentry.revno, 2)
157
eq(logentry.rev.message, 'add one file')
159
self.log('log 2 delta: %r' % d)
160
# self.checkDelta(d, added=['hello'])
162
# commit a log message with control characters
163
msg = "All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
164
self.log("original commit message: %r", msg)
221
166
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)
167
show_log(b, lf, verbose=True)
168
committed_msg = lf.logs[0].rev.message
169
self.log("escaped commit message: %r", committed_msg)
170
self.assert_(msg != committed_msg)
171
self.assert_(len(committed_msg) > len(msg))
230
def test_commit_message_without_control_chars(self):
231
wt = self.make_branch_and_tree('.')
173
# Check that log message with only XML-valid characters isn't
232
174
# escaped. As ElementTree apparently does some kind of
233
175
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
234
176
# included in the test commit message, even though they are
235
177
# valid XML 1.0 characters.
236
178
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
179
self.log("original commit message: %r", msg)
238
181
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):
182
show_log(b, lf, verbose=True)
183
committed_msg = lf.logs[0].rev.message
184
self.log("escaped commit message: %r", committed_msg)
185
self.assert_(msg == committed_msg)
285
187
def test_trailing_newlines(self):
286
188
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
191
open('a', 'wb').write('hello moto\n')
193
wt.commit('simple log message', rev_id='a1'
194
, timestamp=1132586655.459960938, timezone=-6*3600
195
, committer='Joe Foo <joe@foo.com>')
196
open('b', 'wb').write('goodbye\n')
198
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
199
, timestamp=1132586842.411175966, timezone=-6*3600
200
, committer='Joe Foo <joe@foo.com>')
202
open('c', 'wb').write('just another manic monday\n')
204
wt.commit('single line with trailing newline\n', rev_id='a3'
205
, timestamp=1132587176.835228920, timezone=-6*3600
206
, committer = 'Joe Foo <joe@foo.com>')
209
lf = ShortLogFormatter(to_file=sio)
211
self.assertEquals(sio.getvalue(), """\
212
3 Joe Foo\t2005-11-21
290
213
single line with trailing newline
292
2 Joe Foo\t2005-11-22
215
2 Joe Foo\t2005-11-21
297
1 Joe Foo\t2005-11-22
220
1 Joe Foo\t2005-11-21
298
221
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):
226
lf = LongLogFormatter(to_file=sio)
228
self.assertEquals(sio.getvalue(), """\
229
------------------------------------------------------------
231
committer: Joe Foo <joe@foo.com>
233
timestamp: Mon 2005-11-21 09:32:56 -0600
235
single line with trailing newline
236
------------------------------------------------------------
238
committer: Joe Foo <joe@foo.com>
240
timestamp: Mon 2005-11-21 09:27:22 -0600
245
------------------------------------------------------------
247
committer: Joe Foo <joe@foo.com>
249
timestamp: Mon 2005-11-21 09:24:15 -0600
411
254
def test_verbose_log(self):
412
255
"""Verbose log includes changed files
416
wt = self.make_standard_commit('test_verbose_log', authors=[])
417
self.assertFormatterResult('''\
259
wt = self.make_branch_and_tree('.')
261
self.build_tree(['a'])
263
# XXX: why does a longer nick show up?
264
b.nick = 'test_verbose_log'
265
wt.commit(message='add a',
266
timestamp=1132711707,
268
committer='Lorem Ipsum <test@example.com>')
269
logfile = file('out.tmp', 'w+')
270
formatter = LongLogFormatter(to_file=logfile)
271
show_log(b, formatter, verbose=True)
274
log_contents = logfile.read()
275
self.assertEqualDiff(log_contents, '''\
418
276
------------------------------------------------------------
420
278
committer: Lorem Ipsum <test@example.com>
421
279
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):
280
timestamp: Wed 2005-11-23 12:08:27 +1000
800
287
def test_line_log(self):
801
288
"""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
292
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)
294
self.build_tree(['a'])
296
b.nick = 'test-line-log'
297
wt.commit(message='add a',
298
timestamp=1132711707,
300
committer='Line-Log-Formatter Tester <test@line.log>')
301
logfile = file('out.tmp', 'w+')
302
formatter = LineLogFormatter(to_file=logfile)
303
show_log(b, formatter)
306
log_contents = logfile.read()
307
self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
886
309
def make_tree_with_commits(self):
887
310
"""Create a tree with well-known revision ids"""
888
311
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')
312
wt.commit('commit one', rev_id='1')
313
wt.commit('commit two', rev_id='2')
314
wt.commit('commit three', rev_id='3')
892
315
mainline_revs = [None, '1', '2', '3']
893
316
rev_nos = {'1': 1, '2': 2, '3': 3}
894
317
return mainline_revs, rev_nos, wt
319
def pseudo_merge(self, source, target):
320
revision_id = source.last_revision()
321
target.branch.fetch(source.branch, revision_id)
322
target.add_pending_merge(revision_id)
896
324
def make_tree_with_merges(self):
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')
901
wt.merge_from_branch(tree2.branch)
902
self.wt_commit(wt, 'four-b', rev_id='4b')
328
tree2.commit('four-a', rev_id='4a')
329
self.pseudo_merge(tree2, wt)
330
wt.commit('four-b', rev_id='4b')
903
331
mainline_revs.append('4b')
904
332
rev_nos['4b'] = 4
906
333
return mainline_revs, rev_nos, wt
908
def make_branch_with_many_merges(self):
335
def make_tree_with_many_merges(self):
909
336
"""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()
337
wt = self.make_branch_and_tree('tree1')
338
wt.commit('commit one', rev_id='1')
339
wt.commit('commit two', rev_id='2')
340
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
341
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
342
tree3.commit('commit three a', rev_id='3a')
343
self.pseudo_merge(tree3, tree2)
344
tree2.commit('commit three b', rev_id='3b')
345
self.pseudo_merge(tree2, wt)
346
wt.commit('commit three c', rev_id='3c')
347
tree2.commit('four-a', rev_id='4a')
348
self.pseudo_merge(tree2, wt)
349
wt.commit('four-b', rev_id='4b')
938
350
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()
351
rev_nos = {'1': 1, '2': 2, '3c': 3, '4b': 4}
352
return mainline_revs, rev_nos, wt
951
354
def test_get_view_revisions_forward(self):
952
355
"""Test the get_view_revisions method"""
953
356
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))
357
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
359
self.assertEqual(revisions, [('1', 1, 0), ('2', 2, 0), ('3', 3, 0)])
360
revisions2 = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
361
'forward', include_merges=False))
963
362
self.assertEqual(revisions, revisions2)
965
364
def test_get_view_revisions_reverse(self):
966
365
"""Test the get_view_revisions with reverse"""
967
366
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))
367
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
369
self.assertEqual(revisions, [('3', 3, 0), ('2', 2, 0), ('1', 1, 0), ])
370
revisions2 = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
371
'reverse', include_merges=False))
977
372
self.assertEqual(revisions, revisions2)
979
374
def test_get_view_revisions_merge(self):
980
375
"""Test get_view_revisions when there are merges"""
981
376
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),
377
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
379
self.assertEqual(revisions, [('1', 1, 0), ('2', 2, 0), ('3', 3, 0),
380
('4b', 4, 0), ('4a', None, 1)])
381
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
382
'forward', include_merges=False))
383
self.assertEqual(revisions, [('1', 1, 0), ('2', 2, 0), ('3', 3, 0),
996
386
def test_get_view_revisions_merge_reverse(self):
997
387
"""Test get_view_revisions in reverse when there are merges"""
998
388
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),
389
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
391
self.assertEqual(revisions, [('4b', 4, 0), ('4a', None, 1),
392
('3', 3, 0), ('2', 2, 0), ('1', 1, 0)])
393
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
394
'reverse', include_merges=False))
395
self.assertEqual(revisions, [('4b', 4, 0), ('3', 3, 0), ('2', 2, 0),
1013
398
def test_get_view_revisions_merge2(self):
1014
399
"""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')
400
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
401
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
403
expected = [('1', 1, 0), ('2', 2, 0), ('3c', 3, 0), ('3a', None, 1),
404
('3b', None, 1), ('4b', 4, 0), ('4a', None, 1)]
405
self.assertEqual(revisions, expected)
406
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
407
'forward', include_merges=False))
408
self.assertEqual(revisions, [('1', 1, 0), ('2', 2, 0), ('3c', 3, 0),