1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
from bzrlib.selftest import BzrTestBase
20
from bzrlib.log import LogFormatter, show_log, LongLogFormatter
21
from bzrlib.branch import Branch
23
class _LogEntry(object):
24
# should probably move into bzrlib.log?
28
class LogCatcher(LogFormatter):
29
"""Pull log messages into list rather than displaying them.
31
For ease of testing we save log messages here rather than actually
32
formatting them, so that we can precisely check the result without
33
being too dependent on the exact formatting.
35
We should also test the LogFormatter.
18
from cStringIO import StringIO
30
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
33
super(TestCaseWithoutPropsHandler, self).setUp()
34
# keep a reference to the "current" custom prop. handler registry
35
self.properties_handler_registry = log.properties_handler_registry
36
# Use a clean registry for log
37
log.properties_handler_registry = registry.Registry()
40
log.properties_handler_registry = self.properties_handler_registry
41
self.addCleanup(restore)
44
class LogCatcher(log.LogFormatter):
45
"""Pull log messages into a list rather than displaying them.
47
To simplify testing we save logged revisions here rather than actually
48
formatting anything, so that we can precisely check the result without
49
being dependent on the formatting.
37
54
def __init__(self):
38
55
super(LogCatcher, self).__init__(to_file=None)
42
def show(self, revno, rev, delta):
50
class SimpleLogTest(BzrTestBase):
58
def log_revision(self, revision):
59
self.revisions.append(revision)
62
class TestShowLog(tests.TestCaseWithTransport):
51
64
def checkDelta(self, delta, **kw):
52
"""Check the filenames touched by a delta are as expected."""
65
"""Check the filenames touched by a delta are as expected.
67
Caller only have to pass in the list of files for each part, all
68
unspecified parts are considered empty (and checked as such).
53
70
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
71
# By default we expect an empty list
54
72
expected = kw.get(n, [])
56
# tests are written with unix paths; fix them up for windows
58
expected = [x.replace('/', os.sep) for x in expected]
60
73
# strip out only the path components
61
74
got = [x[0] for x in getattr(delta, n)]
62
self.assertEquals(expected, got)
66
eq = self.assertEquals
69
b = Branch('.', init=True)
75
self.assertEqual(expected, got)
77
def assertInvalidRevisonNumber(self, br, start, end):
79
self.assertRaises(errors.InvalidRevisionNumber,
81
start_revision=start, end_revision=end)
83
def test_cur_revno(self):
84
wt = self.make_branch_and_tree('.')
88
wt.commit('empty commit')
89
log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
91
# Since there is a single revision in the branch all the combinations
93
self.assertInvalidRevisonNumber(b, 2, 1)
94
self.assertInvalidRevisonNumber(b, 1, 2)
95
self.assertInvalidRevisonNumber(b, 0, 2)
96
self.assertInvalidRevisonNumber(b, 1, 0)
97
self.assertInvalidRevisonNumber(b, -1, 1)
98
self.assertInvalidRevisonNumber(b, 1, -1)
100
def test_empty_branch(self):
101
wt = self.make_branch_and_tree('.')
104
log.show_log(wt.branch, lf)
77
b.commit('empty commit')
106
self.assertEqual([], lf.revisions)
108
def test_empty_commit(self):
109
wt = self.make_branch_and_tree('.')
111
wt.commit('empty commit')
79
show_log(b, lf, verbose=True)
81
eq(lf.logs[0].revno, 1)
82
eq(lf.logs[0].rev.message, 'empty commit')
84
self.log('log delta: %r' % d)
113
log.show_log(wt.branch, lf, verbose=True)
115
self.assertEqual(1, len(revs))
116
self.assertEqual('1', revs[0].revno)
117
self.assertEqual('empty commit', revs[0].rev.message)
118
self.checkDelta(revs[0].delta)
120
def test_simple_commit(self):
121
wt = self.make_branch_and_tree('.')
122
wt.commit('empty commit')
88
123
self.build_tree(['hello'])
90
b.commit('add one file')
91
# log using regular thing
92
show_log(b, LongLogFormatter(self.TEST_LOG))
94
# get log as data structure
125
wt.commit('add one file',
126
committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
127
u'<test@example.com>')
96
show_log(b, lf, verbose=True)
98
self.log('log entries:')
99
for logentry in lf.logs:
100
self.log('%4d %s' % (logentry.revno, logentry.rev.message))
129
log.show_log(wt.branch, lf, verbose=True)
130
self.assertEqual(2, len(lf.revisions))
102
131
# first one is most recent
103
logentry = lf.logs[0]
104
eq(logentry.revno, 2)
105
eq(logentry.rev.message, 'add one file')
107
self.log('log 2 delta: %r' % d)
108
# self.checkDelta(d, added=['hello'])
132
log_entry = lf.revisions[0]
133
self.assertEqual('2', log_entry.revno)
134
self.assertEqual('add one file', log_entry.rev.message)
135
self.checkDelta(log_entry.delta, added=['hello'])
137
def test_commit_message_with_control_chars(self):
138
wt = self.make_branch_and_tree('.')
139
msg = u"All 8-bit chars: " + ''.join([unichr(x) for x in range(256)])
140
msg = msg.replace(u'\r', u'\n')
143
log.show_log(wt.branch, lf, verbose=True)
144
committed_msg = lf.revisions[0].rev.message
145
self.assertNotEqual(msg, committed_msg)
146
self.assertTrue(len(committed_msg) > len(msg))
148
def test_commit_message_without_control_chars(self):
149
wt = self.make_branch_and_tree('.')
150
# escaped. As ElementTree apparently does some kind of
151
# newline conversion, neither LF (\x0A) nor CR (\x0D) are
152
# included in the test commit message, even though they are
153
# valid XML 1.0 characters.
154
msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
157
log.show_log(wt.branch, lf, verbose=True)
158
committed_msg = lf.revisions[0].rev.message
159
self.assertEqual(msg, committed_msg)
161
def test_deltas_in_merge_revisions(self):
162
"""Check deltas created for both mainline and merge revisions"""
163
wt = self.make_branch_and_tree('parent')
164
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
167
wt.commit(message='add file1 and file2')
168
self.run_bzr('branch parent child')
169
os.unlink('child/file1')
170
file('child/file2', 'wb').write('hello\n')
171
self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
174
self.run_bzr('merge ../child')
175
wt.commit('merge child branch')
179
lf.supports_merge_revisions = True
180
log.show_log(b, lf, verbose=True)
183
self.assertEqual(3, len(revs))
186
self.assertEqual('2', logentry.revno)
187
self.assertEqual('merge child branch', logentry.rev.message)
188
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
191
self.assertEqual('1.1.1', logentry.revno)
192
self.assertEqual('remove file1 and modify file2', logentry.rev.message)
193
self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
196
self.assertEqual('1', logentry.revno)
197
self.assertEqual('add file1 and file2', logentry.rev.message)
198
self.checkDelta(logentry.delta, added=['file1', 'file2'])
201
def make_commits_with_trailing_newlines(wt):
202
"""Helper method for LogFormatter tests"""
205
open('a', 'wb').write('hello moto\n')
207
wt.commit('simple log message', rev_id='a1',
208
timestamp=1132586655.459960938, timezone=-6*3600,
209
committer='Joe Foo <joe@foo.com>')
210
open('b', 'wb').write('goodbye\n')
212
wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
213
timestamp=1132586842.411175966, timezone=-6*3600,
214
committer='Joe Foo <joe@foo.com>',
215
authors=['Joe Bar <joe@bar.com>'])
217
open('c', 'wb').write('just another manic monday\n')
219
wt.commit('single line with trailing newline\n', rev_id='a3',
220
timestamp=1132587176.835228920, timezone=-6*3600,
221
committer = 'Joe Foo <joe@foo.com>')
225
def normalize_log(log):
226
"""Replaces the variable lines of logs with fixed lines"""
227
author = 'author: Dolor Sit <test@example.com>'
228
committer = 'committer: Lorem Ipsum <test@example.com>'
229
lines = log.splitlines(True)
230
for idx,line in enumerate(lines):
231
stripped_line = line.lstrip()
232
indent = ' ' * (len(line) - len(stripped_line))
233
if stripped_line.startswith('author:'):
234
lines[idx] = indent + author + '\n'
235
elif stripped_line.startswith('committer:'):
236
lines[idx] = indent + committer + '\n'
237
elif stripped_line.startswith('timestamp:'):
238
lines[idx] = indent + 'timestamp: Just now\n'
239
return ''.join(lines)
242
class TestShortLogFormatter(tests.TestCaseWithTransport):
244
def test_trailing_newlines(self):
245
wt = self.make_branch_and_tree('.')
246
b = make_commits_with_trailing_newlines(wt)
247
sio = self.make_utf8_encoded_stringio()
248
lf = log.ShortLogFormatter(to_file=sio)
250
self.assertEqualDiff("""\
251
3 Joe Foo\t2005-11-21
252
single line with trailing newline
254
2 Joe Bar\t2005-11-21
259
1 Joe Foo\t2005-11-21
265
def _prepare_tree_with_merges(self, with_tags=False):
266
wt = self.make_branch_and_memory_tree('.')
268
self.addCleanup(wt.unlock)
270
wt.commit('rev-1', rev_id='rev-1',
271
timestamp=1132586655, timezone=36000,
272
committer='Joe Foo <joe@foo.com>')
273
wt.commit('rev-merged', rev_id='rev-2a',
274
timestamp=1132586700, timezone=36000,
275
committer='Joe Foo <joe@foo.com>')
276
wt.set_parent_ids(['rev-1', 'rev-2a'])
277
wt.branch.set_last_revision_info(1, 'rev-1')
278
wt.commit('rev-2', rev_id='rev-2b',
279
timestamp=1132586800, timezone=36000,
280
committer='Joe Foo <joe@foo.com>')
283
branch.tags.set_tag('v0.2', 'rev-2b')
284
wt.commit('rev-3', rev_id='rev-3',
285
timestamp=1132586900, timezone=36000,
286
committer='Jane Foo <jane@foo.com>')
287
branch.tags.set_tag('v1.0rc1', 'rev-3')
288
branch.tags.set_tag('v1.0', 'rev-3')
291
def test_short_log_with_merges(self):
292
wt = self._prepare_tree_with_merges()
293
logfile = self.make_utf8_encoded_stringio()
294
formatter = log.ShortLogFormatter(to_file=logfile)
295
log.show_log(wt.branch, formatter)
296
self.assertEqualDiff("""\
297
2 Joe Foo\t2005-11-22 [merge]
300
1 Joe Foo\t2005-11-22
306
def test_short_log_with_merges_and_advice(self):
307
wt = self._prepare_tree_with_merges()
308
logfile = self.make_utf8_encoded_stringio()
309
formatter = log.ShortLogFormatter(to_file=logfile,
311
log.show_log(wt.branch, formatter)
312
self.assertEqualDiff("""\
313
2 Joe Foo\t2005-11-22 [merge]
316
1 Joe Foo\t2005-11-22
319
Use --include-merges or -n0 to see merged revisions.
323
def test_short_log_with_merges_and_range(self):
324
wt = self.make_branch_and_memory_tree('.')
326
self.addCleanup(wt.unlock)
328
wt.commit('rev-1', rev_id='rev-1',
329
timestamp=1132586655, timezone=36000,
330
committer='Joe Foo <joe@foo.com>')
331
wt.commit('rev-merged', rev_id='rev-2a',
332
timestamp=1132586700, timezone=36000,
333
committer='Joe Foo <joe@foo.com>')
334
wt.branch.set_last_revision_info(1, 'rev-1')
335
wt.set_parent_ids(['rev-1', 'rev-2a'])
336
wt.commit('rev-2b', rev_id='rev-2b',
337
timestamp=1132586800, timezone=36000,
338
committer='Joe Foo <joe@foo.com>')
339
wt.commit('rev-3a', rev_id='rev-3a',
340
timestamp=1132586800, timezone=36000,
341
committer='Joe Foo <joe@foo.com>')
342
wt.branch.set_last_revision_info(2, 'rev-2b')
343
wt.set_parent_ids(['rev-2b', 'rev-3a'])
344
wt.commit('rev-3b', rev_id='rev-3b',
345
timestamp=1132586800, timezone=36000,
346
committer='Joe Foo <joe@foo.com>')
347
logfile = self.make_utf8_encoded_stringio()
348
formatter = log.ShortLogFormatter(to_file=logfile)
349
log.show_log(wt.branch, formatter,
350
start_revision=2, end_revision=3)
351
self.assertEqualDiff("""\
352
3 Joe Foo\t2005-11-22 [merge]
355
2 Joe Foo\t2005-11-22 [merge]
361
def test_short_log_with_tags(self):
362
wt = self._prepare_tree_with_merges(with_tags=True)
363
logfile = self.make_utf8_encoded_stringio()
364
formatter = log.ShortLogFormatter(to_file=logfile)
365
log.show_log(wt.branch, formatter)
366
self.assertEqualDiff("""\
367
3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
370
2 Joe Foo\t2005-11-22 {v0.2} [merge]
373
1 Joe Foo\t2005-11-22
379
def test_short_log_single_merge_revision(self):
380
wt = self.make_branch_and_memory_tree('.')
382
self.addCleanup(wt.unlock)
384
wt.commit('rev-1', rev_id='rev-1',
385
timestamp=1132586655, timezone=36000,
386
committer='Joe Foo <joe@foo.com>')
387
wt.commit('rev-merged', rev_id='rev-2a',
388
timestamp=1132586700, timezone=36000,
389
committer='Joe Foo <joe@foo.com>')
390
wt.set_parent_ids(['rev-1', 'rev-2a'])
391
wt.branch.set_last_revision_info(1, 'rev-1')
392
wt.commit('rev-2', rev_id='rev-2b',
393
timestamp=1132586800, timezone=36000,
394
committer='Joe Foo <joe@foo.com>')
395
logfile = self.make_utf8_encoded_stringio()
396
formatter = log.ShortLogFormatter(to_file=logfile)
397
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
399
rev = revspec.in_history(wtb)
400
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
401
self.assertEqualDiff("""\
402
1.1.1 Joe Foo\t2005-11-22
409
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
411
def test_short_merge_revs_log_with_merges(self):
412
wt = self.make_branch_and_memory_tree('.')
414
self.addCleanup(wt.unlock)
416
wt.commit('rev-1', rev_id='rev-1',
417
timestamp=1132586655, timezone=36000,
418
committer='Joe Foo <joe@foo.com>')
419
wt.commit('rev-merged', rev_id='rev-2a',
420
timestamp=1132586700, timezone=36000,
421
committer='Joe Foo <joe@foo.com>')
422
wt.set_parent_ids(['rev-1', 'rev-2a'])
423
wt.branch.set_last_revision_info(1, 'rev-1')
424
wt.commit('rev-2', rev_id='rev-2b',
425
timestamp=1132586800, timezone=36000,
426
committer='Joe Foo <joe@foo.com>')
427
logfile = self.make_utf8_encoded_stringio()
428
formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
429
log.show_log(wt.branch, formatter)
430
# Note that the 1.1.1 indenting is in fact correct given that
431
# the revision numbers are right justified within 5 characters
432
# for mainline revnos and 9 characters for dotted revnos.
433
self.assertEqualDiff("""\
434
2 Joe Foo\t2005-11-22 [merge]
437
1.1.1 Joe Foo\t2005-11-22
440
1 Joe Foo\t2005-11-22
446
def test_short_merge_revs_log_single_merge_revision(self):
447
wt = self.make_branch_and_memory_tree('.')
449
self.addCleanup(wt.unlock)
451
wt.commit('rev-1', rev_id='rev-1',
452
timestamp=1132586655, timezone=36000,
453
committer='Joe Foo <joe@foo.com>')
454
wt.commit('rev-merged', rev_id='rev-2a',
455
timestamp=1132586700, timezone=36000,
456
committer='Joe Foo <joe@foo.com>')
457
wt.set_parent_ids(['rev-1', 'rev-2a'])
458
wt.branch.set_last_revision_info(1, 'rev-1')
459
wt.commit('rev-2', rev_id='rev-2b',
460
timestamp=1132586800, timezone=36000,
461
committer='Joe Foo <joe@foo.com>')
462
logfile = self.make_utf8_encoded_stringio()
463
formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
464
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
466
rev = revspec.in_history(wtb)
467
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
468
self.assertEqualDiff("""\
469
1.1.1 Joe Foo\t2005-11-22
476
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
478
def test_verbose_log(self):
479
"""Verbose log includes changed files
483
wt = self.make_branch_and_tree('.')
485
self.build_tree(['a'])
487
# XXX: why does a longer nick show up?
488
b.nick = 'test_verbose_log'
489
wt.commit(message='add a',
490
timestamp=1132711707,
492
committer='Lorem Ipsum <test@example.com>')
493
logfile = file('out.tmp', 'w+')
494
formatter = log.LongLogFormatter(to_file=logfile)
495
log.show_log(b, formatter, verbose=True)
498
log_contents = logfile.read()
499
self.assertEqualDiff('''\
500
------------------------------------------------------------
502
committer: Lorem Ipsum <test@example.com>
503
branch nick: test_verbose_log
504
timestamp: Wed 2005-11-23 12:08:27 +1000
512
def test_merges_are_indented_by_level(self):
513
wt = self.make_branch_and_tree('parent')
514
wt.commit('first post')
515
self.run_bzr('branch parent child')
516
self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
517
self.run_bzr('branch child smallerchild')
518
self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
521
self.run_bzr('merge ../smallerchild')
522
self.run_bzr(['commit', '-m', 'merge branch 2'])
523
os.chdir('../parent')
524
self.run_bzr('merge ../child')
525
wt.commit('merge branch 1')
527
sio = self.make_utf8_encoded_stringio()
528
lf = log.LongLogFormatter(to_file=sio, levels=0)
529
log.show_log(b, lf, verbose=True)
530
the_log = normalize_log(sio.getvalue())
531
self.assertEqualDiff("""\
532
------------------------------------------------------------
534
committer: Lorem Ipsum <test@example.com>
539
------------------------------------------------------------
541
committer: Lorem Ipsum <test@example.com>
546
------------------------------------------------------------
548
committer: Lorem Ipsum <test@example.com>
549
branch nick: smallerchild
553
------------------------------------------------------------
555
committer: Lorem Ipsum <test@example.com>
560
------------------------------------------------------------
562
committer: Lorem Ipsum <test@example.com>
570
def test_verbose_merge_revisions_contain_deltas(self):
571
wt = self.make_branch_and_tree('parent')
572
self.build_tree(['parent/f1', 'parent/f2'])
574
wt.commit('first post')
575
self.run_bzr('branch parent child')
576
os.unlink('child/f1')
577
file('child/f2', 'wb').write('hello\n')
578
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
581
self.run_bzr('merge ../child')
582
wt.commit('merge branch 1')
584
sio = self.make_utf8_encoded_stringio()
585
lf = log.LongLogFormatter(to_file=sio, levels=0)
586
log.show_log(b, lf, verbose=True)
587
the_log = normalize_log(sio.getvalue())
588
self.assertEqualDiff("""\
589
------------------------------------------------------------
591
committer: Lorem Ipsum <test@example.com>
600
------------------------------------------------------------
602
committer: Lorem Ipsum <test@example.com>
606
removed f1 and modified f2
611
------------------------------------------------------------
613
committer: Lorem Ipsum <test@example.com>
624
def test_trailing_newlines(self):
625
wt = self.make_branch_and_tree('.')
626
b = make_commits_with_trailing_newlines(wt)
627
sio = self.make_utf8_encoded_stringio()
628
lf = log.LongLogFormatter(to_file=sio)
630
self.assertEqualDiff("""\
631
------------------------------------------------------------
633
committer: Joe Foo <joe@foo.com>
635
timestamp: Mon 2005-11-21 09:32:56 -0600
637
single line with trailing newline
638
------------------------------------------------------------
640
author: Joe Bar <joe@bar.com>
641
committer: Joe Foo <joe@foo.com>
643
timestamp: Mon 2005-11-21 09:27:22 -0600
648
------------------------------------------------------------
650
committer: Joe Foo <joe@foo.com>
652
timestamp: Mon 2005-11-21 09:24:15 -0600
658
def test_author_in_log(self):
659
"""Log includes the author name if it's set in
660
the revision properties
662
wt = self.make_branch_and_tree('.')
664
self.build_tree(['a'])
666
b.nick = 'test_author_log'
667
wt.commit(message='add a',
668
timestamp=1132711707,
670
committer='Lorem Ipsum <test@example.com>',
671
authors=['John Doe <jdoe@example.com>',
672
'Jane Rey <jrey@example.com>'])
674
formatter = log.LongLogFormatter(to_file=sio)
675
log.show_log(b, formatter)
676
self.assertEqualDiff('''\
677
------------------------------------------------------------
679
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
680
committer: Lorem Ipsum <test@example.com>
681
branch nick: test_author_log
682
timestamp: Wed 2005-11-23 12:08:27 +1000
688
def test_properties_in_log(self):
689
"""Log includes the custom properties returned by the registered
692
wt = self.make_branch_and_tree('.')
694
self.build_tree(['a'])
696
b.nick = 'test_properties_in_log'
697
wt.commit(message='add a',
698
timestamp=1132711707,
700
committer='Lorem Ipsum <test@example.com>',
701
authors=['John Doe <jdoe@example.com>'])
703
formatter = log.LongLogFormatter(to_file=sio)
705
def trivial_custom_prop_handler(revision):
706
return {'test_prop':'test_value'}
708
log.properties_handler_registry.register(
709
'trivial_custom_prop_handler',
710
trivial_custom_prop_handler)
711
log.show_log(b, formatter)
713
log.properties_handler_registry.remove(
714
'trivial_custom_prop_handler')
715
self.assertEqualDiff('''\
716
------------------------------------------------------------
718
test_prop: test_value
719
author: John Doe <jdoe@example.com>
720
committer: Lorem Ipsum <test@example.com>
721
branch nick: test_properties_in_log
722
timestamp: Wed 2005-11-23 12:08:27 +1000
728
def test_properties_in_short_log(self):
729
"""Log includes the custom properties returned by the registered
732
wt = self.make_branch_and_tree('.')
734
self.build_tree(['a'])
736
b.nick = 'test_properties_in_short_log'
737
wt.commit(message='add a',
738
timestamp=1132711707,
740
committer='Lorem Ipsum <test@example.com>',
741
authors=['John Doe <jdoe@example.com>'])
743
formatter = log.ShortLogFormatter(to_file=sio)
745
def trivial_custom_prop_handler(revision):
746
return {'test_prop':'test_value'}
748
log.properties_handler_registry.register(
749
'trivial_custom_prop_handler',
750
trivial_custom_prop_handler)
751
log.show_log(b, formatter)
753
log.properties_handler_registry.remove(
754
'trivial_custom_prop_handler')
755
self.assertEqualDiff('''\
756
1 John Doe\t2005-11-23
757
test_prop: test_value
763
def test_error_in_properties_handler(self):
764
"""Log includes the custom properties returned by the registered
767
wt = self.make_branch_and_tree('.')
769
self.build_tree(['a'])
771
b.nick = 'test_author_log'
772
wt.commit(message='add a',
773
timestamp=1132711707,
775
committer='Lorem Ipsum <test@example.com>',
776
authors=['John Doe <jdoe@example.com>'],
777
revprops={'first_prop':'first_value'})
779
formatter = log.LongLogFormatter(to_file=sio)
781
def trivial_custom_prop_handler(revision):
782
raise StandardError("a test error")
784
log.properties_handler_registry.register(
785
'trivial_custom_prop_handler',
786
trivial_custom_prop_handler)
787
self.assertRaises(StandardError, log.show_log, b, formatter,)
789
log.properties_handler_registry.remove(
790
'trivial_custom_prop_handler')
792
def test_properties_handler_bad_argument(self):
793
wt = self.make_branch_and_tree('.')
795
self.build_tree(['a'])
797
b.nick = 'test_author_log'
798
wt.commit(message='add a',
799
timestamp=1132711707,
801
committer='Lorem Ipsum <test@example.com>',
802
authors=['John Doe <jdoe@example.com>'],
803
revprops={'a_prop':'test_value'})
805
formatter = log.LongLogFormatter(to_file=sio)
807
def bad_argument_prop_handler(revision):
808
return {'custom_prop_name':revision.properties['a_prop']}
810
log.properties_handler_registry.register(
811
'bad_argument_prop_handler',
812
bad_argument_prop_handler)
814
self.assertRaises(AttributeError, formatter.show_properties,
817
revision = b.repository.get_revision(b.last_revision())
818
formatter.show_properties(revision, '')
819
self.assertEqualDiff('''custom_prop_name: test_value\n''',
822
log.properties_handler_registry.remove(
823
'bad_argument_prop_handler')
826
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
828
def test_long_verbose_log(self):
829
"""Verbose log includes changed files
833
wt = self.make_branch_and_tree('.')
835
self.build_tree(['a'])
837
# XXX: why does a longer nick show up?
838
b.nick = 'test_verbose_log'
839
wt.commit(message='add a',
840
timestamp=1132711707,
842
committer='Lorem Ipsum <test@example.com>')
843
logfile = file('out.tmp', 'w+')
844
formatter = log.LongLogFormatter(to_file=logfile, levels=1)
845
log.show_log(b, formatter, verbose=True)
848
log_contents = logfile.read()
849
self.assertEqualDiff('''\
850
------------------------------------------------------------
852
committer: Lorem Ipsum <test@example.com>
853
branch nick: test_verbose_log
854
timestamp: Wed 2005-11-23 12:08:27 +1000
862
def test_long_verbose_contain_deltas(self):
863
wt = self.make_branch_and_tree('parent')
864
self.build_tree(['parent/f1', 'parent/f2'])
866
wt.commit('first post')
867
self.run_bzr('branch parent child')
868
os.unlink('child/f1')
869
file('child/f2', 'wb').write('hello\n')
870
self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
873
self.run_bzr('merge ../child')
874
wt.commit('merge branch 1')
876
sio = self.make_utf8_encoded_stringio()
877
lf = log.LongLogFormatter(to_file=sio, levels=1)
878
log.show_log(b, lf, verbose=True)
879
the_log = normalize_log(sio.getvalue())
880
self.assertEqualDiff("""\
881
------------------------------------------------------------
883
committer: Lorem Ipsum <test@example.com>
892
------------------------------------------------------------
894
committer: Lorem Ipsum <test@example.com>
905
def test_long_trailing_newlines(self):
906
wt = self.make_branch_and_tree('.')
907
b = make_commits_with_trailing_newlines(wt)
908
sio = self.make_utf8_encoded_stringio()
909
lf = log.LongLogFormatter(to_file=sio, levels=1)
911
self.assertEqualDiff("""\
912
------------------------------------------------------------
914
committer: Joe Foo <joe@foo.com>
916
timestamp: Mon 2005-11-21 09:32:56 -0600
918
single line with trailing newline
919
------------------------------------------------------------
921
author: Joe Bar <joe@bar.com>
922
committer: Joe Foo <joe@foo.com>
924
timestamp: Mon 2005-11-21 09:27:22 -0600
929
------------------------------------------------------------
931
committer: Joe Foo <joe@foo.com>
933
timestamp: Mon 2005-11-21 09:24:15 -0600
939
def test_long_author_in_log(self):
940
"""Log includes the author name if it's set in
941
the revision properties
943
wt = self.make_branch_and_tree('.')
945
self.build_tree(['a'])
947
b.nick = 'test_author_log'
948
wt.commit(message='add a',
949
timestamp=1132711707,
951
committer='Lorem Ipsum <test@example.com>',
952
authors=['John Doe <jdoe@example.com>'])
954
formatter = log.LongLogFormatter(to_file=sio, levels=1)
955
log.show_log(b, formatter)
956
self.assertEqualDiff('''\
957
------------------------------------------------------------
959
author: John Doe <jdoe@example.com>
960
committer: Lorem Ipsum <test@example.com>
961
branch nick: test_author_log
962
timestamp: Wed 2005-11-23 12:08:27 +1000
968
def test_long_properties_in_log(self):
969
"""Log includes the custom properties returned by the registered
972
wt = self.make_branch_and_tree('.')
974
self.build_tree(['a'])
976
b.nick = 'test_properties_in_log'
977
wt.commit(message='add a',
978
timestamp=1132711707,
980
committer='Lorem Ipsum <test@example.com>',
981
authors=['John Doe <jdoe@example.com>'])
983
formatter = log.LongLogFormatter(to_file=sio, levels=1)
985
def trivial_custom_prop_handler(revision):
986
return {'test_prop':'test_value'}
988
log.properties_handler_registry.register(
989
'trivial_custom_prop_handler',
990
trivial_custom_prop_handler)
991
log.show_log(b, formatter)
993
log.properties_handler_registry.remove(
994
'trivial_custom_prop_handler')
995
self.assertEqualDiff('''\
996
------------------------------------------------------------
998
test_prop: test_value
999
author: John Doe <jdoe@example.com>
1000
committer: Lorem Ipsum <test@example.com>
1001
branch nick: test_properties_in_log
1002
timestamp: Wed 2005-11-23 12:08:27 +1000
1009
class TestLineLogFormatter(tests.TestCaseWithTransport):
1011
def test_line_log(self):
1012
"""Line log should show revno
1016
wt = self.make_branch_and_tree('.')
1018
self.build_tree(['a'])
1020
b.nick = 'test-line-log'
1021
wt.commit(message='add a',
1022
timestamp=1132711707,
1024
committer='Line-Log-Formatter Tester <test@line.log>')
1025
logfile = file('out.tmp', 'w+')
1026
formatter = log.LineLogFormatter(to_file=logfile)
1027
log.show_log(b, formatter)
1030
log_contents = logfile.read()
1031
self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1034
def test_trailing_newlines(self):
1035
wt = self.make_branch_and_tree('.')
1036
b = make_commits_with_trailing_newlines(wt)
1037
sio = self.make_utf8_encoded_stringio()
1038
lf = log.LineLogFormatter(to_file=sio)
1040
self.assertEqualDiff("""\
1041
3: Joe Foo 2005-11-21 single line with trailing newline
1042
2: Joe Bar 2005-11-21 multiline
1043
1: Joe Foo 2005-11-21 simple log message
1047
def _prepare_tree_with_merges(self, with_tags=False):
1048
wt = self.make_branch_and_memory_tree('.')
1050
self.addCleanup(wt.unlock)
1052
wt.commit('rev-1', rev_id='rev-1',
1053
timestamp=1132586655, timezone=36000,
1054
committer='Joe Foo <joe@foo.com>')
1055
wt.commit('rev-merged', rev_id='rev-2a',
1056
timestamp=1132586700, timezone=36000,
1057
committer='Joe Foo <joe@foo.com>')
1058
wt.set_parent_ids(['rev-1', 'rev-2a'])
1059
wt.branch.set_last_revision_info(1, 'rev-1')
1060
wt.commit('rev-2', rev_id='rev-2b',
1061
timestamp=1132586800, timezone=36000,
1062
committer='Joe Foo <joe@foo.com>')
1065
branch.tags.set_tag('v0.2', 'rev-2b')
1066
wt.commit('rev-3', rev_id='rev-3',
1067
timestamp=1132586900, timezone=36000,
1068
committer='Jane Foo <jane@foo.com>')
1069
branch.tags.set_tag('v1.0rc1', 'rev-3')
1070
branch.tags.set_tag('v1.0', 'rev-3')
1073
def test_line_log_single_merge_revision(self):
1074
wt = self._prepare_tree_with_merges()
1075
logfile = self.make_utf8_encoded_stringio()
1076
formatter = log.LineLogFormatter(to_file=logfile)
1077
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1079
rev = revspec.in_history(wtb)
1080
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1081
self.assertEqualDiff("""\
1082
1.1.1: Joe Foo 2005-11-22 rev-merged
1086
def test_line_log_with_tags(self):
1087
wt = self._prepare_tree_with_merges(with_tags=True)
1088
logfile = self.make_utf8_encoded_stringio()
1089
formatter = log.LineLogFormatter(to_file=logfile)
1090
log.show_log(wt.branch, formatter)
1091
self.assertEqualDiff("""\
1092
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1093
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
1094
1: Joe Foo 2005-11-22 rev-1
1098
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
1100
def test_line_merge_revs_log(self):
1101
"""Line log should show revno
1105
wt = self.make_branch_and_tree('.')
1107
self.build_tree(['a'])
1109
b.nick = 'test-line-log'
1110
wt.commit(message='add a',
1111
timestamp=1132711707,
1113
committer='Line-Log-Formatter Tester <test@line.log>')
1114
logfile = file('out.tmp', 'w+')
1115
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1116
log.show_log(b, formatter)
1119
log_contents = logfile.read()
1120
self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1123
def test_line_merge_revs_log_single_merge_revision(self):
1124
wt = self.make_branch_and_memory_tree('.')
1126
self.addCleanup(wt.unlock)
1128
wt.commit('rev-1', rev_id='rev-1',
1129
timestamp=1132586655, timezone=36000,
1130
committer='Joe Foo <joe@foo.com>')
1131
wt.commit('rev-merged', rev_id='rev-2a',
1132
timestamp=1132586700, timezone=36000,
1133
committer='Joe Foo <joe@foo.com>')
1134
wt.set_parent_ids(['rev-1', 'rev-2a'])
1135
wt.branch.set_last_revision_info(1, 'rev-1')
1136
wt.commit('rev-2', rev_id='rev-2b',
1137
timestamp=1132586800, timezone=36000,
1138
committer='Joe Foo <joe@foo.com>')
1139
logfile = self.make_utf8_encoded_stringio()
1140
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1141
revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1143
rev = revspec.in_history(wtb)
1144
log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1145
self.assertEqualDiff("""\
1146
1.1.1: Joe Foo 2005-11-22 rev-merged
1150
def test_line_merge_revs_log_with_merges(self):
1151
wt = self.make_branch_and_memory_tree('.')
1153
self.addCleanup(wt.unlock)
1155
wt.commit('rev-1', rev_id='rev-1',
1156
timestamp=1132586655, timezone=36000,
1157
committer='Joe Foo <joe@foo.com>')
1158
wt.commit('rev-merged', rev_id='rev-2a',
1159
timestamp=1132586700, timezone=36000,
1160
committer='Joe Foo <joe@foo.com>')
1161
wt.set_parent_ids(['rev-1', 'rev-2a'])
1162
wt.branch.set_last_revision_info(1, 'rev-1')
1163
wt.commit('rev-2', rev_id='rev-2b',
1164
timestamp=1132586800, timezone=36000,
1165
committer='Joe Foo <joe@foo.com>')
1166
logfile = self.make_utf8_encoded_stringio()
1167
formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1168
log.show_log(wt.branch, formatter)
1169
self.assertEqualDiff("""\
1170
2: Joe Foo 2005-11-22 [merge] rev-2
1171
1.1.1: Joe Foo 2005-11-22 rev-merged
1172
1: Joe Foo 2005-11-22 rev-1
1176
class TestGetViewRevisions(tests.TestCaseWithTransport):
1178
def make_tree_with_commits(self):
1179
"""Create a tree with well-known revision ids"""
1180
wt = self.make_branch_and_tree('tree1')
1181
wt.commit('commit one', rev_id='1')
1182
wt.commit('commit two', rev_id='2')
1183
wt.commit('commit three', rev_id='3')
1184
mainline_revs = [None, '1', '2', '3']
1185
rev_nos = {'1': 1, '2': 2, '3': 3}
1186
return mainline_revs, rev_nos, wt
1188
def make_tree_with_merges(self):
1189
"""Create a tree with well-known revision ids and a merge"""
1190
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1191
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1192
tree2.commit('four-a', rev_id='4a')
1193
wt.merge_from_branch(tree2.branch)
1194
wt.commit('four-b', rev_id='4b')
1195
mainline_revs.append('4b')
1198
return mainline_revs, rev_nos, wt
1200
def make_branch_with_many_merges(self):
1201
"""Create a tree with well-known revision ids"""
1202
builder = self.make_branch_builder('tree1')
1203
builder.start_series()
1204
builder.build_snapshot('1', None, [
1205
('add', ('', 'TREE_ROOT', 'directory', '')),
1206
('add', ('f', 'f-id', 'file', '1\n'))])
1207
builder.build_snapshot('2', ['1'], [])
1208
builder.build_snapshot('3a', ['2'], [
1209
('modify', ('f-id', '1\n2\n3a\n'))])
1210
builder.build_snapshot('3b', ['2', '3a'], [
1211
('modify', ('f-id', '1\n2\n3a\n'))])
1212
builder.build_snapshot('3c', ['2', '3b'], [
1213
('modify', ('f-id', '1\n2\n3a\n'))])
1214
builder.build_snapshot('4a', ['3b'], [])
1215
builder.build_snapshot('4b', ['3c', '4a'], [])
1216
builder.finish_series()
1230
mainline_revs = [None, '1', '2', '3c', '4b']
1231
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
1232
full_rev_nos_for_reference = {
1235
'3a': '2.1.1', #first commit tree 3
1236
'3b': '2.2.1', # first commit tree 2
1237
'3c': '3', #merges 3b to main
1238
'4a': '2.2.2', # second commit tree 2
1239
'4b': '4', # merges 4a to main
1241
return mainline_revs, rev_nos, builder.get_branch()
1243
def test_get_view_revisions_forward(self):
1244
"""Test the get_view_revisions method"""
1245
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1247
self.addCleanup(wt.unlock)
1248
revisions = list(log.get_view_revisions(
1249
mainline_revs, rev_nos, wt.branch, 'forward'))
1250
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1252
revisions2 = list(log.get_view_revisions(
1253
mainline_revs, rev_nos, wt.branch, 'forward',
1254
include_merges=False))
1255
self.assertEqual(revisions, revisions2)
1257
def test_get_view_revisions_reverse(self):
1258
"""Test the get_view_revisions with reverse"""
1259
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1261
self.addCleanup(wt.unlock)
1262
revisions = list(log.get_view_revisions(
1263
mainline_revs, rev_nos, wt.branch, 'reverse'))
1264
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1266
revisions2 = list(log.get_view_revisions(
1267
mainline_revs, rev_nos, wt.branch, 'reverse',
1268
include_merges=False))
1269
self.assertEqual(revisions, revisions2)
1271
def test_get_view_revisions_merge(self):
1272
"""Test get_view_revisions when there are merges"""
1273
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1275
self.addCleanup(wt.unlock)
1276
revisions = list(log.get_view_revisions(
1277
mainline_revs, rev_nos, wt.branch, 'forward'))
1278
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1279
('4b', '4', 0), ('4a', '3.1.1', 1)],
1281
revisions = list(log.get_view_revisions(
1282
mainline_revs, rev_nos, wt.branch, 'forward',
1283
include_merges=False))
1284
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1288
def test_get_view_revisions_merge_reverse(self):
1289
"""Test get_view_revisions in reverse when there are merges"""
1290
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1292
self.addCleanup(wt.unlock)
1293
revisions = list(log.get_view_revisions(
1294
mainline_revs, rev_nos, wt.branch, 'reverse'))
1295
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1296
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1298
revisions = list(log.get_view_revisions(
1299
mainline_revs, rev_nos, wt.branch, 'reverse',
1300
include_merges=False))
1301
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1305
def test_get_view_revisions_merge2(self):
1306
"""Test get_view_revisions when there are merges"""
1307
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1309
self.addCleanup(b.unlock)
1310
revisions = list(log.get_view_revisions(
1311
mainline_revs, rev_nos, b, 'forward'))
1312
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1313
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1315
self.assertEqual(expected, revisions)
1316
revisions = list(log.get_view_revisions(
1317
mainline_revs, rev_nos, b, 'forward',
1318
include_merges=False))
1319
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1324
def test_file_id_for_range(self):
1325
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1327
self.addCleanup(b.unlock)
1329
def rev_from_rev_id(revid, branch):
1330
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1331
return revspec.in_history(branch)
1333
def view_revs(start_rev, end_rev, file_id, direction):
1334
revs = log.calculate_view_revisions(
1336
start_rev, # start_revision
1337
end_rev, # end_revision
1338
direction, # direction
1339
file_id, # specific_fileid
1340
True, # generate_merge_revisions
1344
rev_3a = rev_from_rev_id('3a', b)
1345
rev_4b = rev_from_rev_id('4b', b)
1346
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1347
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1348
# Note: 3c still appears before 3a here because of depth-based sorting
1349
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1), ('3a', '2.1.1', 2)],
1350
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1353
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1355
def create_tree_with_single_merge(self):
1356
"""Create a branch with a moderate layout.
1358
The revision graph looks like:
1366
In this graph, A introduced files f1 and f2 and f3.
1367
B modifies f1 and f3, and C modifies f2 and f3.
1368
D merges the changes from B and C and resolves the conflict for f3.
1370
# TODO: jam 20070218 This seems like it could really be done
1371
# with make_branch_and_memory_tree() if we could just
1372
# create the content of those files.
1373
# TODO: jam 20070218 Another alternative is that we would really
1374
# like to only create this tree 1 time for all tests that
1375
# use it. Since 'log' only uses the tree in a readonly
1376
# fashion, it seems a shame to regenerate an identical
1377
# tree for each test.
1378
tree = self.make_branch_and_tree('tree')
1380
self.addCleanup(tree.unlock)
1382
self.build_tree_contents([('tree/f1', 'A\n'),
1386
tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1387
tree.commit('A', rev_id='A')
1389
self.build_tree_contents([('tree/f2', 'A\nC\n'),
1390
('tree/f3', 'A\nC\n'),
1392
tree.commit('C', rev_id='C')
1393
# Revert back to A to build the other history.
1394
tree.set_last_revision('A')
1395
tree.branch.set_last_revision_info(1, 'A')
1396
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1398
('tree/f3', 'A\nB\n'),
1400
tree.commit('B', rev_id='B')
1401
tree.set_parent_ids(['B', 'C'])
1402
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1403
('tree/f2', 'A\nC\n'),
1404
('tree/f3', 'A\nB\nC\n'),
1406
tree.commit('D', rev_id='D')
1408
# Switch to a read lock for this tree.
1409
# We still have an addCleanup(tree.unlock) pending
1414
def check_delta(self, delta, **kw):
1415
"""Check the filenames touched by a delta are as expected.
1417
Caller only have to pass in the list of files for each part, all
1418
unspecified parts are considered empty (and checked as such).
1420
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1421
# By default we expect an empty list
1422
expected = kw.get(n, [])
1423
# strip out only the path components
1424
got = [x[0] for x in getattr(delta, n)]
1425
self.assertEqual(expected, got)
1427
def test_tree_with_single_merge(self):
1428
"""Make sure the tree layout is correct."""
1429
tree = self.create_tree_with_single_merge()
1430
rev_A_tree = tree.branch.repository.revision_tree('A')
1431
rev_B_tree = tree.branch.repository.revision_tree('B')
1432
rev_C_tree = tree.branch.repository.revision_tree('C')
1433
rev_D_tree = tree.branch.repository.revision_tree('D')
1435
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1436
modified=['f1', 'f3'])
1438
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1439
modified=['f2', 'f3'])
1441
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1442
modified=['f2', 'f3'])
1444
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1445
modified=['f1', 'f3'])
1447
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
1448
"""Ensure _filter_revisions_touching_file_id returns the right values.
1450
Get the return value from _filter_revisions_touching_file_id and make
1451
sure they are correct.
1453
# The api for _filter_revisions_touching_file_id is a little crazy.
1454
# So we do the setup here.
1455
mainline = tree.branch.revision_history()
1456
mainline.insert(0, None)
1457
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1458
view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1460
actual_revs = log._filter_revisions_touching_file_id(
1463
list(view_revs_iter))
1464
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1466
def test_file_id_f1(self):
1467
tree = self.create_tree_with_single_merge()
1468
# f1 should be marked as modified by revisions A and B
1469
self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1471
def test_file_id_f2(self):
1472
tree = self.create_tree_with_single_merge()
1473
# f2 should be marked as modified by revisions A, C, and D
1474
# because D merged the changes from C.
1475
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1477
def test_file_id_f3(self):
1478
tree = self.create_tree_with_single_merge()
1479
# f3 should be marked as modified by revisions A, B, C, and D
1480
self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1482
def test_file_id_with_ghosts(self):
1483
# This is testing bug #209948, where having a ghost would cause
1484
# _filter_revisions_touching_file_id() to fail.
1485
tree = self.create_tree_with_single_merge()
1486
# We need to add a revision, so switch back to a write-locked tree
1487
# (still a single addCleanup(tree.unlock) pending).
1490
first_parent = tree.last_revision()
1491
tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1492
self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1493
tree.commit('commit with a ghost', rev_id='XX')
1494
self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1495
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1497
def test_unknown_file_id(self):
1498
tree = self.create_tree_with_single_merge()
1499
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1501
def test_empty_branch_unknown_file_id(self):
1502
tree = self.make_branch_and_tree('tree')
1503
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1506
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1508
def test_show_changed_revisions_verbose(self):
1509
tree = self.make_branch_and_tree('tree_a')
1510
self.build_tree(['tree_a/foo'])
1512
tree.commit('bar', rev_id='bar-id')
1513
s = self.make_utf8_encoded_stringio()
1514
log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1515
self.assertContainsRe(s.getvalue(), 'bar')
1516
self.assertNotContainsRe(s.getvalue(), 'foo')
1519
class TestLogFormatter(tests.TestCase):
1521
def test_short_committer(self):
1522
rev = revision.Revision('a-id')
1523
rev.committer = 'John Doe <jdoe@example.com>'
1524
lf = log.LogFormatter(None)
1525
self.assertEqual('John Doe', lf.short_committer(rev))
1526
rev.committer = 'John Smith <jsmith@example.com>'
1527
self.assertEqual('John Smith', lf.short_committer(rev))
1528
rev.committer = 'John Smith'
1529
self.assertEqual('John Smith', lf.short_committer(rev))
1530
rev.committer = 'jsmith@example.com'
1531
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1532
rev.committer = '<jsmith@example.com>'
1533
self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1534
rev.committer = 'John Smith jsmith@example.com'
1535
self.assertEqual('John Smith', lf.short_committer(rev))
1537
def test_short_author(self):
1538
rev = revision.Revision('a-id')
1539
rev.committer = 'John Doe <jdoe@example.com>'
1540
lf = log.LogFormatter(None)
1541
self.assertEqual('John Doe', lf.short_author(rev))
1542
rev.properties['author'] = 'John Smith <jsmith@example.com>'
1543
self.assertEqual('John Smith', lf.short_author(rev))
1544
rev.properties['author'] = 'John Smith'
1545
self.assertEqual('John Smith', lf.short_author(rev))
1546
rev.properties['author'] = 'jsmith@example.com'
1547
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1548
rev.properties['author'] = '<jsmith@example.com>'
1549
self.assertEqual('jsmith@example.com', lf.short_author(rev))
1550
rev.properties['author'] = 'John Smith jsmith@example.com'
1551
self.assertEqual('John Smith', lf.short_author(rev))
1552
del rev.properties['author']
1553
rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1554
'Jane Rey <jrey@example.com>')
1555
self.assertEqual('John Smith', lf.short_author(rev))
1558
class TestReverseByDepth(tests.TestCase):
1559
"""Test reverse_by_depth behavior.
1561
This is used to present revisions in forward (oldest first) order in a nice
1564
The tests use lighter revision description to ease reading.
1567
def assertReversed(self, forward, backward):
1568
# Transform the descriptions to suit the API: tests use (revno, depth),
1569
# while the API expects (revid, revno, depth)
1570
def complete_revisions(l):
1571
"""Transform the description to suit the API.
1573
Tests use (revno, depth) whil the API expects (revid, revno, depth).
1574
Since the revid is arbitrary, we just duplicate revno
1576
return [ (r, r, d) for r, d in l]
1577
forward = complete_revisions(forward)
1578
backward= complete_revisions(backward)
1579
self.assertEqual(forward, log.reverse_by_depth(backward))
1582
def test_mainline_revisions(self):
1583
self.assertReversed([( '1', 0), ('2', 0)],
1584
[('2', 0), ('1', 0)])
1586
def test_merged_revisions(self):
1587
self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1588
[('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
1589
def test_shifted_merged_revisions(self):
1590
"""Test irregular layout.
1592
Requesting revisions touching a file can produce "holes" in the depths.
1594
self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1595
[('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
1597
def test_merged_without_child_revisions(self):
1598
"""Test irregular layout.
1600
Revision ranges can produce "holes" in the depths.
1602
# When a revision of higher depth doesn't follow one of lower depth, we
1603
# assume a lower depth one is virtually there
1604
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1605
[('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1606
# So we get the same order after reversing below even if the original
1607
# revisions are not in the same order.
1608
self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1609
[('3', 3), ('4', 4), ('2', 2), ('1', 2),])
1612
class TestHistoryChange(tests.TestCaseWithTransport):
1614
def setup_a_tree(self):
1615
tree = self.make_branch_and_tree('tree')
1617
self.addCleanup(tree.unlock)
1618
tree.commit('1a', rev_id='1a')
1619
tree.commit('2a', rev_id='2a')
1620
tree.commit('3a', rev_id='3a')
1623
def setup_ab_tree(self):
1624
tree = self.setup_a_tree()
1625
tree.set_last_revision('1a')
1626
tree.branch.set_last_revision_info(1, '1a')
1627
tree.commit('2b', rev_id='2b')
1628
tree.commit('3b', rev_id='3b')
1631
def setup_ac_tree(self):
1632
tree = self.setup_a_tree()
1633
tree.set_last_revision(revision.NULL_REVISION)
1634
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1635
tree.commit('1c', rev_id='1c')
1636
tree.commit('2c', rev_id='2c')
1637
tree.commit('3c', rev_id='3c')
1640
def test_all_new(self):
1641
tree = self.setup_ab_tree()
1642
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1643
self.assertEqual([], old)
1644
self.assertEqual(['2a', '3a'], new)
1646
def test_all_old(self):
1647
tree = self.setup_ab_tree()
1648
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1649
self.assertEqual([], new)
1650
self.assertEqual(['2a', '3a'], old)
1652
def test_null_old(self):
1653
tree = self.setup_ab_tree()
1654
old, new = log.get_history_change(revision.NULL_REVISION,
1655
'3a', tree.branch.repository)
1656
self.assertEqual([], old)
1657
self.assertEqual(['1a', '2a', '3a'], new)
1659
def test_null_new(self):
1660
tree = self.setup_ab_tree()
1661
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1662
tree.branch.repository)
1663
self.assertEqual([], new)
1664
self.assertEqual(['1a', '2a', '3a'], old)
1666
def test_diverged(self):
1667
tree = self.setup_ab_tree()
1668
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1669
self.assertEqual(old, ['2a', '3a'])
1670
self.assertEqual(new, ['2b', '3b'])
1672
def test_unrelated(self):
1673
tree = self.setup_ac_tree()
1674
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1675
self.assertEqual(old, ['1a', '2a', '3a'])
1676
self.assertEqual(new, ['1c', '2c', '3c'])
1678
def test_show_branch_change(self):
1679
tree = self.setup_ab_tree()
1681
log.show_branch_change(tree.branch, s, 3, '3a')
1682
self.assertContainsRe(s.getvalue(),
1683
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1684
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1686
def test_show_branch_change_no_change(self):
1687
tree = self.setup_ab_tree()
1689
log.show_branch_change(tree.branch, s, 3, '3b')
1690
self.assertEqual(s.getvalue(),
1691
'Nothing seems to have changed\n')
1693
def test_show_branch_change_no_old(self):
1694
tree = self.setup_ab_tree()
1696
log.show_branch_change(tree.branch, s, 2, '2b')
1697
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1698
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1700
def test_show_branch_change_no_new(self):
1701
tree = self.setup_ab_tree()
1702
tree.branch.set_last_revision_info(2, '2b')
1704
log.show_branch_change(tree.branch, s, 3, '3b')
1705
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1706
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')