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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
from cStringIO import StringIO
20
from bzrlib import log, registry
21
from bzrlib.tests import TestCase, TestCaseWithTransport
22
from bzrlib.log import (show_log,
29
from bzrlib.branch import Branch
30
from bzrlib.errors import (
32
InvalidRevisionNumber,
34
from bzrlib.revision import Revision
35
from bzrlib.revisionspec import (
41
class TestCaseWithoutPropsHandler(TestCaseWithTransport):
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):
44
super(TestCaseWithoutPropsHandler, self).setUp()
53
super(TestCaseForLogFormatter, self).setUp()
45
54
# keep a reference to the "current" custom prop. handler registry
46
self.properties_handler_registry = \
47
log.properties_handler_registry
48
# clean up the registry in log
55
self.properties_handler_registry = log.properties_handler_registry
56
# Use a clean registry for log
49
57
log.properties_handler_registry = registry.Registry()
52
super(TestCaseWithoutPropsHandler, self)._cleanup()
53
# restore the custom properties handler registry
54
log.properties_handler_registry = \
55
self.properties_handler_registry
58
class LogCatcher(LogFormatter):
59
"""Pull log messages into list rather than displaying them.
61
For ease of testing we save log messages here rather than actually
62
formatting them, so that we can precisely check the result without
63
being too dependent on the exact formatting.
65
We should also test the LogFormatter.
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.
127
supports_merge_revisions = True
68
128
supports_delta = True
71
super(LogCatcher, self).__init__(to_file=None)
132
def __init__(self, *args, **kwargs):
133
kwargs.update(dict(to_file=None))
134
super(LogCatcher, self).__init__(*args, **kwargs)
74
137
def log_revision(self, revision):
75
self.logs.append(revision)
78
class TestShowLog(TestCaseWithTransport):
138
self.revisions.append(revision)
141
class TestShowLog(tests.TestCaseWithTransport):
80
143
def checkDelta(self, delta, **kw):
81
"""Check the filenames touched by a delta are as expected."""
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).
82
149
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
150
# By default we expect an empty list
83
151
expected = kw.get(n, [])
84
152
# strip out only the path components
85
153
got = [x[0] for x in getattr(delta, n)]
86
self.assertEquals(expected, got)
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)
88
162
def test_cur_revno(self):
89
163
wt = self.make_branch_and_tree('.')
93
167
wt.commit('empty commit')
94
show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
95
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
96
start_revision=2, end_revision=1)
97
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
98
start_revision=1, end_revision=2)
99
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
100
start_revision=0, end_revision=2)
101
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
102
start_revision=1, end_revision=0)
103
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
104
start_revision=-1, end_revision=1)
105
self.assertRaises(InvalidRevisionNumber, show_log, b, lf,
106
start_revision=1, end_revision=-1)
108
def test_simple_log(self):
109
eq = self.assertEquals
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):
111
180
wt = self.make_branch_and_tree('.')
114
182
lf = LogCatcher()
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('.')
119
190
wt.commit('empty commit')
120
191
lf = LogCatcher()
121
show_log(b, lf, verbose=True)
123
eq(lf.logs[0].revno, '1')
124
eq(lf.logs[0].rev.message, 'empty commit')
126
self.log('log delta: %r' % d)
192
log.show_log(wt.branch, lf, verbose=True)
194
self.assertEqual(1, len(revs))
195
self.assertEqual('1', revs[0].revno)
196
self.assertEqual('empty commit', revs[0].rev.message)
197
self.checkDelta(revs[0].delta)
199
def test_simple_commit(self):
200
wt = self.make_branch_and_tree('.')
201
wt.commit('empty commit')
129
202
self.build_tree(['hello'])
131
204
wt.commit('add one file',
132
205
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
133
206
u'<test@example.com>')
135
lf = self.make_utf8_encoded_stringio()
136
# log using regular thing
137
show_log(b, LongLogFormatter(lf))
139
for l in lf.readlines():
142
# get log as data structure
143
207
lf = LogCatcher()
144
show_log(b, lf, verbose=True)
146
self.log('log entries:')
147
for logentry in lf.logs:
148
self.log('%4s %s' % (logentry.revno, logentry.rev.message))
208
log.show_log(wt.branch, lf, verbose=True)
209
self.assertEqual(2, len(lf.revisions))
150
210
# first one is most recent
151
logentry = lf.logs[0]
152
eq(logentry.revno, '2')
153
eq(logentry.rev.message, 'add one file')
155
self.log('log 2 delta: %r' % d)
156
self.checkDelta(d, added=['hello'])
158
# commit a log message with control characters
159
msg = "All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
160
self.log("original commit message: %r", msg)
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')
162
221
lf = LogCatcher()
163
show_log(b, lf, verbose=True)
164
committed_msg = lf.logs[0].rev.message
165
self.log("escaped commit message: %r", committed_msg)
166
self.assert_(msg != committed_msg)
167
self.assert_(len(committed_msg) > len(msg))
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)
169
# Check that log message with only XML-valid characters isn't
230
def test_commit_message_without_control_chars(self):
231
wt = self.make_branch_and_tree('.')
170
232
# escaped. As ElementTree apparently does some kind of
171
233
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
172
234
# included in the test commit message, even though they are
173
235
# valid XML 1.0 characters.
174
236
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
175
self.log("original commit message: %r", msg)
177
238
lf = LogCatcher()
178
show_log(b, lf, verbose=True)
179
committed_msg = lf.logs[0].rev.message
180
self.log("escaped commit message: %r", committed_msg)
181
self.assert_(msg == committed_msg)
239
log.show_log(wt.branch, lf, verbose=True)
240
committed_msg = lf.revisions[0].rev.message
241
self.assertEqual(msg, committed_msg)
183
243
def test_deltas_in_merge_revisions(self):
184
244
"""Check deltas created for both mainline and merge revisions"""
185
eq = self.assertEquals
186
245
wt = self.make_branch_and_tree('parent')
187
246
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
201
260
lf = LogCatcher()
202
261
lf.supports_merge_revisions = True
203
show_log(b, lf, verbose=True)
205
logentry = lf.logs[0]
206
eq(logentry.revno, '2')
207
eq(logentry.rev.message, 'merge child branch')
209
self.checkDelta(d, removed=['file1'], modified=['file2'])
210
logentry = lf.logs[1]
211
eq(logentry.revno, '1.1.1')
212
eq(logentry.rev.message, 'remove file1 and modify file2')
214
self.checkDelta(d, removed=['file1'], modified=['file2'])
215
logentry = lf.logs[2]
216
eq(logentry.revno, '1')
217
eq(logentry.rev.message, 'add file1 and file2')
219
self.checkDelta(d, added=['file1', 'file2'])
221
def test_merges_nonsupporting_formatter(self):
222
"""Tests that show_log will raise if the formatter doesn't
223
support merge revisions."""
224
wt = self.make_branch_and_memory_tree('.')
228
wt.commit('rev-1', rev_id='rev-1',
229
timestamp=1132586655, timezone=36000,
230
committer='Joe Foo <joe@foo.com>')
231
wt.commit('rev-merged', rev_id='rev-2a',
232
timestamp=1132586700, timezone=36000,
233
committer='Joe Foo <joe@foo.com>')
234
wt.set_parent_ids(['rev-1', 'rev-2a'])
235
wt.branch.set_last_revision_info(1, 'rev-1')
236
wt.commit('rev-2', rev_id='rev-2b',
237
timestamp=1132586800, timezone=36000,
238
committer='Joe Foo <joe@foo.com>')
239
logfile = self.make_utf8_encoded_stringio()
240
formatter = ShortLogFormatter(to_file=logfile)
243
revspec = RevisionSpec.from_string('1.1.1')
244
rev = revspec.in_history(wtb)
245
self.assertRaises(BzrCommandError, show_log, wtb, lf,
246
start_revision=rev, end_revision=rev)
251
def make_commits_with_trailing_newlines(wt):
252
"""Helper method for LogFormatter tests"""
255
open('a', 'wb').write('hello moto\n')
257
wt.commit('simple log message', rev_id='a1',
258
timestamp=1132586655.459960938, timezone=-6*3600,
259
committer='Joe Foo <joe@foo.com>')
260
open('b', 'wb').write('goodbye\n')
262
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
263
timestamp=1132586842.411175966, timezone=-6*3600,
264
committer='Joe Foo <joe@foo.com>',
265
author='Joe Bar <joe@bar.com>')
267
open('c', 'wb').write('just another manic monday\n')
269
wt.commit('single line with trailing newline\n', rev_id='a3',
270
timestamp=1132587176.835228920, timezone=-6*3600,
271
committer = 'Joe Foo <joe@foo.com>')
275
def normalize_log(log):
276
"""Replaces the variable lines of logs with fixed lines"""
277
author = 'author: Dolor Sit <test@example.com>'
278
committer = 'committer: Lorem Ipsum <test@example.com>'
279
lines = log.splitlines(True)
280
for idx,line in enumerate(lines):
281
stripped_line = line.lstrip()
282
indent = ' ' * (len(line) - len(stripped_line))
283
if stripped_line.startswith('author:'):
284
lines[idx] = indent + author + '\n'
285
elif stripped_line.startswith('committer:'):
286
lines[idx] = indent + committer + '\n'
287
elif stripped_line.startswith('timestamp:'):
288
lines[idx] = indent + 'timestamp: Just now\n'
289
return ''.join(lines)
292
class TestShortLogFormatter(TestCaseWithTransport):
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):
294
285
def test_trailing_newlines(self):
295
286
wt = self.make_branch_and_tree('.')
296
b = make_commits_with_trailing_newlines(wt)
297
sio = self.make_utf8_encoded_stringio()
298
lf = ShortLogFormatter(to_file=sio)
300
self.assertEqualDiff(sio.getvalue(), """\
301
3 Joe Foo\t2005-11-21
287
b = self.make_commits_with_trailing_newlines(wt)
288
self.assertFormatterResult("""\
289
3 Joe Foo\t2005-11-22
302
290
single line with trailing newline
304
2 Joe Bar\t2005-11-21
292
2 Joe Foo\t2005-11-22
309
1 Joe Foo\t2005-11-21
297
1 Joe Foo\t2005-11-22
310
298
simple log message
301
b, log.ShortLogFormatter)
314
303
def test_short_log_with_merges(self):
315
wt = self.make_branch_and_memory_tree('.')
319
wt.commit('rev-1', rev_id='rev-1',
320
timestamp=1132586655, timezone=36000,
321
committer='Joe Foo <joe@foo.com>')
322
wt.commit('rev-merged', rev_id='rev-2a',
323
timestamp=1132586700, timezone=36000,
324
committer='Joe Foo <joe@foo.com>')
325
wt.set_parent_ids(['rev-1', 'rev-2a'])
326
wt.branch.set_last_revision_info(1, 'rev-1')
327
wt.commit('rev-2', rev_id='rev-2b',
328
timestamp=1132586800, timezone=36000,
329
committer='Joe Foo <joe@foo.com>')
330
logfile = self.make_utf8_encoded_stringio()
331
formatter = ShortLogFormatter(to_file=logfile)
332
show_log(wt.branch, formatter)
333
self.assertEqualDiff(logfile.getvalue(), """\
334
2 Joe Foo\t2005-11-22 [merge]
337
1 Joe Foo\t2005-11-22
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)
344
361
def test_short_log_single_merge_revision(self):
345
wt = self.make_branch_and_memory_tree('.')
349
wt.commit('rev-1', rev_id='rev-1',
350
timestamp=1132586655, timezone=36000,
351
committer='Joe Foo <joe@foo.com>')
352
wt.commit('rev-merged', rev_id='rev-2a',
353
timestamp=1132586700, timezone=36000,
354
committer='Joe Foo <joe@foo.com>')
355
wt.set_parent_ids(['rev-1', 'rev-2a'])
356
wt.branch.set_last_revision_info(1, 'rev-1')
357
wt.commit('rev-2', rev_id='rev-2b',
358
timestamp=1132586800, timezone=36000,
359
committer='Joe Foo <joe@foo.com>')
360
logfile = self.make_utf8_encoded_stringio()
361
formatter = ShortLogFormatter(to_file=logfile)
362
revspec = RevisionSpec.from_string('1.1.1')
364
rev = revspec.in_history(wtb)
365
show_log(wtb, formatter, start_revision=rev, end_revision=rev)
366
self.assertEqualDiff(logfile.getvalue(), """\
367
1.1.1 Joe Foo\t2005-11-22
375
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
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):
377
411
def test_verbose_log(self):
378
412
"""Verbose log includes changed files
382
wt = self.make_branch_and_tree('.')
384
self.build_tree(['a'])
386
# XXX: why does a longer nick show up?
387
b.nick = 'test_verbose_log'
388
wt.commit(message='add a',
389
timestamp=1132711707,
391
committer='Lorem Ipsum <test@example.com>')
392
logfile = file('out.tmp', 'w+')
393
formatter = LongLogFormatter(to_file=logfile)
394
show_log(b, formatter, verbose=True)
397
log_contents = logfile.read()
398
self.assertEqualDiff(log_contents, '''\
416
wt = self.make_standard_commit('test_verbose_log', authors=[])
417
self.assertFormatterResult('''\
399
418
------------------------------------------------------------
401
420
committer: Lorem Ipsum <test@example.com>
402
421
branch nick: test_verbose_log
403
timestamp: Wed 2005-11-23 12:08:27 +1000
422
timestamp: Tue 2005-11-22 00:00:00 +0000
428
wt.branch, log.LongLogFormatter,
429
show_log_kwargs=dict(verbose=True))
410
431
def test_merges_are_indented_by_level(self):
411
432
wt = self.make_branch_and_tree('parent')
412
wt.commit('first post')
413
self.run_bzr('branch parent child')
414
self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
415
self.run_bzr('branch child smallerchild')
416
self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
419
self.run_bzr('merge ../smallerchild')
420
self.run_bzr(['commit', '-m', 'merge branch 2'])
421
os.chdir('../parent')
422
self.run_bzr('merge ../child')
423
wt.commit('merge branch 1')
425
sio = self.make_utf8_encoded_stringio()
426
lf = LongLogFormatter(to_file=sio)
427
show_log(b, lf, verbose=True)
428
log = normalize_log(sio.getvalue())
429
self.assertEqualDiff(log, """\
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("""\
430
443
------------------------------------------------------------
432
committer: Lorem Ipsum <test@example.com>
445
committer: Joe Foo <joe@foo.com>
433
446
branch nick: parent
447
timestamp: Tue 2005-11-22 00:00:04 +0000
437
450
------------------------------------------------------------
439
committer: Lorem Ipsum <test@example.com>
452
committer: Joe Foo <joe@foo.com>
440
453
branch nick: child
454
timestamp: Tue 2005-11-22 00:00:03 +0000
444
457
------------------------------------------------------------
446
committer: Lorem Ipsum <test@example.com>
459
committer: Joe Foo <joe@foo.com>
447
460
branch nick: smallerchild
461
timestamp: Tue 2005-11-22 00:00:02 +0000
451
464
------------------------------------------------------------
453
committer: Lorem Ipsum <test@example.com>
466
committer: Joe Foo <joe@foo.com>
454
467
branch nick: child
468
timestamp: Tue 2005-11-22 00:00:01 +0000
458
471
------------------------------------------------------------
460
committer: Lorem Ipsum <test@example.com>
473
committer: Joe Foo <joe@foo.com>
461
474
branch nick: parent
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))
467
483
def test_verbose_merge_revisions_contain_deltas(self):
468
484
wt = self.make_branch_and_tree('parent')
469
485
self.build_tree(['parent/f1', 'parent/f2'])
470
486
wt.add(['f1','f2'])
471
wt.commit('first post')
472
self.run_bzr('branch parent child')
487
self.wt_commit(wt, 'first post')
488
child_wt = wt.bzrdir.sprout('child').open_workingtree()
473
489
os.unlink('child/f1')
474
file('child/f2', 'wb').write('hello\n')
475
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
478
self.run_bzr('merge ../child')
479
wt.commit('merge branch 1')
481
sio = self.make_utf8_encoded_stringio()
482
lf = LongLogFormatter(to_file=sio)
483
show_log(b, lf, verbose=True)
484
log = normalize_log(sio.getvalue())
485
self.assertEqualDiff(log, """\
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("""\
486
495
------------------------------------------------------------
488
committer: Lorem Ipsum <test@example.com>
497
committer: Joe Foo <joe@foo.com>
489
498
branch nick: parent
499
timestamp: Tue 2005-11-22 00:00:02 +0000
546
554
committer: Joe Foo <joe@foo.com>
547
555
branch nick: test
548
timestamp: Mon 2005-11-21 09:24:15 -0600
556
timestamp: Tue 2005-11-22 00:00:00 +0000
550
558
simple log message
560
b, log.LongLogFormatter)
553
562
def test_author_in_log(self):
554
563
"""Log includes the author name if it's set in
555
564
the revision properties
557
wt = self.make_branch_and_tree('.')
559
self.build_tree(['a'])
561
b.nick = 'test_author_log'
562
wt.commit(message='add a',
563
timestamp=1132711707,
565
committer='Lorem Ipsum <test@example.com>',
566
author='John Doe <jdoe@example.com>')
568
formatter = LongLogFormatter(to_file=sio)
569
show_log(b, formatter)
570
self.assertEqualDiff(sio.getvalue(), '''\
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("""\
571
570
------------------------------------------------------------
573
author: John Doe <jdoe@example.com>
572
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
574
573
committer: Lorem Ipsum <test@example.com>
575
574
branch nick: test_author_log
576
timestamp: Wed 2005-11-23 12:08:27 +1000
575
timestamp: Tue 2005-11-22 00:00:00 +0000
579
wt.branch, log.LongLogFormatter)
581
581
def test_properties_in_log(self):
582
"""Log includes the custom properties returned by the registered
582
"""Log includes the custom properties returned by the registered
585
wt = self.make_branch_and_tree('.')
587
self.build_tree(['a'])
589
b.nick = 'test_properties_in_log'
590
wt.commit(message='add a',
591
timestamp=1132711707,
593
committer='Lorem Ipsum <test@example.com>',
594
author='John Doe <jdoe@example.com>')
596
formatter = LongLogFormatter(to_file=sio)
598
def trivial_custom_prop_handler(revision):
599
return {'test_prop':'test_value'}
601
log.properties_handler_registry.register(
602
'trivial_custom_prop_handler',
603
trivial_custom_prop_handler)
604
show_log(b, formatter)
606
log.properties_handler_registry.remove(
607
'trivial_custom_prop_handler')
608
self.assertEqualDiff(sio.getvalue(), '''\
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("""\
609
594
------------------------------------------------------------
611
596
test_prop: test_value
612
597
author: John Doe <jdoe@example.com>
613
598
committer: Lorem Ipsum <test@example.com>
614
599
branch nick: test_properties_in_log
615
timestamp: Wed 2005-11-23 12:08:27 +1000
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)
620
625
def test_error_in_properties_handler(self):
621
"""Log includes the custom properties returned by the registered
626
"""Log includes the custom properties returned by the registered
624
wt = self.make_branch_and_tree('.')
626
self.build_tree(['a'])
628
b.nick = 'test_author_log'
629
wt.commit(message='add a',
630
timestamp=1132711707,
632
committer='Lorem Ipsum <test@example.com>',
633
author='John Doe <jdoe@example.com>',
634
revprops={'first_prop':'first_value'})
636
formatter = LongLogFormatter(to_file=sio)
638
def trivial_custom_prop_handler(revision):
639
raise StandardError("a test error")
641
log.properties_handler_registry.register(
642
'trivial_custom_prop_handler',
643
trivial_custom_prop_handler)
644
self.assertRaises(StandardError, show_log, b, formatter,)
646
log.properties_handler_registry.remove(
647
'trivial_custom_prop_handler')
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,)
649
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):
650
724
wt = self.make_branch_and_tree('.')
652
self.build_tree(['a'])
654
b.nick = 'test_author_log'
655
wt.commit(message='add a',
656
timestamp=1132711707,
658
committer='Lorem Ipsum <test@example.com>',
659
author='John Doe <jdoe@example.com>',
660
revprops={'a_prop':'test_value'})
662
formatter = LongLogFormatter(to_file=sio)
664
def bad_argument_prop_handler(revision):
665
return {'custom_prop_name':revision.properties['a_prop']}
667
log.properties_handler_registry.register(
668
'bad_argument_prop_handler',
669
bad_argument_prop_handler)
671
self.assertRaises(AttributeError, formatter.show_properties,
674
revision = b.repository.get_revision(b.last_revision())
675
formatter.show_properties(revision, '')
676
self.assertEqualDiff(sio.getvalue(),
677
'''custom_prop_name: test_value\n''')
679
log.properties_handler_registry.remove(
680
'bad_argument_prop_handler')
683
class TestLineLogFormatter(TestCaseWithTransport):
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):
685
800
def test_line_log(self):
686
801
"""Line log should show revno
690
wt = self.make_branch_and_tree('.')
692
self.build_tree(['a'])
694
b.nick = 'test-line-log'
695
wt.commit(message='add a',
696
timestamp=1132711707,
698
committer='Line-Log-Formatter Tester <test@line.log>')
699
logfile = file('out.tmp', 'w+')
700
formatter = LineLogFormatter(to_file=logfile)
701
show_log(b, formatter)
704
log_contents = logfile.read()
705
self.assertEqualDiff(log_contents,
706
'1: Line-Log-Formatte... 2005-11-23 add a\n')
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)
708
813
def test_trailing_newlines(self):
709
814
wt = self.make_branch_and_tree('.')
710
b = make_commits_with_trailing_newlines(wt)
711
sio = self.make_utf8_encoded_stringio()
712
lf = LineLogFormatter(to_file=sio)
714
self.assertEqualDiff(sio.getvalue(), """\
715
3: Joe Foo 2005-11-21 single line with trailing newline
716
2: Joe Bar 2005-11-21 multiline
717
1: Joe Foo 2005-11-21 simple log message
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)
720
823
def test_line_log_single_merge_revision(self):
721
wt = self.make_branch_and_memory_tree('.')
725
wt.commit('rev-1', rev_id='rev-1',
726
timestamp=1132586655, timezone=36000,
727
committer='Joe Foo <joe@foo.com>')
728
wt.commit('rev-merged', rev_id='rev-2a',
729
timestamp=1132586700, timezone=36000,
730
committer='Joe Foo <joe@foo.com>')
731
wt.set_parent_ids(['rev-1', 'rev-2a'])
732
wt.branch.set_last_revision_info(1, 'rev-1')
733
wt.commit('rev-2', rev_id='rev-2b',
734
timestamp=1132586800, timezone=36000,
735
committer='Joe Foo <joe@foo.com>')
736
logfile = self.make_utf8_encoded_stringio()
737
formatter = LineLogFormatter(to_file=logfile)
738
revspec = RevisionSpec.from_string('1.1.1')
740
rev = revspec.in_history(wtb)
741
show_log(wtb, formatter, start_revision=rev, end_revision=rev)
742
self.assertEqualDiff(logfile.getvalue(), """\
743
1.1.1: Joe Foo 2005-11-22 rev-merged
750
class TestGetViewRevisions(TestCaseWithTransport):
824
wt = self._prepare_tree_with_merges()
825
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
826
rev = revspec.in_history(wt.branch)
827
self.assertFormatterResult("""\
828
1.1.1: Joe Foo 2005-11-22 rev-merged
830
wt.branch, log.LineLogFormatter,
831
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
833
def test_line_log_with_tags(self):
834
wt = self._prepare_tree_with_merges(with_tags=True)
835
self.assertFormatterResult("""\
836
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
837
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
838
1: Joe Foo 2005-11-22 rev-1
840
wt.branch, log.LineLogFormatter)
843
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
845
def test_line_merge_revs_log(self):
846
"""Line log should show revno
850
wt = self.make_standard_commit('test-line-log',
851
committer='Line-Log-Formatter Tester <test@line.log>',
853
self.assertFormatterResult("""\
854
1: Line-Log-Formatte... 2005-11-22 add a
856
wt.branch, log.LineLogFormatter)
858
def test_line_merge_revs_log_single_merge_revision(self):
859
wt = self._prepare_tree_with_merges()
860
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
861
rev = revspec.in_history(wt.branch)
862
self.assertFormatterResult("""\
863
1.1.1: Joe Foo 2005-11-22 rev-merged
865
wt.branch, log.LineLogFormatter,
866
formatter_kwargs=dict(levels=0),
867
show_log_kwargs=dict(start_revision=rev, end_revision=rev))
869
def test_line_merge_revs_log_with_merges(self):
870
wt = self._prepare_tree_with_merges()
871
self.assertFormatterResult("""\
872
2: Joe Foo 2005-11-22 [merge] rev-2
873
1.1.1: Joe Foo 2005-11-22 rev-merged
874
1: Joe Foo 2005-11-22 rev-1
876
wt.branch, log.LineLogFormatter,
877
formatter_kwargs=dict(levels=0))
880
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
882
def test_gnu_changelog(self):
883
wt = self.make_standard_commit('nicky', authors=[])
884
self.assertFormatterResult('''\
885
2005-11-22 Lorem Ipsum <test@example.com>
890
wt.branch, log.GnuChangelogLogFormatter)
892
def test_with_authors(self):
893
wt = self.make_standard_commit('nicky',
894
authors=['Fooa Fooz <foo@example.com>',
895
'Bari Baro <bar@example.com>'])
896
self.assertFormatterResult('''\
897
2005-11-22 Fooa Fooz <foo@example.com>
902
wt.branch, log.GnuChangelogLogFormatter)
904
def test_verbose(self):
905
wt = self.make_standard_commit('nicky')
906
self.assertFormatterResult('''\
907
2005-11-22 John Doe <jdoe@example.com>
914
wt.branch, log.GnuChangelogLogFormatter,
915
show_log_kwargs=dict(verbose=True))
917
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
919
def _get_view_revisions(self, *args, **kwargs):
920
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
921
log.get_view_revisions, *args, **kwargs)
752
923
def make_tree_with_commits(self):
753
924
"""Create a tree with well-known revision ids"""
754
925
wt = self.make_branch_and_tree('tree1')
755
wt.commit('commit one', rev_id='1')
756
wt.commit('commit two', rev_id='2')
757
wt.commit('commit three', rev_id='3')
926
self.wt_commit(wt, 'commit one', rev_id='1')
927
self.wt_commit(wt, 'commit two', rev_id='2')
928
self.wt_commit(wt, 'commit three', rev_id='3')
758
929
mainline_revs = [None, '1', '2', '3']
759
930
rev_nos = {'1': 1, '2': 2, '3': 3}
760
931
return mainline_revs, rev_nos, wt
830
1018
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
832
1020
self.addCleanup(wt.unlock)
833
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
835
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
836
('4b', '4', 0), ('4a', '3.1.1', 1)],
838
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
839
'forward', include_merges=False))
840
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1021
revisions = list(self._get_view_revisions(
1022
mainline_revs, rev_nos, wt.branch, 'forward'))
1023
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1024
('4b', '4', 0), ('4a', '3.1.1', 1)],
1026
revisions = list(self._get_view_revisions(
1027
mainline_revs, rev_nos, wt.branch, 'forward',
1028
include_merges=False))
1029
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
844
1033
def test_get_view_revisions_merge_reverse(self):
845
1034
"""Test get_view_revisions in reverse when there are merges"""
846
1035
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
848
1037
self.addCleanup(wt.unlock)
849
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
1038
revisions = list(self._get_view_revisions(
1039
mainline_revs, rev_nos, wt.branch, 'reverse'))
851
1040
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
852
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
854
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
855
'reverse', include_merges=False))
1041
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1043
revisions = list(self._get_view_revisions(
1044
mainline_revs, rev_nos, wt.branch, 'reverse',
1045
include_merges=False))
856
1046
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
860
1050
def test_get_view_revisions_merge2(self):
861
1051
"""Test get_view_revisions when there are merges"""
862
mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
864
self.addCleanup(wt.unlock)
865
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
1052
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1054
self.addCleanup(b.unlock)
1055
revisions = list(self._get_view_revisions(
1056
mainline_revs, rev_nos, b, 'forward'))
867
1057
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
868
('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
1058
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
870
1060
self.assertEqual(expected, revisions)
871
revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
872
'forward', include_merges=False))
1061
revisions = list(self._get_view_revisions(
1062
mainline_revs, rev_nos, b, 'forward',
1063
include_merges=False))
873
1064
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
878
class TestGetRevisionsTouchingFileID(TestCaseWithTransport):
1068
def test_file_id_for_range(self):
1069
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1071
self.addCleanup(b.unlock)
1073
def rev_from_rev_id(revid, branch):
1074
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1075
return revspec.in_history(branch)
1077
def view_revs(start_rev, end_rev, file_id, direction):
1078
revs = self.applyDeprecated(
1079
symbol_versioning.deprecated_in((2, 2, 0)),
1080
log.calculate_view_revisions,
1082
start_rev, # start_revision
1083
end_rev, # end_revision
1084
direction, # direction
1085
file_id, # specific_fileid
1086
True, # generate_merge_revisions
1090
rev_3a = rev_from_rev_id('3a', b)
1091
rev_4b = rev_from_rev_id('4b', b)
1092
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1093
('3a', '2.1.1', 2)],
1094
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1095
# Note: 3c still appears before 3a here because of depth-based sorting
1096
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1097
('3a', '2.1.1', 2)],
1098
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1101
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1103
def get_view_revisions(self, *args):
1104
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1105
log.get_view_revisions, *args)
880
1107
def create_tree_with_single_merge(self):
881
1108
"""Create a branch with a moderate layout.
931
1163
tree.commit('D', rev_id='D')
933
1165
# Switch to a read lock for this tree.
934
# We still have addCleanup(unlock)
1166
# We still have an addCleanup(tree.unlock) pending
936
1168
tree.lock_read()
1171
def check_delta(self, delta, **kw):
1172
"""Check the filenames touched by a delta are as expected.
1174
Caller only have to pass in the list of files for each part, all
1175
unspecified parts are considered empty (and checked as such).
1177
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1178
# By default we expect an empty list
1179
expected = kw.get(n, [])
1180
# strip out only the path components
1181
got = [x[0] for x in getattr(delta, n)]
1182
self.assertEqual(expected, got)
939
1184
def test_tree_with_single_merge(self):
940
1185
"""Make sure the tree layout is correct."""
941
1186
tree = self.create_tree_with_single_merge()
942
1187
rev_A_tree = tree.branch.repository.revision_tree('A')
943
1188
rev_B_tree = tree.branch.repository.revision_tree('B')
945
f1_changed = (u'f1', 'f1-id', 'file', True, False)
946
f2_changed = (u'f2', 'f2-id', 'file', True, False)
947
f3_changed = (u'f3', 'f3-id', 'file', True, False)
949
delta = rev_B_tree.changes_from(rev_A_tree)
950
self.assertEqual([f1_changed, f3_changed], delta.modified)
951
self.assertEqual([], delta.renamed)
952
self.assertEqual([], delta.added)
953
self.assertEqual([], delta.removed)
955
1189
rev_C_tree = tree.branch.repository.revision_tree('C')
956
delta = rev_C_tree.changes_from(rev_A_tree)
957
self.assertEqual([f2_changed, f3_changed], delta.modified)
958
self.assertEqual([], delta.renamed)
959
self.assertEqual([], delta.added)
960
self.assertEqual([], delta.removed)
962
1190
rev_D_tree = tree.branch.repository.revision_tree('D')
963
delta = rev_D_tree.changes_from(rev_B_tree)
964
self.assertEqual([f2_changed, f3_changed], delta.modified)
965
self.assertEqual([], delta.renamed)
966
self.assertEqual([], delta.added)
967
self.assertEqual([], delta.removed)
969
delta = rev_D_tree.changes_from(rev_C_tree)
970
self.assertEqual([f1_changed, f3_changed], delta.modified)
971
self.assertEqual([], delta.renamed)
972
self.assertEqual([], delta.added)
973
self.assertEqual([], delta.removed)
1192
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1193
modified=['f1', 'f3'])
1195
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1196
modified=['f2', 'f3'])
1198
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1199
modified=['f2', 'f3'])
1201
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1202
modified=['f1', 'f3'])
975
1204
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
976
"""Make sure _filter_revisions_touching_file_id returns the right values.
1205
"""Ensure _filter_revisions_touching_file_id returns the right values.
978
1207
Get the return value from _filter_revisions_touching_file_id and make
979
1208
sure they are correct.
981
# The api for _get_revisions_touching_file_id is a little crazy,
1210
# The api for _filter_revisions_touching_file_id is a little crazy.
982
1211
# So we do the setup here.
983
1212
mainline = tree.branch.revision_history()
984
1213
mainline.insert(0, None)
985
1214
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
986
view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1215
view_revs_iter = self.get_view_revisions(
1216
mainline, revnos, tree.branch, 'reverse', True)
988
1217
actual_revs = log._filter_revisions_touching_file_id(
991
list(view_revs_iter),
1218
tree.branch, file_id, list(view_revs_iter))
993
1219
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
995
1221
def test_file_id_f1(self):
1036
1271
self.assertNotContainsRe(s.getvalue(), 'foo')
1039
class TestLogFormatter(TestCase):
1274
class TestLogFormatter(tests.TestCase):
1277
super(TestLogFormatter, self).setUp()
1278
self.rev = revision.Revision('a-id')
1279
self.lf = log.LogFormatter(None)
1041
1281
def test_short_committer(self):
1042
rev = Revision('a-id')
1043
rev.committer = 'John Doe <jdoe@example.com>'
1044
lf = LogFormatter(None)
1045
self.assertEqual('John Doe', lf.short_committer(rev))
1046
rev.committer = 'John Smith <jsmith@example.com>'
1047
self.assertEqual('John Smith', lf.short_committer(rev))
1048
rev.committer = 'John Smith'
1049
self.assertEqual('John Smith', lf.short_committer(rev))
1050
rev.committer = 'jsmith@example.com'
1051
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1052
rev.committer = '<jsmith@example.com>'
1053
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1054
rev.committer = 'John Smith jsmith@example.com'
1055
self.assertEqual('John Smith', lf.short_committer(rev))
1282
def assertCommitter(expected, committer):
1283
self.rev.committer = committer
1284
self.assertEqual(expected, self.lf.short_committer(self.rev))
1286
assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1287
assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1288
assertCommitter('John Smith', 'John Smith')
1289
assertCommitter('jsmith@example.com', 'jsmith@example.com')
1290
assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1291
assertCommitter('John Smith', 'John Smith jsmith@example.com')
1057
1293
def test_short_author(self):
1058
rev = Revision('a-id')
1059
rev.committer = 'John Doe <jdoe@example.com>'
1060
lf = LogFormatter(None)
1061
self.assertEqual('John Doe', lf.short_author(rev))
1062
rev.properties['author'] = 'John Smith <jsmith@example.com>'
1063
self.assertEqual('John Smith', lf.short_author(rev))
1064
rev.properties['author'] = 'John Smith'
1065
self.assertEqual('John Smith', lf.short_author(rev))
1066
rev.properties['author'] = 'jsmith@example.com'
1067
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1068
rev.properties['author'] = '<jsmith@example.com>'
1069
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1070
rev.properties['author'] = 'John Smith jsmith@example.com'
1071
self.assertEqual('John Smith', lf.short_author(rev))
1294
def assertAuthor(expected, author):
1295
self.rev.properties['author'] = author
1296
self.assertEqual(expected, self.lf.short_author(self.rev))
1298
assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1299
assertAuthor('John Smith', 'John Smith')
1300
assertAuthor('jsmith@example.com', 'jsmith@example.com')
1301
assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1302
assertAuthor('John Smith', 'John Smith jsmith@example.com')
1304
def test_short_author_from_committer(self):
1305
self.rev.committer = 'John Doe <jdoe@example.com>'
1306
self.assertEqual('John Doe', self.lf.short_author(self.rev))
1308
def test_short_author_from_authors(self):
1309
self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1310
'Jane Rey <jrey@example.com>')
1311
self.assertEqual('John Smith', self.lf.short_author(self.rev))
1314
class TestReverseByDepth(tests.TestCase):
1315
"""Test reverse_by_depth behavior.
1317
This is used to present revisions in forward (oldest first) order in a nice
1320
The tests use lighter revision description to ease reading.
1323
def assertReversed(self, forward, backward):
1324
# Transform the descriptions to suit the API: tests use (revno, depth),
1325
# while the API expects (revid, revno, depth)
1326
def complete_revisions(l):
1327
"""Transform the description to suit the API.
1329
Tests use (revno, depth) whil the API expects (revid, revno, depth).
1330
Since the revid is arbitrary, we just duplicate revno
1332
return [ (r, r, d) for r, d in l]
1333
forward = complete_revisions(forward)
1334
backward= complete_revisions(backward)
1335
self.assertEqual(forward, log.reverse_by_depth(backward))
1338
def test_mainline_revisions(self):
1339
self.assertReversed([( '1', 0), ('2', 0)],
1340
[('2', 0), ('1', 0)])
1342
def test_merged_revisions(self):
1343
self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1344
[('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
1345
def test_shifted_merged_revisions(self):
1346
"""Test irregular layout.
1348
Requesting revisions touching a file can produce "holes" in the depths.
1350
self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1351
[('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
1353
def test_merged_without_child_revisions(self):
1354
"""Test irregular layout.
1356
Revision ranges can produce "holes" in the depths.
1358
# When a revision of higher depth doesn't follow one of lower depth, we
1359
# assume a lower depth one is virtually there
1360
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1361
[('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1362
# So we get the same order after reversing below even if the original
1363
# revisions are not in the same order.
1364
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1365
[('3', 3), ('4', 4), ('2', 2), ('1', 2),])
1368
class TestHistoryChange(tests.TestCaseWithTransport):
1370
def setup_a_tree(self):
1371
tree = self.make_branch_and_tree('tree')
1373
self.addCleanup(tree.unlock)
1374
tree.commit('1a', rev_id='1a')
1375
tree.commit('2a', rev_id='2a')
1376
tree.commit('3a', rev_id='3a')
1379
def setup_ab_tree(self):
1380
tree = self.setup_a_tree()
1381
tree.set_last_revision('1a')
1382
tree.branch.set_last_revision_info(1, '1a')
1383
tree.commit('2b', rev_id='2b')
1384
tree.commit('3b', rev_id='3b')
1387
def setup_ac_tree(self):
1388
tree = self.setup_a_tree()
1389
tree.set_last_revision(revision.NULL_REVISION)
1390
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1391
tree.commit('1c', rev_id='1c')
1392
tree.commit('2c', rev_id='2c')
1393
tree.commit('3c', rev_id='3c')
1396
def test_all_new(self):
1397
tree = self.setup_ab_tree()
1398
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1399
self.assertEqual([], old)
1400
self.assertEqual(['2a', '3a'], new)
1402
def test_all_old(self):
1403
tree = self.setup_ab_tree()
1404
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1405
self.assertEqual([], new)
1406
self.assertEqual(['2a', '3a'], old)
1408
def test_null_old(self):
1409
tree = self.setup_ab_tree()
1410
old, new = log.get_history_change(revision.NULL_REVISION,
1411
'3a', tree.branch.repository)
1412
self.assertEqual([], old)
1413
self.assertEqual(['1a', '2a', '3a'], new)
1415
def test_null_new(self):
1416
tree = self.setup_ab_tree()
1417
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1418
tree.branch.repository)
1419
self.assertEqual([], new)
1420
self.assertEqual(['1a', '2a', '3a'], old)
1422
def test_diverged(self):
1423
tree = self.setup_ab_tree()
1424
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1425
self.assertEqual(old, ['2a', '3a'])
1426
self.assertEqual(new, ['2b', '3b'])
1428
def test_unrelated(self):
1429
tree = self.setup_ac_tree()
1430
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1431
self.assertEqual(old, ['1a', '2a', '3a'])
1432
self.assertEqual(new, ['1c', '2c', '3c'])
1434
def test_show_branch_change(self):
1435
tree = self.setup_ab_tree()
1437
log.show_branch_change(tree.branch, s, 3, '3a')
1438
self.assertContainsRe(s.getvalue(),
1439
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1440
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1442
def test_show_branch_change_no_change(self):
1443
tree = self.setup_ab_tree()
1445
log.show_branch_change(tree.branch, s, 3, '3b')
1446
self.assertEqual(s.getvalue(),
1447
'Nothing seems to have changed\n')
1449
def test_show_branch_change_no_old(self):
1450
tree = self.setup_ab_tree()
1452
log.show_branch_change(tree.branch, s, 2, '2b')
1453
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1454
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1456
def test_show_branch_change_no_new(self):
1457
tree = self.setup_ab_tree()
1458
tree.branch.set_last_revision_info(2, '2b')
1460
log.show_branch_change(tree.branch, s, 3, '3b')
1461
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1462
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1466
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1469
TestCaseForLogFormatter.setUp(self)
1470
log.properties_handler_registry.register(
1471
'bugs_properties_handler',
1472
log._bugs_properties_handler)
1474
def make_commits_with_bugs(self):
1475
"""Helper method for LogFormatter tests"""
1476
tree = self.make_branch_and_tree(u'.')
1477
self.build_tree(['a', 'b'])
1479
self.wt_commit(tree, 'simple log message', rev_id='a1',
1480
revprops={'bugs': 'test://bug/id fixed'})
1482
self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1483
authors=['Joe Bar <joe@bar.com>'],
1484
revprops={'bugs': 'test://bug/id fixed\n'
1485
'test://bug/2 fixed'})
1489
def test_long_bugs(self):
1490
tree = self.make_commits_with_bugs()
1491
self.assertFormatterResult("""\
1492
------------------------------------------------------------
1494
fixes bug(s): test://bug/id test://bug/2
1495
author: Joe Bar <joe@bar.com>
1496
committer: Joe Foo <joe@foo.com>
1498
timestamp: Tue 2005-11-22 00:00:01 +0000
1503
------------------------------------------------------------
1505
fixes bug(s): test://bug/id
1506
committer: Joe Foo <joe@foo.com>
1508
timestamp: Tue 2005-11-22 00:00:00 +0000
1512
tree.branch, log.LongLogFormatter)
1514
def test_short_bugs(self):
1515
tree = self.make_commits_with_bugs()
1516
self.assertFormatterResult("""\
1517
2 Joe Bar\t2005-11-22
1518
fixes bug(s): test://bug/id test://bug/2
1523
1 Joe Foo\t2005-11-22
1524
fixes bug(s): test://bug/id
1528
tree.branch, log.ShortLogFormatter)
1530
def test_wrong_bugs_property(self):
1531
tree = self.make_branch_and_tree(u'.')
1532
self.build_tree(['foo'])
1533
self.wt_commit(tree, 'simple log message', rev_id='a1',
1534
revprops={'bugs': 'test://bug/id invalid_value'})
1535
self.assertFormatterResult("""\
1536
1 Joe Foo\t2005-11-22
1540
tree.branch, log.ShortLogFormatter)
1542
def test_bugs_handler_present(self):
1543
self.properties_handler_registry.get('bugs_properties_handler')