/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1685.1.80 by Wouter van Heyst
more code cleanup
2
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1685.1.80 by Wouter van Heyst
more code cleanup
7
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1685.1.80 by Wouter van Heyst
more code cleanup
12
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
16
17
import os
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
20
    branchbuilder,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
21
    errors,
22
    log,
23
    registry,
24
    revision,
25
    revisionspec,
26
    tests,
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
27
    gpg,
28
    trace,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
31
    BytesIO,
32
    )
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
33
34
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
35
class TestLogMixin(object):
36
37
    def wt_commit(self, wt, message, **kwargs):
38
        """Use some mostly fixed values for commits to simplify tests.
39
40
        Tests can use this function to get some commit attributes. The time
41
        stamp is incremented at each commit.
42
        """
43
        if getattr(self, 'timestamp', None) is None:
44
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
45
        else:
46
            self.timestamp += 1 # 1 second between each commit
47
        kwargs.setdefault('timestamp', self.timestamp)
48
        kwargs.setdefault('timezone', 0) # UTC
49
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
50
51
        return wt.commit(message, **kwargs)
52
53
54
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
55
56
    def setUp(self):
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
57
        super(TestCaseForLogFormatter, self).setUp()
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
58
        # keep a reference to the "current" custom prop. handler registry
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
59
        self.properties_handler_registry = log.properties_handler_registry
4325.4.3 by Vincent Ladeuil
More cleanups.
60
        # Use a clean registry for log
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
61
        log.properties_handler_registry = registry.Registry()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
62
4325.4.3 by Vincent Ladeuil
More cleanups.
63
        def restore():
64
            log.properties_handler_registry = self.properties_handler_registry
65
        self.addCleanup(restore)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
66
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
67
    def assertFormatterResult(self, result, branch, formatter_class,
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
68
                              formatter_kwargs=None, show_log_kwargs=None):
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
69
        logfile = self.make_utf8_encoded_stringio()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
70
        if formatter_kwargs is None:
71
            formatter_kwargs = {}
72
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
73
        if show_log_kwargs is None:
74
            show_log_kwargs = {}
75
        log.show_log(branch, formatter, **show_log_kwargs)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
76
        self.assertEqualDiff(result, logfile.getvalue())
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
77
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
78
    def make_standard_commit(self, branch_nick, **kwargs):
79
        wt = self.make_branch_and_tree('.')
80
        wt.lock_write()
81
        self.addCleanup(wt.unlock)
82
        self.build_tree(['a'])
83
        wt.add(['a'])
84
        wt.branch.nick = branch_nick
85
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
86
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
87
        self.wt_commit(wt, 'add a', **kwargs)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
88
        return wt
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
89
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
90
    def make_commits_with_trailing_newlines(self, wt):
91
        """Helper method for LogFormatter tests"""
92
        b = wt.branch
93
        b.nick = 'test'
6855.4.1 by Jelmer Vernooij
Yet more bees.
94
        self.build_tree_contents([('a', b'hello moto\n')])
95
        self.wt_commit(wt, 'simple log message', rev_id=b'a1')
96
        self.build_tree_contents([('b', b'goodbye\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
97
        wt.add('b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
98
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id=b'a2')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
99
6855.4.1 by Jelmer Vernooij
Yet more bees.
100
        self.build_tree_contents([('c', b'just another manic monday\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
101
        wt.add('c')
6855.4.1 by Jelmer Vernooij
Yet more bees.
102
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id=b'a3')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
103
        return b
104
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
105
    def _prepare_tree_with_merges(self, with_tags=False):
106
        wt = self.make_branch_and_memory_tree('.')
107
        wt.lock_write()
108
        self.addCleanup(wt.unlock)
109
        wt.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
110
        self.wt_commit(wt, 'rev-1', rev_id=b'rev-1')
111
        self.wt_commit(wt, 'rev-merged', rev_id=b'rev-2a')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
112
        wt.set_parent_ids(['rev-1', 'rev-2a'])
113
        wt.branch.set_last_revision_info(1, 'rev-1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
114
        self.wt_commit(wt, 'rev-2', rev_id=b'rev-2b')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
115
        if with_tags:
116
            branch = wt.branch
117
            branch.tags.set_tag('v0.2', 'rev-2b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
118
            self.wt_commit(wt, 'rev-3', rev_id=b'rev-3')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
119
            branch.tags.set_tag('v1.0rc1', 'rev-3')
120
            branch.tags.set_tag('v1.0', 'rev-3')
121
        return wt
122
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
123
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
124
class LogCatcher(log.LogFormatter):
4325.4.3 by Vincent Ladeuil
More cleanups.
125
    """Pull log messages into a list rather than displaying them.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
126
4325.4.3 by Vincent Ladeuil
More cleanups.
127
    To simplify testing we save logged revisions here rather than actually
4325.4.1 by Vincent Ladeuil
Some cleanups.
128
    formatting anything, so that we can precisely check the result without
4325.4.3 by Vincent Ladeuil
More cleanups.
129
    being dependent on the formatting.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
130
    """
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
131
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
132
    supports_merge_revisions = True
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
133
    supports_delta = True
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
134
    supports_diff = True
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
135
    preferred_levels = 0
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
136
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
137
    def __init__(self, *args, **kwargs):
138
        kwargs.update(dict(to_file=None))
139
        super(LogCatcher, self).__init__(*args, **kwargs)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
140
        self.revisions = []
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
141
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
142
    def log_revision(self, revision):
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
143
        self.revisions.append(revision)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
144
145
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
146
class TestShowLog(tests.TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
147
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
148
    def checkDelta(self, delta, **kw):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
149
        """Check the filenames touched by a delta are as expected.
150
151
        Caller only have to pass in the list of files for each part, all
152
        unspecified parts are considered empty (and checked as such).
153
        """
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
154
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
155
            # By default we expect an empty list
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
156
            expected = kw.get(n, [])
157
            # strip out only the path components
158
            got = [x[0] for x in getattr(delta, n)]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
159
            self.assertEqual(expected, got)
160
161
    def assertInvalidRevisonNumber(self, br, start, end):
162
        lf = LogCatcher()
163
        self.assertRaises(errors.InvalidRevisionNumber,
164
                          log.show_log, br, lf,
165
                          start_revision=start, end_revision=end)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
166
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
167
    def test_cur_revno(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
168
        wt = self.make_branch_and_tree('.')
169
        b = wt.branch
1092.3.4 by Robert Collins
update symlink branch to integration
170
171
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
172
        wt.commit('empty commit')
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
173
        log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
174
175
        # Since there is a single revision in the branch all the combinations
176
        # below should fail.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
177
        self.assertInvalidRevisonNumber(b, 2, 1)
178
        self.assertInvalidRevisonNumber(b, 1, 2)
179
        self.assertInvalidRevisonNumber(b, 0, 2)
180
        self.assertInvalidRevisonNumber(b, 1, 0)
181
        self.assertInvalidRevisonNumber(b, -1, 1)
182
        self.assertInvalidRevisonNumber(b, 1, -1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
183
184
    def test_empty_branch(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
185
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
186
187
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
188
        log.show_log(wt.branch, lf)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
189
        # no entries yet
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
190
        self.assertEqual([], lf.revisions)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
191
192
    def test_empty_commit(self):
193
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
194
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
195
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
196
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
197
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
198
        revs = lf.revisions
199
        self.assertEqual(1, len(revs))
200
        self.assertEqual('1', revs[0].revno)
201
        self.assertEqual('empty commit', revs[0].rev.message)
202
        self.checkDelta(revs[0].delta)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
203
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
204
    def test_simple_commit(self):
205
        wt = self.make_branch_and_tree('.')
206
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
207
        self.build_tree(['hello'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
208
        wt.add('hello')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
209
        wt.commit('add one file',
210
                  committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
211
                            u'<test@example.com>')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
212
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
213
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
214
        self.assertEqual(2, len(lf.revisions))
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
215
        # first one is most recent
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
216
        log_entry = lf.revisions[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
217
        self.assertEqual('2', log_entry.revno)
218
        self.assertEqual('add one file', log_entry.rev.message)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
219
        self.checkDelta(log_entry.delta, added=['hello'])
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
220
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
221
    def test_commit_message_with_control_chars(self):
222
        wt = self.make_branch_and_tree('.')
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
223
        msg = u"All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
224
        msg = msg.replace(u'\r', u'\n')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
225
        wt.commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
226
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
227
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
228
        committed_msg = lf.revisions[0].rev.message
4627.1.1 by Robert Collins
Review feedback per IanC.
229
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
230
            self.assertNotEqual(msg, committed_msg)
231
            self.assertTrue(len(committed_msg) > len(msg))
232
        else:
233
            self.assertEqual(msg, committed_msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
234
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
235
    def test_commit_message_without_control_chars(self):
236
        wt = self.make_branch_and_tree('.')
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
237
        # escaped.  As ElementTree apparently does some kind of
238
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
239
        # included in the test commit message, even though they are
240
        # valid XML 1.0 characters.
241
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
242
        wt.commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
243
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
244
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
245
        committed_msg = lf.revisions[0].rev.message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
246
        self.assertEqual(msg, committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
247
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
248
    def test_deltas_in_merge_revisions(self):
249
        """Check deltas created for both mainline and merge revisions"""
250
        wt = self.make_branch_and_tree('parent')
251
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
252
        wt.add('file1')
253
        wt.add('file2')
254
        wt.commit(message='add file1 and file2')
2581.1.6 by Martin Pool
fix up more run_bzr callers
255
        self.run_bzr('branch parent child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
256
        os.unlink('child/file1')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
257
        with file('child/file2', 'wb') as f: f.write('hello\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
258
        self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
259
            'child'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
260
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
261
        self.run_bzr('merge ../child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
262
        wt.commit('merge child branch')
263
        os.chdir('..')
264
        b = wt.branch
265
        lf = LogCatcher()
266
        lf.supports_merge_revisions = True
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
267
        log.show_log(b, lf, verbose=True)
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
268
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
269
        revs = lf.revisions
270
        self.assertEqual(3, len(revs))
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
271
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
272
        logentry = revs[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
273
        self.assertEqual('2', logentry.revno)
274
        self.assertEqual('merge child branch', logentry.rev.message)
275
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
276
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
277
        logentry = revs[1]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
278
        self.assertEqual('1.1.1', logentry.revno)
279
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
280
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
281
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
282
        logentry = revs[2]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
283
        self.assertEqual('1', logentry.revno)
284
        self.assertEqual('add file1 and file2', logentry.rev.message)
285
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
286
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
287
    def test_bug_842695_log_restricted_to_dir(self):
288
        # Comments here indicate revision numbers in trunk  # VVVVV
289
        trunk = self.make_branch_and_tree('this')
290
        trunk.commit('initial trunk')                       # 1
6833.5.1 by Jelmer Vernooij
Merge lp:~gagern/bzr/bug842695-log-dir.
291
        adder = trunk.controldir.sprout('adder').open_workingtree()
292
        merger = trunk.controldir.sprout('merger').open_workingtree()
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
293
        self.build_tree_contents([
294
            ('adder/dir/',),
6855.4.1 by Jelmer Vernooij
Yet more bees.
295
            ('adder/dir/file', b'foo'),
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
296
            ])
297
        adder.add(['dir', 'dir/file'])
298
        adder.commit('added dir')                           # 1.1.1
299
        trunk.merge_from_branch(adder.branch)
300
        trunk.commit('merged adder into trunk')             # 2
301
        merger.merge_from_branch(trunk.branch)
302
        merger.commit('merged trunk into merger')           # 1.2.1
303
        # Commits are processed in increments of 200 revisions, so
304
        # make sure the two merges into trunk are in different chunks.
305
        for i in xrange(200):
306
            trunk.commit('intermediate commit %d' % i)      # 3-202
307
        trunk.merge_from_branch(merger.branch)
308
        trunk.commit('merged merger into trunk')            # 203
309
        file_id = trunk.path2id('dir')
310
        lf = LogCatcher()
311
        lf.supports_merge_revisions = True
312
        log.show_log(trunk.branch, lf, file_id)
6833.5.1 by Jelmer Vernooij
Merge lp:~gagern/bzr/bug842695-log-dir.
313
        try:
314
            self.assertEqual(['2', '1.1.1'], [r.revno for r in lf.revisions])
315
        except AssertionError:
316
            raise tests.KnownFailure("bug #842695")
317
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
318
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
319
class TestFormatSignatureValidity(tests.TestCaseWithTransport):
6883.11.3 by Jelmer Vernooij
Fix tests.
320
321
    def verify_revision_signature(self, revid, gpg_strategy):
322
        return (gpg.SIGNATURE_VALID,
323
            u'UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>')
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
324
325
    def test_format_signature_validity_utf(self):
326
        """Check that GPG signatures containing UTF-8 names are formatted
327
        correctly."""
328
        wt = self.make_branch_and_tree('.')
329
        revid = wt.commit('empty commit')
330
        repo = wt.branch.repository
331
        # Monkey patch out checking if this rev is actually signed, since we
332
        # can't sign it without a heavier TestCase and LoopbackGPGStrategy
333
        # doesn't care anyways.
6883.11.3 by Jelmer Vernooij
Fix tests.
334
        self.overrideAttr(repo, 'verify_revision_signature',
335
                self.verify_revision_signature)
6767.1.2 by Jelmer Vernooij
Fix a test.
336
        out = log.format_signature_validity(revid, wt.branch)
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
337
        self.assertEqual(
338
u'valid signature from UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>',
339
                out)
6129.2.1 by Martin von Gagern
Test case exposing bug #842695.
340
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
341
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
342
class TestShortLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
343
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
344
    def test_trailing_newlines(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
345
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
346
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
347
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
348
    3 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
349
      single line with trailing newline
350
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
351
    2 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
352
      multiline
353
      log
354
      message
355
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
356
    1 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
357
      simple log message
358
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
359
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
360
            b, log.ShortLogFormatter)
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
361
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
362
    def test_short_log_with_merges(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
363
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
364
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
365
    2 Joe Foo\t2005-11-22 [merge]
366
      rev-2
367
368
    1 Joe Foo\t2005-11-22
369
      rev-1
370
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
371
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
372
            wt.branch, log.ShortLogFormatter)
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
373
374
    def test_short_log_with_merges_and_advice(self):
375
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
376
        self.assertFormatterResult("""\
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
377
    2 Joe Foo\t2005-11-22 [merge]
378
      rev-2
379
380
    1 Joe Foo\t2005-11-22
381
      rev-1
382
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
383
Use --include-merged or -n0 to see merged revisions.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
384
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
385
            wt.branch, log.ShortLogFormatter,
386
            formatter_kwargs=dict(show_advice=True))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
387
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
388
    def test_short_log_with_merges_and_range(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
389
        wt = self._prepare_tree_with_merges()
6855.4.1 by Jelmer Vernooij
Yet more bees.
390
        self.wt_commit(wt, 'rev-3a', rev_id=b'rev-3a')
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
391
        wt.branch.set_last_revision_info(2, 'rev-2b')
392
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
393
        self.wt_commit(wt, 'rev-3b', rev_id=b'rev-3b')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
394
        self.assertFormatterResult("""\
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
395
    3 Joe Foo\t2005-11-22 [merge]
396
      rev-3b
397
398
    2 Joe Foo\t2005-11-22 [merge]
4955.4.19 by Vincent Ladeuil
Less code duplication.
399
      rev-2
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
400
401
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
402
            wt.branch, log.ShortLogFormatter,
403
            show_log_kwargs=dict(start_revision=2, end_revision=3))
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
404
3946.3.2 by Ian Clatworthy
add tests & NEWS item
405
    def test_short_log_with_tags(self):
406
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
407
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
408
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
3946.3.2 by Ian Clatworthy
add tests & NEWS item
409
      rev-3
410
411
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
412
      rev-2
413
414
    1 Joe Foo\t2005-11-22
415
      rev-1
416
417
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
418
            wt.branch, log.ShortLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
419
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
420
    def test_short_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
421
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
422
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
423
        rev = revspec.in_history(wt.branch)
424
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
425
      1.1.1 Joe Foo\t2005-11-22
426
            rev-merged
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
427
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
428
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
429
            wt.branch, log.ShortLogFormatter,
430
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
431
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
432
    def test_show_ids(self):
433
        wt = self.make_branch_and_tree('parent')
434
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
435
        wt.add(['f1', 'f2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
436
        self.wt_commit(wt, 'first post', rev_id=b'a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
437
        child_wt = wt.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
438
        self.wt_commit(child_wt, 'branch 1 changes', rev_id=b'b')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
439
        wt.merge_from_branch(child_wt.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
440
        self.wt_commit(wt, 'merge branch 1', rev_id=b'c')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
441
        self.assertFormatterResult("""\
442
    2 Joe Foo\t2005-11-22 [merge]
443
      revision-id:c
444
      merge branch 1
445
446
          1.1.1 Joe Foo\t2005-11-22
447
                revision-id:b
448
                branch 1 changes
449
450
    1 Joe Foo\t2005-11-22
451
      revision-id:a
452
      first post
453
454
""",
455
            wt.branch, log.ShortLogFormatter,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
456
            formatter_kwargs=dict(levels=0, show_ids=True))
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
457
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
458
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
459
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
460
461
    def test_short_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
462
        wt = self._prepare_tree_with_merges()
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
463
        # Note that the 1.1.1 indenting is in fact correct given that
464
        # the revision numbers are right justified within 5 characters
465
        # for mainline revnos and 9 characters for dotted revnos.
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
466
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
467
    2 Joe Foo\t2005-11-22 [merge]
468
      rev-2
469
3947.1.10 by Ian Clatworthy
review feedback from vila
470
          1.1.1 Joe Foo\t2005-11-22
471
                rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
472
473
    1 Joe Foo\t2005-11-22
474
      rev-1
475
476
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
477
            wt.branch, log.ShortLogFormatter,
478
            formatter_kwargs=dict(levels=0))
3947.1.2 by Ian Clatworthy
formatter tests
479
480
    def test_short_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
481
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
482
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
483
        rev = revspec.in_history(wt.branch)
484
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
485
      1.1.1 Joe Foo\t2005-11-22
486
            rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
487
488
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
489
            wt.branch, log.ShortLogFormatter,
490
            formatter_kwargs=dict(levels=0),
491
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
492
493
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
494
class TestLongLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
495
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
496
    def test_verbose_log(self):
497
        """Verbose log includes changed files
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
498
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
499
        bug #4676
500
        """
4857.4.4 by John Arbash Meinel
One more standard-commit
501
        wt = self.make_standard_commit('test_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
502
        self.assertFormatterResult('''\
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
503
------------------------------------------------------------
504
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
505
committer: Lorem Ipsum <test@example.com>
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
506
branch nick: test_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
507
timestamp: Tue 2005-11-22 00:00:00 +0000
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
508
message:
509
  add a
510
added:
511
  a
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
512
''',
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
513
            wt.branch, log.LongLogFormatter,
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
514
            show_log_kwargs=dict(verbose=True))
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
515
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
516
    def test_merges_are_indented_by_level(self):
517
        wt = self.make_branch_and_tree('parent')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
518
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
519
        child_wt = wt.controldir.sprout('child').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
520
        self.wt_commit(child_wt, 'branch 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
521
        smallerchild_wt = wt.controldir.sprout('smallerchild').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
522
        self.wt_commit(smallerchild_wt, 'branch 2')
523
        child_wt.merge_from_branch(smallerchild_wt.branch)
524
        self.wt_commit(child_wt, 'merge branch 2')
525
        wt.merge_from_branch(child_wt.branch)
526
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
527
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
528
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
529
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
530
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
531
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
532
timestamp: Tue 2005-11-22 00:00:04 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
533
message:
534
  merge branch 1
535
    ------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
536
    revno: 1.1.2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
537
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
538
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
539
    timestamp: Tue 2005-11-22 00:00:03 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
540
    message:
541
      merge branch 2
542
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
543
        revno: 1.2.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
544
        committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
545
        branch nick: smallerchild
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
546
        timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
547
        message:
548
          branch 2
549
    ------------------------------------------------------------
550
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
551
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
552
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
553
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
554
    message:
555
      branch 1
556
------------------------------------------------------------
557
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
558
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
559
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
560
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
561
message:
562
  first post
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
563
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
564
            wt.branch, log.LongLogFormatter,
565
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
566
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
567
568
    def test_verbose_merge_revisions_contain_deltas(self):
569
        wt = self.make_branch_and_tree('parent')
570
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
571
        wt.add(['f1', 'f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
572
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
573
        child_wt = wt.controldir.sprout('child').open_workingtree()
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
574
        os.unlink('child/f1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
575
        self.build_tree_contents([('child/f2', b'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
576
        self.wt_commit(child_wt, 'removed f1 and modified f2')
577
        wt.merge_from_branch(child_wt.branch)
578
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
579
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
580
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
581
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
582
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
583
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
584
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
585
message:
586
  merge branch 1
587
removed:
588
  f1
589
modified:
590
  f2
591
    ------------------------------------------------------------
592
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
593
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
594
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
595
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
596
    message:
597
      removed f1 and modified f2
598
    removed:
599
      f1
600
    modified:
601
      f2
602
------------------------------------------------------------
603
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
604
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
605
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
606
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
607
message:
608
  first post
609
added:
610
  f1
611
  f2
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
612
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
613
            wt.branch, log.LongLogFormatter,
614
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
615
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
616
617
    def test_trailing_newlines(self):
618
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
619
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
620
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
621
------------------------------------------------------------
622
revno: 3
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
623
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
624
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
625
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
626
message:
627
  single line with trailing newline
628
------------------------------------------------------------
629
revno: 2
630
committer: Joe Foo <joe@foo.com>
631
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
632
timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
633
message:
634
  multiline
635
  log
636
  message
637
------------------------------------------------------------
638
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
639
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
640
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
641
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
642
message:
643
  simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
644
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
645
        b, log.LongLogFormatter)
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
646
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
647
    def test_author_in_log(self):
648
        """Log includes the author name if it's set in
649
        the revision properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
650
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
651
        wt = self.make_standard_commit('test_author_log',
652
            authors=['John Doe <jdoe@example.com>',
653
                     'Jane Rey <jrey@example.com>'])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
654
        self.assertFormatterResult("""\
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
655
------------------------------------------------------------
656
revno: 1
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
657
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
2671.5.4 by Lukáš Lalinsky
Replace the committer with the author in log, the committer is displayed only in the long format and only if it's different from the author.
658
committer: Lorem Ipsum <test@example.com>
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
659
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
660
timestamp: Tue 2005-11-22 00:00:00 +0000
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
661
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
662
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
663
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
664
        wt.branch, log.LongLogFormatter)
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
665
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
666
    def test_properties_in_log(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
667
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
668
        handlers.
669
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
670
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
671
        def trivial_custom_prop_handler(revision):
672
            return {'test_prop':'test_value'}
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
673
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
674
        # Cleaned up in setUp()
675
        log.properties_handler_registry.register(
676
            'trivial_custom_prop_handler',
677
            trivial_custom_prop_handler)
678
        self.assertFormatterResult("""\
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
679
------------------------------------------------------------
680
revno: 1
681
test_prop: test_value
682
author: John Doe <jdoe@example.com>
683
committer: Lorem Ipsum <test@example.com>
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
684
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
685
timestamp: Tue 2005-11-22 00:00:00 +0000
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
686
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
687
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
688
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
689
            wt.branch, log.LongLogFormatter)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
690
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
691
    def test_properties_in_short_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
692
        """Log includes the custom properties returned by the registered
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
693
        handlers.
694
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
695
        wt = self.make_standard_commit('test_properties_in_short_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
696
        def trivial_custom_prop_handler(revision):
697
            return {'test_prop':'test_value'}
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
698
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
699
        log.properties_handler_registry.register(
700
            'trivial_custom_prop_handler',
701
            trivial_custom_prop_handler)
702
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
703
    1 John Doe\t2005-11-22
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
704
      test_prop: test_value
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
705
      add a
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
706
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
707
""",
708
            wt.branch, log.ShortLogFormatter)
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
709
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
710
    def test_error_in_properties_handler(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
711
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
712
        handlers.
713
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
714
        wt = self.make_standard_commit('error_in_properties_handler',
715
            revprops={'first_prop':'first_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
716
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
717
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
718
        def trivial_custom_prop_handler(revision):
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
719
            raise Exception("a test error")
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
720
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
721
        log.properties_handler_registry.register(
722
            'trivial_custom_prop_handler',
723
            trivial_custom_prop_handler)
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
724
        self.assertRaises(Exception, log.show_log, wt.branch, formatter,)
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
725
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
726
    def test_properties_handler_bad_argument(self):
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
727
        wt = self.make_standard_commit('bad_argument',
728
              revprops={'a_prop':'test_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
729
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
730
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
731
        def bad_argument_prop_handler(revision):
732
            return {'custom_prop_name':revision.properties['a_prop']}
733
734
        log.properties_handler_registry.register(
735
            'bad_argument_prop_handler',
736
            bad_argument_prop_handler)
737
738
        self.assertRaises(AttributeError, formatter.show_properties,
739
                          'a revision', '')
740
741
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
742
        formatter.show_properties(revision, '')
743
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
744
                             sio.getvalue())
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
745
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
746
    def test_show_ids(self):
747
        wt = self.make_branch_and_tree('parent')
748
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
749
        wt.add(['f1', 'f2'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
750
        self.wt_commit(wt, 'first post', rev_id=b'a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
751
        child_wt = wt.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
752
        self.wt_commit(child_wt, 'branch 1 changes', rev_id=b'b')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
753
        wt.merge_from_branch(child_wt.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
754
        self.wt_commit(wt, 'merge branch 1', rev_id=b'c')
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
755
        self.assertFormatterResult("""\
756
------------------------------------------------------------
757
revno: 2 [merge]
758
revision-id: c
759
parent: a
760
parent: b
761
committer: Joe Foo <joe@foo.com>
762
branch nick: parent
763
timestamp: Tue 2005-11-22 00:00:02 +0000
764
message:
765
  merge branch 1
766
    ------------------------------------------------------------
767
    revno: 1.1.1
768
    revision-id: b
769
    parent: a
770
    committer: Joe Foo <joe@foo.com>
771
    branch nick: child
772
    timestamp: Tue 2005-11-22 00:00:01 +0000
773
    message:
774
      branch 1 changes
775
------------------------------------------------------------
776
revno: 1
777
revision-id: a
778
committer: Joe Foo <joe@foo.com>
779
branch nick: parent
780
timestamp: Tue 2005-11-22 00:00:00 +0000
781
message:
782
  first post
783
""",
784
            wt.branch, log.LongLogFormatter,
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
785
            formatter_kwargs=dict(levels=0, show_ids=True))
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
786
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
787
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
788
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
789
790
    def test_long_verbose_log(self):
791
        """Verbose log includes changed files
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
792
3947.1.2 by Ian Clatworthy
formatter tests
793
        bug #4676
794
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
795
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
796
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
797
------------------------------------------------------------
798
revno: 1
799
committer: Lorem Ipsum <test@example.com>
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
800
branch nick: test_long_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
801
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
802
message:
803
  add a
804
added:
805
  a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
806
""",
807
            wt.branch, log.LongLogFormatter,
808
            formatter_kwargs=dict(levels=1),
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
809
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
810
811
    def test_long_verbose_contain_deltas(self):
812
        wt = self.make_branch_and_tree('parent')
813
        self.build_tree(['parent/f1', 'parent/f2'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
814
        wt.add(['f1', 'f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
815
        self.wt_commit(wt, 'first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
816
        child_wt = wt.controldir.sprout('child').open_workingtree()
3947.1.2 by Ian Clatworthy
formatter tests
817
        os.unlink('child/f1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
818
        self.build_tree_contents([('child/f2', b'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
819
        self.wt_commit(child_wt, 'removed f1 and modified f2')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
820
        wt.merge_from_branch(child_wt.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
821
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
822
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
823
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
824
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
825
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
826
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
827
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
828
message:
829
  merge branch 1
830
removed:
831
  f1
832
modified:
833
  f2
834
------------------------------------------------------------
835
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
836
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
837
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
838
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
839
message:
840
  first post
841
added:
842
  f1
843
  f2
844
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
845
            wt.branch, log.LongLogFormatter,
846
            formatter_kwargs=dict(levels=1),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
847
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
848
849
    def test_long_trailing_newlines(self):
850
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
851
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
852
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
853
------------------------------------------------------------
854
revno: 3
855
committer: Joe Foo <joe@foo.com>
856
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
857
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
858
message:
859
  single line with trailing newline
860
------------------------------------------------------------
861
revno: 2
862
committer: Joe Foo <joe@foo.com>
863
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
864
timestamp: Tue 2005-11-22 00:00:01 +0000
3947.1.2 by Ian Clatworthy
formatter tests
865
message:
866
  multiline
867
  log
868
  message
869
------------------------------------------------------------
870
revno: 1
871
committer: Joe Foo <joe@foo.com>
872
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
873
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
874
message:
875
  simple log message
876
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
877
        b, log.LongLogFormatter,
878
        formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
879
880
    def test_long_author_in_log(self):
881
        """Log includes the author name if it's set in
882
        the revision properties
883
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
884
        wt = self.make_standard_commit('test_author_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
885
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
886
------------------------------------------------------------
887
revno: 1
888
author: John Doe <jdoe@example.com>
889
committer: Lorem Ipsum <test@example.com>
890
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
891
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
892
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
893
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
894
""",
895
            wt.branch, log.LongLogFormatter,
896
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
897
898
    def test_long_properties_in_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
899
        """Log includes the custom properties returned by the registered
3947.1.2 by Ian Clatworthy
formatter tests
900
        handlers.
901
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
902
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
903
        def trivial_custom_prop_handler(revision):
904
            return {'test_prop':'test_value'}
3947.1.2 by Ian Clatworthy
formatter tests
905
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
906
        log.properties_handler_registry.register(
907
            'trivial_custom_prop_handler',
908
            trivial_custom_prop_handler)
909
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
910
------------------------------------------------------------
911
revno: 1
912
test_prop: test_value
913
author: John Doe <jdoe@example.com>
914
committer: Lorem Ipsum <test@example.com>
915
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
916
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
917
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
918
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
919
""",
920
            wt.branch, log.LongLogFormatter,
921
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
922
923
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
924
class TestLineLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
925
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
926
    def test_line_log(self):
927
        """Line log should show revno
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
928
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
929
        bug #5162
930
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
931
        wt = self.make_standard_commit('test-line-log',
932
                committer='Line-Log-Formatter Tester <test@line.log>',
933
                authors=[])
934
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
935
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
936
""",
937
            wt.branch, log.LineLogFormatter)
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
938
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
939
    def test_trailing_newlines(self):
940
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
941
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
942
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
943
3: Joe Foo 2005-11-22 single line with trailing newline
944
2: Joe Foo 2005-11-22 multiline
945
1: Joe Foo 2005-11-22 simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
946
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
947
            b, log.LineLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
948
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
949
    def test_line_log_single_merge_revision(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
950
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
951
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
952
        rev = revspec.in_history(wt.branch)
953
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
954
1.1.1: Joe Foo 2005-11-22 rev-merged
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
955
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
956
            wt.branch, log.LineLogFormatter,
957
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
958
3946.3.2 by Ian Clatworthy
add tests & NEWS item
959
    def test_line_log_with_tags(self):
960
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
961
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
962
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
963
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
3946.3.2 by Ian Clatworthy
add tests & NEWS item
964
1: Joe Foo 2005-11-22 rev-1
965
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
966
            wt.branch, log.LineLogFormatter)
967
968
969
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
970
971
    def test_line_merge_revs_log(self):
972
        """Line log should show revno
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
973
3947.1.2 by Ian Clatworthy
formatter tests
974
        bug #5162
975
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
976
        wt = self.make_standard_commit('test-line-log',
977
                committer='Line-Log-Formatter Tester <test@line.log>',
978
                authors=[])
979
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
980
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
981
""",
982
            wt.branch, log.LineLogFormatter)
3947.1.2 by Ian Clatworthy
formatter tests
983
984
    def test_line_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
985
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
986
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
987
        rev = revspec.in_history(wt.branch)
988
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
989
1.1.1: Joe Foo 2005-11-22 rev-merged
990
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
991
            wt.branch, log.LineLogFormatter,
992
            formatter_kwargs=dict(levels=0),
993
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
994
995
    def test_line_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
996
        wt = self._prepare_tree_with_merges()
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
997
        self.assertFormatterResult("""\
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
998
2: Joe Foo 2005-11-22 [merge] rev-2
3947.1.2 by Ian Clatworthy
formatter tests
999
  1.1.1: Joe Foo 2005-11-22 rev-merged
1000
1: Joe Foo 2005-11-22 rev-1
1001
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
1002
            wt.branch, log.LineLogFormatter,
1003
            formatter_kwargs=dict(levels=0))
1004
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
1005
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
1006
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
1007
1008
    def test_gnu_changelog(self):
1009
        wt = self.make_standard_commit('nicky', authors=[])
1010
        self.assertFormatterResult('''\
1011
2005-11-22  Lorem Ipsum  <test@example.com>
1012
1013
\tadd a
1014
1015
''',
1016
            wt.branch, log.GnuChangelogLogFormatter)
1017
1018
    def test_with_authors(self):
1019
        wt = self.make_standard_commit('nicky',
1020
            authors=['Fooa Fooz <foo@example.com>',
1021
                     'Bari Baro <bar@example.com>'])
1022
        self.assertFormatterResult('''\
1023
2005-11-22  Fooa Fooz  <foo@example.com>
1024
1025
\tadd a
1026
1027
''',
1028
            wt.branch, log.GnuChangelogLogFormatter)
1029
1030
    def test_verbose(self):
1031
        wt = self.make_standard_commit('nicky')
1032
        self.assertFormatterResult('''\
1033
2005-11-22  John Doe  <jdoe@example.com>
1034
1035
\t* a:
1036
1037
\tadd a
1038
1039
''',
1040
            wt.branch, log.GnuChangelogLogFormatter,
1041
            show_log_kwargs=dict(verbose=True))
1042
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1043
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1044
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1045
1046
    def test_show_changed_revisions_verbose(self):
1047
        tree = self.make_branch_and_tree('tree_a')
1048
        self.build_tree(['tree_a/foo'])
1049
        tree.add('foo')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1050
        tree.commit('bar', rev_id=b'bar-id')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
1051
        s = self.make_utf8_encoded_stringio()
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1052
        log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1053
        self.assertContainsRe(s.getvalue(), 'bar')
1054
        self.assertNotContainsRe(s.getvalue(), 'foo')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1055
1056
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1057
class TestLogFormatter(tests.TestCase):
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1058
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1059
    def setUp(self):
1060
        super(TestLogFormatter, self).setUp()
1061
        self.rev = revision.Revision('a-id')
1062
        self.lf = log.LogFormatter(None)
1063
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1064
    def test_short_committer(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1065
        def assertCommitter(expected, committer):
1066
            self.rev.committer = committer
1067
            self.assertEqual(expected, self.lf.short_committer(self.rev))
1068
1069
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1070
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1071
        assertCommitter('John Smith', 'John Smith')
1072
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
1073
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1074
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1075
1076
    def test_short_author(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1077
        def assertAuthor(expected, author):
1078
            self.rev.properties['author'] = author
1079
            self.assertEqual(expected, self.lf.short_author(self.rev))
1080
1081
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1082
        assertAuthor('John Smith', 'John Smith')
1083
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
1084
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1085
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
1086
1087
    def test_short_author_from_committer(self):
1088
        self.rev.committer = 'John Doe <jdoe@example.com>'
1089
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
1090
1091
    def test_short_author_from_authors(self):
1092
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1093
                                          'Jane Rey <jrey@example.com>')
1094
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1095
1096
1097
class TestReverseByDepth(tests.TestCase):
1098
    """Test reverse_by_depth behavior.
1099
1100
    This is used to present revisions in forward (oldest first) order in a nice
1101
    layout.
1102
1103
    The tests use lighter revision description to ease reading.
1104
    """
1105
1106
    def assertReversed(self, forward, backward):
1107
        # Transform the descriptions to suit the API: tests use (revno, depth),
1108
        # while the API expects (revid, revno, depth)
1109
        def complete_revisions(l):
1110
            """Transform the description to suit the API.
1111
1112
            Tests use (revno, depth) whil the API expects (revid, revno, depth).
1113
            Since the revid is arbitrary, we just duplicate revno
1114
            """
1115
            return [ (r, r, d) for r, d in l]
1116
        forward = complete_revisions(forward)
1117
        backward= complete_revisions(backward)
1118
        self.assertEqual(forward, log.reverse_by_depth(backward))
1119
1120
1121
    def test_mainline_revisions(self):
1122
        self.assertReversed([( '1', 0), ('2', 0)],
1123
                            [('2', 0), ('1', 0)])
1124
1125
    def test_merged_revisions(self):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1126
        self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1127
                            [('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1128
    def test_shifted_merged_revisions(self):
1129
        """Test irregular layout.
1130
1131
        Requesting revisions touching a file can produce "holes" in the depths.
1132
        """
1133
        self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1134
                            [('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1135
1136
    def test_merged_without_child_revisions(self):
1137
        """Test irregular layout.
1138
1139
        Revision ranges can produce "holes" in the depths.
1140
        """
1141
        # When a revision of higher depth doesn't follow one of lower depth, we
1142
        # assume a lower depth one is virtually there
1143
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1144
                            [('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1145
        # So we get the same order after reversing below even if the original
1146
        # revisions are not in the same order.
1147
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1148
                            [('3', 3), ('4', 4), ('2', 2), ('1', 2),])
3848.1.6 by Aaron Bentley
Implement get_history_change
1149
1150
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1151
class TestHistoryChange(tests.TestCaseWithTransport):
3848.1.6 by Aaron Bentley
Implement get_history_change
1152
1153
    def setup_a_tree(self):
1154
        tree = self.make_branch_and_tree('tree')
1155
        tree.lock_write()
1156
        self.addCleanup(tree.unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1157
        tree.commit('1a', rev_id=b'1a')
1158
        tree.commit('2a', rev_id=b'2a')
1159
        tree.commit('3a', rev_id=b'3a')
3848.1.6 by Aaron Bentley
Implement get_history_change
1160
        return tree
1161
1162
    def setup_ab_tree(self):
1163
        tree = self.setup_a_tree()
1164
        tree.set_last_revision('1a')
1165
        tree.branch.set_last_revision_info(1, '1a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1166
        tree.commit('2b', rev_id=b'2b')
1167
        tree.commit('3b', rev_id=b'3b')
3848.1.6 by Aaron Bentley
Implement get_history_change
1168
        return tree
1169
1170
    def setup_ac_tree(self):
1171
        tree = self.setup_a_tree()
1172
        tree.set_last_revision(revision.NULL_REVISION)
1173
        tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
6855.4.1 by Jelmer Vernooij
Yet more bees.
1174
        tree.commit('1c', rev_id=b'1c')
1175
        tree.commit('2c', rev_id=b'2c')
1176
        tree.commit('3c', rev_id=b'3c')
3848.1.6 by Aaron Bentley
Implement get_history_change
1177
        return tree
1178
1179
    def test_all_new(self):
1180
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1181
        old, new = log.get_history_change('1a', '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1182
        self.assertEqual([], old)
1183
        self.assertEqual(['2a', '3a'], new)
1184
1185
    def test_all_old(self):
1186
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1187
        old, new = log.get_history_change('3a', '1a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1188
        self.assertEqual([], new)
1189
        self.assertEqual(['2a', '3a'], old)
1190
1191
    def test_null_old(self):
1192
        tree = self.setup_ab_tree()
1193
        old, new = log.get_history_change(revision.NULL_REVISION,
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1194
                                          '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1195
        self.assertEqual([], old)
1196
        self.assertEqual(['1a', '2a', '3a'], new)
1197
1198
    def test_null_new(self):
1199
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1200
        old, new = log.get_history_change('3a', revision.NULL_REVISION,
1201
                                          tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1202
        self.assertEqual([], new)
1203
        self.assertEqual(['1a', '2a', '3a'], old)
1204
1205
    def test_diverged(self):
1206
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1207
        old, new = log.get_history_change('3a', '3b', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1208
        self.assertEqual(old, ['2a', '3a'])
1209
        self.assertEqual(new, ['2b', '3b'])
1210
1211
    def test_unrelated(self):
1212
        tree = self.setup_ac_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1213
        old, new = log.get_history_change('3a', '3c', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1214
        self.assertEqual(old, ['1a', '2a', '3a'])
1215
        self.assertEqual(new, ['1c', '2c', '3c'])
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1216
1217
    def test_show_branch_change(self):
1218
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1219
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1220
        log.show_branch_change(tree.branch, s, 3, '3a')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1221
        self.assertContainsRe(s.getvalue(),
1222
            '[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1223
            '[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1224
1225
    def test_show_branch_change_no_change(self):
1226
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1227
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1228
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1229
        self.assertEqual(s.getvalue(),
1230
            'Nothing seems to have changed\n')
1231
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1232
    def test_show_branch_change_no_old(self):
1233
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1234
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1235
        log.show_branch_change(tree.branch, s, 2, '2b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1236
        self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1237
        self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1238
1239
    def test_show_branch_change_no_new(self):
1240
        tree = self.setup_ab_tree()
1241
        tree.branch.set_last_revision_info(2, '2b')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1242
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1243
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1244
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1245
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1246
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1247
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1248
class TestRevisionNotInBranch(TestCaseForLogFormatter):
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1249
1250
    def setup_a_tree(self):
1251
        tree = self.make_branch_and_tree('tree')
1252
        tree.lock_write()
1253
        self.addCleanup(tree.unlock)
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1254
        kwargs = {
1255
            'committer': 'Joe Foo <joe@foo.com>',
1256
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1257
            'timezone': 0, # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1258
        }
6855.4.1 by Jelmer Vernooij
Yet more bees.
1259
        tree.commit('commit 1a', rev_id=b'1a', **kwargs)
1260
        tree.commit('commit 2a', rev_id=b'2a', **kwargs)
1261
        tree.commit('commit 3a', rev_id=b'3a', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1262
        return tree
1263
1264
    def setup_ab_tree(self):
1265
        tree = self.setup_a_tree()
1266
        tree.set_last_revision('1a')
1267
        tree.branch.set_last_revision_info(1, '1a')
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1268
        kwargs = {
1269
            'committer': 'Joe Foo <joe@foo.com>',
1270
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1271
            'timezone': 0, # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1272
        }
6855.4.1 by Jelmer Vernooij
Yet more bees.
1273
        tree.commit('commit 2b', rev_id=b'2b', **kwargs)
1274
        tree.commit('commit 3b', rev_id=b'3b', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1275
        return tree
1276
1277
    def test_one_revision(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1278
        tree = self.setup_ab_tree()
1279
        lf = LogCatcher()
1280
        rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1281
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1282
                     end_revision=rev)
1283
        self.assertEqual(1, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1284
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1285
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1286
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1287
    def test_many_revisions(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1288
        tree = self.setup_ab_tree()
1289
        lf = LogCatcher()
1290
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1291
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1292
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1293
                     end_revision=end_rev)
1294
        self.assertEqual(3, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1295
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1296
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1297
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
1298
        self.assertEqual('2a', lf.revisions[1].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1299
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1300
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1301
    def test_long_format(self):
1302
        tree = self.setup_ab_tree()
1303
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1304
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1305
        self.assertFormatterResult("""\
1306
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1307
revision-id: 3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1308
committer: Joe Foo <joe@foo.com>
1309
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1310
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1311
message:
1312
  commit 3a
1313
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1314
revision-id: 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1315
committer: Joe Foo <joe@foo.com>
1316
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1317
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1318
message:
1319
  commit 2a
1320
------------------------------------------------------------
1321
revno: 1
1322
committer: Joe Foo <joe@foo.com>
1323
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1324
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1325
message:
1326
  commit 1a
1327
""",
1328
            tree.branch, log.LongLogFormatter, show_log_kwargs={
1329
                'start_revision': start_rev, 'end_revision': end_rev
1330
            })
1331
1332
    def test_short_format(self):
1333
        tree = self.setup_ab_tree()
1334
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1335
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1336
        self.assertFormatterResult("""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1337
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1338
      revision-id:3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1339
      commit 3a
1340
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1341
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1342
      revision-id:2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1343
      commit 2a
1344
1345
    1 Joe Foo\t2005-11-22
1346
      commit 1a
1347
1348
""",
1349
            tree.branch, log.ShortLogFormatter, show_log_kwargs={
1350
                'start_revision': start_rev, 'end_revision': end_rev
1351
            })
1352
1353
    def test_line_format(self):
1354
        tree = self.setup_ab_tree()
1355
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1356
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1357
        self.assertFormatterResult("""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1358
Joe Foo 2005-11-22 commit 3a
1359
Joe Foo 2005-11-22 commit 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1360
1: Joe Foo 2005-11-22 commit 1a
1361
""",
1362
            tree.branch, log.LineLogFormatter, show_log_kwargs={
1363
                'start_revision': start_rev, 'end_revision': end_rev
1364
            })
1365
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1366
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1367
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1368
1369
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1370
        super(TestLogWithBugs, self).setUp()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1371
        log.properties_handler_registry.register(
1372
            'bugs_properties_handler',
1373
            log._bugs_properties_handler)
1374
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1375
    def make_commits_with_bugs(self):
1376
        """Helper method for LogFormatter tests"""
1377
        tree = self.make_branch_and_tree(u'.')
1378
        self.build_tree(['a', 'b'])
1379
        tree.add('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1380
        self.wt_commit(tree, 'simple log message', rev_id=b'a1',
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1381
                       revprops={'bugs': 'test://bug/id fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1382
        tree.add('b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1383
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id=b'a2',
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1384
                       authors=['Joe Bar <joe@bar.com>'],
1385
                       revprops={'bugs': 'test://bug/id fixed\n'
1386
                                 'test://bug/2 fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1387
        return tree
1388
1389
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1390
    def test_long_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1391
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1392
        self.assertFormatterResult("""\
1393
------------------------------------------------------------
1394
revno: 2
6143.1.8 by Jonathan Riddell
fix log formatting of bug line
1395
fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1396
author: Joe Bar <joe@bar.com>
1397
committer: Joe Foo <joe@foo.com>
1398
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1399
timestamp: Tue 2005-11-22 00:00:01 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1400
message:
1401
  multiline
1402
  log
1403
  message
1404
------------------------------------------------------------
1405
revno: 1
6143.1.4 by Jonathan Riddell
update tests
1406
fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1407
committer: Joe Foo <joe@foo.com>
1408
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1409
timestamp: Tue 2005-11-22 00:00:00 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1410
message:
1411
  simple log message
1412
""",
1413
            tree.branch, log.LongLogFormatter)
1414
1415
    def test_short_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1416
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1417
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1418
    2 Joe Bar\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1419
      fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1420
      multiline
1421
      log
1422
      message
1423
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1424
    1 Joe Foo\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1425
      fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1426
      simple log message
1427
1428
""",
1429
            tree.branch, log.ShortLogFormatter)
1430
1431
    def test_wrong_bugs_property(self):
1432
        tree = self.make_branch_and_tree(u'.')
1433
        self.build_tree(['foo'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1434
        self.wt_commit(tree, 'simple log message', rev_id=b'a1',
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1435
                       revprops={'bugs': 'test://bug/id invalid_value'})
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1436
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1437
    1 Joe Foo\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1438
      simple log message
1439
1440
""",
1441
            tree.branch, log.ShortLogFormatter)
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1442
1443
    def test_bugs_handler_present(self):
1444
        self.properties_handler_registry.get('bugs_properties_handler')
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1445
1446
1447
class TestLogForAuthors(TestCaseForLogFormatter):
1448
1449
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1450
        super(TestLogForAuthors, self).setUp()
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1451
        self.wt = self.make_standard_commit('nicky',
1452
            authors=['John Doe <jdoe@example.com>',
1453
                     'Jane Rey <jrey@example.com>'])
1454
1455
    def assertFormatterResult(self, formatter, who, result):
1456
        formatter_kwargs = dict()
1457
        if who is not None:
4081.3.10 by Martin von Gagern
Renamed "authors" to "author_list_handler" in several places.
1458
            author_list_handler = log.author_list_registry.get(who)
1459
            formatter_kwargs['author_list_handler'] = author_list_handler
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1460
        TestCaseForLogFormatter.assertFormatterResult(self, result,
1461
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
1462
1463
    def test_line_default(self):
1464
        self.assertFormatterResult(log.LineLogFormatter, None, """\
1465
1: John Doe 2005-11-22 add a
1466
""")
1467
1468
    def test_line_committer(self):
1469
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
1470
1: Lorem Ipsum 2005-11-22 add a
1471
""")
1472
1473
    def test_line_first(self):
1474
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
1475
1: John Doe 2005-11-22 add a
1476
""")
1477
1478
    def test_line_all(self):
1479
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
1480
1: John Doe, Jane Rey 2005-11-22 add a
1481
""")
1482
1483
1484
    def test_short_default(self):
1485
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
1486
    1 John Doe\t2005-11-22
1487
      add a
1488
1489
""")
1490
1491
    def test_short_committer(self):
1492
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
1493
    1 Lorem Ipsum\t2005-11-22
1494
      add a
1495
1496
""")
1497
1498
    def test_short_first(self):
1499
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
1500
    1 John Doe\t2005-11-22
1501
      add a
1502
1503
""")
1504
1505
    def test_short_all(self):
1506
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
1507
    1 John Doe, Jane Rey\t2005-11-22
1508
      add a
1509
1510
""")
1511
1512
    def test_long_default(self):
1513
        self.assertFormatterResult(log.LongLogFormatter, None, """\
1514
------------------------------------------------------------
1515
revno: 1
1516
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1517
committer: Lorem Ipsum <test@example.com>
1518
branch nick: nicky
1519
timestamp: Tue 2005-11-22 00:00:00 +0000
1520
message:
1521
  add a
1522
""")
1523
1524
    def test_long_committer(self):
1525
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
1526
------------------------------------------------------------
1527
revno: 1
1528
committer: Lorem Ipsum <test@example.com>
1529
branch nick: nicky
1530
timestamp: Tue 2005-11-22 00:00:00 +0000
1531
message:
1532
  add a
1533
""")
1534
1535
    def test_long_first(self):
1536
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
1537
------------------------------------------------------------
1538
revno: 1
1539
author: John Doe <jdoe@example.com>
1540
committer: Lorem Ipsum <test@example.com>
1541
branch nick: nicky
1542
timestamp: Tue 2005-11-22 00:00:00 +0000
1543
message:
1544
  add a
1545
""")
1546
1547
    def test_long_all(self):
1548
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
1549
------------------------------------------------------------
1550
revno: 1
1551
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1552
committer: Lorem Ipsum <test@example.com>
1553
branch nick: nicky
1554
timestamp: Tue 2005-11-22 00:00:00 +0000
1555
message:
1556
  add a
1557
""")
1558
1559
    def test_gnu_changelog_default(self):
1560
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
1561
2005-11-22  John Doe  <jdoe@example.com>
1562
1563
\tadd a
1564
1565
""")
1566
1567
    def test_gnu_changelog_committer(self):
1568
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
1569
2005-11-22  Lorem Ipsum  <test@example.com>
1570
1571
\tadd a
1572
1573
""")
1574
1575
    def test_gnu_changelog_first(self):
1576
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
1577
2005-11-22  John Doe  <jdoe@example.com>
1578
1579
\tadd a
1580
1581
""")
1582
1583
    def test_gnu_changelog_all(self):
1584
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
1585
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
1586
1587
\tadd a
1588
1589
""")
4081.3.15 by Gary van der Merwe
Merge bzr.dev.
1590
5691.1.3 by Jelmer Vernooij
Fix whitespace.
1591
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1592
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1593
1594
    def make_branch_with_alternate_ancestries(self, relpath='.'):
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1595
        # See test_merge_sorted_exclude_ancestry below for the difference with
1596
        # bt.per_branch.test_iter_merge_sorted_revision.
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1597
        # TestIterMergeSortedRevisionsBushyGraph.
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1598
        # make_branch_with_alternate_ancestries
1599
        # and test_merge_sorted_exclude_ancestry
1600
        # See the FIXME in assertLogRevnos too.
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1601
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1602
        # 1
1603
        # |\
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1604
        # 2 \
1605
        # |  |
1606
        # |  1.1.1
1607
        # |  | \
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1608
        # |  |  1.2.1
1609
        # |  | /
1610
        # |  1.1.2
1611
        # | /
1612
        # 3
1613
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1614
        builder.build_snapshot(None, [
1615
            ('add', ('', 'TREE_ROOT', 'directory', '')),],
1616
            revision_id='1')
1617
        builder.build_snapshot(['1'], [], revision_id='1.1.1')
1618
        builder.build_snapshot(['1'], [], revision_id='2')
1619
        builder.build_snapshot(['1.1.1'], [], revision_id='1.2.1')
1620
        builder.build_snapshot(['1.1.1', '1.2.1'], [], revision_id='1.1.2')
1621
        builder.build_snapshot(['2', '1.1.2'], [], revision_id='3')
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1622
        builder.finish_series()
1623
        br = builder.get_branch()
1624
        br.lock_read()
1625
        self.addCleanup(br.unlock)
1626
        return br
1627
1628
    def assertLogRevnos(self, expected_revnos, b, start, end,
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1629
                        exclude_common_ancestry, generate_merge_revisions=True):
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1630
        # FIXME: the layering in log makes it hard to test intermediate levels,
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
1631
        # I wish adding filters with their parameters was easier...
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1632
        # -- vila 20100413
1633
        iter_revs = log._calc_view_revisions(
1634
            b, start, end, direction='reverse',
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1635
            generate_merge_revisions=generate_merge_revisions,
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1636
            exclude_common_ancestry=exclude_common_ancestry)
1637
        self.assertEqual(expected_revnos,
1638
                         [revid for revid, revno, depth in iter_revs])
1639
1640
    def test_merge_sorted_exclude_ancestry(self):
1641
        b = self.make_branch_with_alternate_ancestries()
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1642
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1643
                             b, '1', '3', exclude_common_ancestry=False)
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1644
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1645
        # it should be mentioned even if merge_sort order will make it appear
1646
        # after 1.1.1
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1647
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1648
                             b, '1.1.1', '3', exclude_common_ancestry=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1649
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1650
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1651
        b = self.make_branch_with_alternate_ancestries()
1652
        self.assertLogRevnos(['3', '2'],
1653
                             b, '1', '3', exclude_common_ancestry=True,
1654
                             generate_merge_revisions=False)
5268.4.3 by Vincent Ladeuil
Respect --exclude-common-ancestry for linear ancestries.
1655
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
1656
                             b, '1', '3', exclude_common_ancestry=True,
1657
                             generate_merge_revisions=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1658
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1659
1660
class TestLogDefaults(TestCaseForLogFormatter):
1661
    def test_default_log_level(self):
6042.1.2 by Thomi Richards
Minor changes as a result of feedback from merge proposal.
1662
        """
1663
        Test to ensure that specifying 'levels=1' to make_log_request_dict
1664
        doesn't get overwritten when using a LogFormatter that supports more
1665
        detail.
1666
        Fixes bug #747958.
1667
        """
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1668
        wt = self._prepare_tree_with_merges()
1669
        b = wt.branch
1670
1671
        class CustomLogFormatter(log.LogFormatter):
1672
            def __init__(self, *args, **kwargs):
1673
                super(CustomLogFormatter, self).__init__(*args, **kwargs)
1674
                self.revisions = []
1675
            def get_levels(self):
1676
                # log formatter supports all levels:
1677
                return 0
1678
            def log_revision(self, revision):
1679
                self.revisions.append(revision)
1680
1681
        log_formatter = LogCatcher()
1682
        # First request we don't specify number of levels, we should get a
1683
        # sensible default (whatever the LogFormatter handles - which in this
1684
        # case is 0/everything):
1685
        request = log.make_log_request_dict(limit=10)
1686
        log.Logger(b, request).show(log_formatter)
1687
        # should have all three revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1688
        self.assertEqual(len(log_formatter.revisions), 3)
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1689
1690
        del log_formatter
1691
        log_formatter = LogCatcher()
1692
        # now explicitly request mainline revisions only:
1693
        request = log.make_log_request_dict(limit=10, levels=1)
1694
        log.Logger(b, request).show(log_formatter)
1695
        # should now only have 2 revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1696
        self.assertEqual(len(log_formatter.revisions), 2)
6283.1.13 by Jelmer Vernooij
ADd hpss call count tests for 'bzr log'.
1697