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