/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2005-2010 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
1123 by Martin Pool
* move bzr-specific code from testsweet into bzrlib.selftest
18
from cStringIO import StringIO
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
19
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
20
from bzrlib import (
21
    errors,
22
    log,
23
    registry,
24
    revision,
25
    revisionspec,
4955.4.14 by Vincent Ladeuil
Properly deprecate log.calculate_view_revisions.
26
    symbol_versioning,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
27
    tests,
28
    )
29
30
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
31
class TestLogMixin(object):
32
33
    def wt_commit(self, wt, message, **kwargs):
34
        """Use some mostly fixed values for commits to simplify tests.
35
36
        Tests can use this function to get some commit attributes. The time
37
        stamp is incremented at each commit.
38
        """
39
        if getattr(self, 'timestamp', None) is None:
40
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
41
        else:
42
            self.timestamp += 1 # 1 second between each commit
43
        kwargs.setdefault('timestamp', self.timestamp)
44
        kwargs.setdefault('timezone', 0) # UTC
45
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
46
47
        return wt.commit(message, **kwargs)
48
49
50
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
51
52
    def setUp(self):
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
53
        super(TestCaseForLogFormatter, self).setUp()
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
54
        # 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.
55
        self.properties_handler_registry = log.properties_handler_registry
4325.4.3 by Vincent Ladeuil
More cleanups.
56
        # Use a clean registry for log
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
57
        log.properties_handler_registry = registry.Registry()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
58
4325.4.3 by Vincent Ladeuil
More cleanups.
59
        def restore():
60
            log.properties_handler_registry = self.properties_handler_registry
61
        self.addCleanup(restore)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
62
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
63
    def assertFormatterResult(self, result, branch, formatter_class,
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
64
                              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,
65
        logfile = self.make_utf8_encoded_stringio()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
66
        if formatter_kwargs is None:
67
            formatter_kwargs = {}
68
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
69
        if show_log_kwargs is None:
70
            show_log_kwargs = {}
71
        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.
72
        self.assertEqualDiff(result, logfile.getvalue())
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
73
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
74
    def make_standard_commit(self, branch_nick, **kwargs):
75
        wt = self.make_branch_and_tree('.')
76
        wt.lock_write()
77
        self.addCleanup(wt.unlock)
78
        self.build_tree(['a'])
79
        wt.add(['a'])
80
        wt.branch.nick = branch_nick
81
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
82
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
83
        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.
84
        return wt
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
85
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
86
    def make_commits_with_trailing_newlines(self, wt):
87
        """Helper method for LogFormatter tests"""
88
        b = wt.branch
89
        b.nick = 'test'
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
90
        self.build_tree_contents([('a', 'hello moto\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
91
        self.wt_commit(wt, 'simple log message', rev_id='a1')
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
92
        self.build_tree_contents([('b', 'goodbye\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
93
        wt.add('b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
94
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
95
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
96
        self.build_tree_contents([('c', 'just another manic monday\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
97
        wt.add('c')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
98
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
99
        return b
100
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
101
    def _prepare_tree_with_merges(self, with_tags=False):
102
        wt = self.make_branch_and_memory_tree('.')
103
        wt.lock_write()
104
        self.addCleanup(wt.unlock)
105
        wt.add('')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
106
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
107
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
108
        wt.set_parent_ids(['rev-1', 'rev-2a'])
109
        wt.branch.set_last_revision_info(1, 'rev-1')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
110
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
111
        if with_tags:
112
            branch = wt.branch
113
            branch.tags.set_tag('v0.2', 'rev-2b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
114
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
115
            branch.tags.set_tag('v1.0rc1', 'rev-3')
116
            branch.tags.set_tag('v1.0', 'rev-3')
117
        return wt
118
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
119
class LogCatcher(log.LogFormatter):
4325.4.3 by Vincent Ladeuil
More cleanups.
120
    """Pull log messages into a list rather than displaying them.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
121
4325.4.3 by Vincent Ladeuil
More cleanups.
122
    To simplify testing we save logged revisions here rather than actually
4325.4.1 by Vincent Ladeuil
Some cleanups.
123
    formatting anything, so that we can precisely check the result without
4325.4.3 by Vincent Ladeuil
More cleanups.
124
    being dependent on the formatting.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
125
    """
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.
126
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
127
    supports_merge_revisions = True
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
128
    supports_delta = True
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
129
    supports_diff = True
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
130
    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.
131
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
132
    def __init__(self, *args, **kwargs):
133
        kwargs.update(dict(to_file=None))
134
        super(LogCatcher, self).__init__(*args, **kwargs)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
135
        self.revisions = []
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
136
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
    def log_revision(self, revision):
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
138
        self.revisions.append(revision)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
139
140
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
141
class TestShowLog(tests.TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
142
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
143
    def checkDelta(self, delta, **kw):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
144
        """Check the filenames touched by a delta are as expected.
145
146
        Caller only have to pass in the list of files for each part, all
147
        unspecified parts are considered empty (and checked as such).
148
        """
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
149
        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.
150
            # By default we expect an empty list
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
151
            expected = kw.get(n, [])
152
            # strip out only the path components
153
            got = [x[0] for x in getattr(delta, n)]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
154
            self.assertEqual(expected, got)
155
156
    def assertInvalidRevisonNumber(self, br, start, end):
157
        lf = LogCatcher()
158
        self.assertRaises(errors.InvalidRevisionNumber,
159
                          log.show_log, br, lf,
160
                          start_revision=start, end_revision=end)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
161
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
162
    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.
163
        wt = self.make_branch_and_tree('.')
164
        b = wt.branch
1092.3.4 by Robert Collins
update symlink branch to integration
165
166
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
167
        wt.commit('empty commit')
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
168
        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.
169
170
        # Since there is a single revision in the branch all the combinations
171
        # below should fail.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
172
        self.assertInvalidRevisonNumber(b, 2, 1)
173
        self.assertInvalidRevisonNumber(b, 1, 2)
174
        self.assertInvalidRevisonNumber(b, 0, 2)
175
        self.assertInvalidRevisonNumber(b, 1, 0)
176
        self.assertInvalidRevisonNumber(b, -1, 1)
177
        self.assertInvalidRevisonNumber(b, 1, -1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
178
179
    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.
180
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
181
182
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
183
        log.show_log(wt.branch, lf)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
184
        # no entries yet
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
185
        self.assertEqual([], lf.revisions)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
186
187
    def test_empty_commit(self):
188
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
189
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
190
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
191
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
192
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
193
        revs = lf.revisions
194
        self.assertEqual(1, len(revs))
195
        self.assertEqual('1', revs[0].revno)
196
        self.assertEqual('empty commit', revs[0].rev.message)
197
        self.checkDelta(revs[0].delta)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
198
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
199
    def test_simple_commit(self):
200
        wt = self.make_branch_and_tree('.')
201
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
202
        self.build_tree(['hello'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
203
        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.
204
        wt.commit('add one file',
205
                  committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
206
                            u'<test@example.com>')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
207
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
208
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
209
        self.assertEqual(2, len(lf.revisions))
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
210
        # first one is most recent
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
211
        log_entry = lf.revisions[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
212
        self.assertEqual('2', log_entry.revno)
213
        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.
214
        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.
215
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
216
    def test_commit_message_with_control_chars(self):
217
        wt = self.make_branch_and_tree('.')
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
218
        msg = u"All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
219
        msg = msg.replace(u'\r', u'\n')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
220
        wt.commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
221
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
222
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
223
        committed_msg = lf.revisions[0].rev.message
4627.1.1 by Robert Collins
Review feedback per IanC.
224
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
225
            self.assertNotEqual(msg, committed_msg)
226
            self.assertTrue(len(committed_msg) > len(msg))
227
        else:
228
            self.assertEqual(msg, committed_msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
229
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
230
    def test_commit_message_without_control_chars(self):
231
        wt = self.make_branch_and_tree('.')
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
232
        # escaped.  As ElementTree apparently does some kind of
233
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
234
        # included in the test commit message, even though they are
235
        # valid XML 1.0 characters.
236
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
237
        wt.commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
238
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
239
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
240
        committed_msg = lf.revisions[0].rev.message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
241
        self.assertEqual(msg, committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
242
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
243
    def test_deltas_in_merge_revisions(self):
244
        """Check deltas created for both mainline and merge revisions"""
245
        wt = self.make_branch_and_tree('parent')
246
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
247
        wt.add('file1')
248
        wt.add('file2')
249
        wt.commit(message='add file1 and file2')
2581.1.6 by Martin Pool
fix up more run_bzr callers
250
        self.run_bzr('branch parent child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
251
        os.unlink('child/file1')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
252
        file('child/file2', 'wb').write('hello\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
253
        self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
254
            'child'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
255
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
256
        self.run_bzr('merge ../child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
257
        wt.commit('merge child branch')
258
        os.chdir('..')
259
        b = wt.branch
260
        lf = LogCatcher()
261
        lf.supports_merge_revisions = True
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
262
        log.show_log(b, lf, verbose=True)
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
263
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
264
        revs = lf.revisions
265
        self.assertEqual(3, len(revs))
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
266
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
267
        logentry = revs[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
268
        self.assertEqual('2', logentry.revno)
269
        self.assertEqual('merge child branch', logentry.rev.message)
270
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
271
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
272
        logentry = revs[1]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
273
        self.assertEqual('1.1.1', logentry.revno)
274
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
275
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
276
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
277
        logentry = revs[2]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
278
        self.assertEqual('1', logentry.revno)
279
        self.assertEqual('add file1 and file2', logentry.rev.message)
280
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
281
282
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
283
class TestShortLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
284
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
285
    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.
286
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
287
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
288
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
289
    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.
290
      single line with trailing newline
291
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
292
    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.
293
      multiline
294
      log
295
      message
296
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
297
    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.
298
      simple log message
299
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
300
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
301
            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.
302
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
303
    def test_short_log_with_merges(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
304
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
305
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
306
    2 Joe Foo\t2005-11-22 [merge]
307
      rev-2
308
309
    1 Joe Foo\t2005-11-22
310
      rev-1
311
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
312
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
313
            wt.branch, log.ShortLogFormatter)
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
314
315
    def test_short_log_with_merges_and_advice(self):
316
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
317
        self.assertFormatterResult("""\
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
318
    2 Joe Foo\t2005-11-22 [merge]
319
      rev-2
320
321
    1 Joe Foo\t2005-11-22
322
      rev-1
323
4221.2.1 by Ian Clatworthy
--include-merges as an alias for --levels 0 in log
324
Use --include-merges or -n0 to see merged revisions.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
325
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
326
            wt.branch, log.ShortLogFormatter,
327
            formatter_kwargs=dict(show_advice=True))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
328
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
329
    def test_short_log_with_merges_and_range(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
330
        wt = self._prepare_tree_with_merges()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
331
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
332
        wt.branch.set_last_revision_info(2, 'rev-2b')
333
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
334
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
335
        self.assertFormatterResult("""\
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
336
    3 Joe Foo\t2005-11-22 [merge]
337
      rev-3b
338
339
    2 Joe Foo\t2005-11-22 [merge]
4955.4.19 by Vincent Ladeuil
Less code duplication.
340
      rev-2
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
341
342
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
343
            wt.branch, log.ShortLogFormatter,
344
            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.
345
3946.3.2 by Ian Clatworthy
add tests & NEWS item
346
    def test_short_log_with_tags(self):
347
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
348
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
349
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
3946.3.2 by Ian Clatworthy
add tests & NEWS item
350
      rev-3
351
352
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
353
      rev-2
354
355
    1 Joe Foo\t2005-11-22
356
      rev-1
357
358
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
359
            wt.branch, log.ShortLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
360
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
361
    def test_short_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
362
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
363
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
364
        rev = revspec.in_history(wt.branch)
365
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
366
      1.1.1 Joe Foo\t2005-11-22
367
            rev-merged
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
368
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
369
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
370
            wt.branch, log.ShortLogFormatter,
371
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
372
373
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
375
376
    def test_short_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
377
        wt = self._prepare_tree_with_merges()
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
378
        # Note that the 1.1.1 indenting is in fact correct given that
379
        # the revision numbers are right justified within 5 characters
380
        # for mainline revnos and 9 characters for dotted revnos.
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
381
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
382
    2 Joe Foo\t2005-11-22 [merge]
383
      rev-2
384
3947.1.10 by Ian Clatworthy
review feedback from vila
385
          1.1.1 Joe Foo\t2005-11-22
386
                rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
387
388
    1 Joe Foo\t2005-11-22
389
      rev-1
390
391
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
392
            wt.branch, log.ShortLogFormatter,
393
            formatter_kwargs=dict(levels=0))
3947.1.2 by Ian Clatworthy
formatter tests
394
395
    def test_short_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
396
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
397
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
398
        rev = revspec.in_history(wt.branch)
399
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
400
      1.1.1 Joe Foo\t2005-11-22
401
            rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
402
403
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
404
            wt.branch, log.ShortLogFormatter,
405
            formatter_kwargs=dict(levels=0),
406
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
407
408
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
409
class TestLongLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
410
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
411
    def test_verbose_log(self):
412
        """Verbose log includes changed files
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
413
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
414
        bug #4676
415
        """
4857.4.4 by John Arbash Meinel
One more standard-commit
416
        wt = self.make_standard_commit('test_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
417
        self.assertFormatterResult('''\
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
418
------------------------------------------------------------
419
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
420
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)
421
branch nick: test_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
422
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)
423
message:
424
  add a
425
added:
426
  a
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
427
''',
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
428
            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,
429
            show_log_kwargs=dict(verbose=True))
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
430
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
431
    def test_merges_are_indented_by_level(self):
432
        wt = self.make_branch_and_tree('parent')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
433
        self.wt_commit(wt, 'first post')
434
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
435
        self.wt_commit(child_wt, 'branch 1')
436
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
437
        self.wt_commit(smallerchild_wt, 'branch 2')
438
        child_wt.merge_from_branch(smallerchild_wt.branch)
439
        self.wt_commit(child_wt, 'merge branch 2')
440
        wt.merge_from_branch(child_wt.branch)
441
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
442
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
443
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
444
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
445
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
446
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
447
timestamp: Tue 2005-11-22 00:00:04 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
448
message:
449
  merge branch 1
450
    ------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
451
    revno: 1.1.2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
452
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
453
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
454
    timestamp: Tue 2005-11-22 00:00:03 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
455
    message:
456
      merge branch 2
457
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
458
        revno: 1.2.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
459
        committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
460
        branch nick: smallerchild
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
461
        timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
462
        message:
463
          branch 2
464
    ------------------------------------------------------------
465
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
466
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
467
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
468
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
469
    message:
470
      branch 1
471
------------------------------------------------------------
472
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
473
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
474
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
475
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
476
message:
477
  first post
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
478
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
479
            wt.branch, log.LongLogFormatter,
480
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
481
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
482
483
    def test_verbose_merge_revisions_contain_deltas(self):
484
        wt = self.make_branch_and_tree('parent')
485
        self.build_tree(['parent/f1', 'parent/f2'])
486
        wt.add(['f1','f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
487
        self.wt_commit(wt, 'first post')
488
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
489
        os.unlink('child/f1')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
490
        self.build_tree_contents([('child/f2', 'hello\n')])
491
        self.wt_commit(child_wt, 'removed f1 and modified f2')
492
        wt.merge_from_branch(child_wt.branch)
493
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
494
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
495
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
496
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
497
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
498
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
499
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
500
message:
501
  merge branch 1
502
removed:
503
  f1
504
modified:
505
  f2
506
    ------------------------------------------------------------
507
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
508
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
509
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
510
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
511
    message:
512
      removed f1 and modified f2
513
    removed:
514
      f1
515
    modified:
516
      f2
517
------------------------------------------------------------
518
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
519
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
520
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
521
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
522
message:
523
  first post
524
added:
525
  f1
526
  f2
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
527
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
528
            wt.branch, log.LongLogFormatter,
529
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
530
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
531
532
    def test_trailing_newlines(self):
533
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
534
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
535
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
536
------------------------------------------------------------
537
revno: 3
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
538
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
539
branch nick: test
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:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
541
message:
542
  single line with trailing newline
543
------------------------------------------------------------
544
revno: 2
545
committer: Joe Foo <joe@foo.com>
546
branch nick: test
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:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
548
message:
549
  multiline
550
  log
551
  message
552
------------------------------------------------------------
553
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
554
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
555
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
556
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
557
message:
558
  simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
559
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
560
        b, log.LongLogFormatter)
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
561
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
562
    def test_author_in_log(self):
563
        """Log includes the author name if it's set in
564
        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.
565
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
566
        wt = self.make_standard_commit('test_author_log',
567
            authors=['John Doe <jdoe@example.com>',
568
                     'Jane Rey <jrey@example.com>'])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
569
        self.assertFormatterResult("""\
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
570
------------------------------------------------------------
571
revno: 1
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
572
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.
573
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.
574
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
575
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.
576
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
577
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
578
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
579
        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.
580
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
581
    def test_properties_in_log(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
582
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
583
        handlers.
584
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
585
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
586
        def trivial_custom_prop_handler(revision):
587
            return {'test_prop':'test_value'}
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
588
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
589
        # Cleaned up in setUp()
590
        log.properties_handler_registry.register(
591
            'trivial_custom_prop_handler',
592
            trivial_custom_prop_handler)
593
        self.assertFormatterResult("""\
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
594
------------------------------------------------------------
595
revno: 1
596
test_prop: test_value
597
author: John Doe <jdoe@example.com>
598
committer: Lorem Ipsum <test@example.com>
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
599
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
600
timestamp: Tue 2005-11-22 00:00:00 +0000
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
601
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
602
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
603
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
604
            wt.branch, log.LongLogFormatter)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
605
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
606
    def test_properties_in_short_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
607
        """Log includes the custom properties returned by the registered
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
608
        handlers.
609
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
610
        wt = self.make_standard_commit('test_properties_in_short_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
611
        def trivial_custom_prop_handler(revision):
612
            return {'test_prop':'test_value'}
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
613
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
614
        log.properties_handler_registry.register(
615
            'trivial_custom_prop_handler',
616
            trivial_custom_prop_handler)
617
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
618
    1 John Doe\t2005-11-22
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
619
      test_prop: test_value
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
620
      add a
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
621
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
622
""",
623
            wt.branch, log.ShortLogFormatter)
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
624
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
625
    def test_error_in_properties_handler(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
626
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
627
        handlers.
628
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
629
        wt = self.make_standard_commit('error_in_properties_handler',
630
            revprops={'first_prop':'first_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
631
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
632
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
633
        def trivial_custom_prop_handler(revision):
634
            raise StandardError("a test error")
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
635
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
636
        log.properties_handler_registry.register(
637
            'trivial_custom_prop_handler',
638
            trivial_custom_prop_handler)
639
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
640
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
641
    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.
642
        wt = self.make_standard_commit('bad_argument',
643
              revprops={'a_prop':'test_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
644
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
645
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
646
        def bad_argument_prop_handler(revision):
647
            return {'custom_prop_name':revision.properties['a_prop']}
648
649
        log.properties_handler_registry.register(
650
            'bad_argument_prop_handler',
651
            bad_argument_prop_handler)
652
653
        self.assertRaises(AttributeError, formatter.show_properties,
654
                          'a revision', '')
655
656
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
657
        formatter.show_properties(revision, '')
658
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
659
                             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.
660
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
661
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
662
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
663
664
    def test_long_verbose_log(self):
665
        """Verbose log includes changed files
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
666
3947.1.2 by Ian Clatworthy
formatter tests
667
        bug #4676
668
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
669
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
670
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
671
------------------------------------------------------------
672
revno: 1
673
committer: Lorem Ipsum <test@example.com>
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
674
branch nick: test_long_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
675
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
676
message:
677
  add a
678
added:
679
  a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
680
""",
681
            wt.branch, log.LongLogFormatter,
682
            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,
683
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
684
685
    def test_long_verbose_contain_deltas(self):
686
        wt = self.make_branch_and_tree('parent')
687
        self.build_tree(['parent/f1', 'parent/f2'])
688
        wt.add(['f1','f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
689
        self.wt_commit(wt, 'first post')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
690
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
3947.1.2 by Ian Clatworthy
formatter tests
691
        os.unlink('child/f1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
692
        self.build_tree_contents([('child/f2', 'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
693
        self.wt_commit(child_wt, 'removed f1 and modified f2')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
694
        wt.merge_from_branch(child_wt.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
695
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
696
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
697
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
698
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
699
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
700
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
701
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
702
message:
703
  merge branch 1
704
removed:
705
  f1
706
modified:
707
  f2
708
------------------------------------------------------------
709
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
710
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
711
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
712
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
713
message:
714
  first post
715
added:
716
  f1
717
  f2
718
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
719
            wt.branch, log.LongLogFormatter,
720
            formatter_kwargs=dict(levels=1),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
721
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
722
723
    def test_long_trailing_newlines(self):
724
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
725
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
726
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
727
------------------------------------------------------------
728
revno: 3
729
committer: Joe Foo <joe@foo.com>
730
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
731
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
732
message:
733
  single line with trailing newline
734
------------------------------------------------------------
735
revno: 2
736
committer: Joe Foo <joe@foo.com>
737
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
738
timestamp: Tue 2005-11-22 00:00:01 +0000
3947.1.2 by Ian Clatworthy
formatter tests
739
message:
740
  multiline
741
  log
742
  message
743
------------------------------------------------------------
744
revno: 1
745
committer: Joe Foo <joe@foo.com>
746
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
747
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
748
message:
749
  simple log message
750
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
751
        b, log.LongLogFormatter,
752
        formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
753
754
    def test_long_author_in_log(self):
755
        """Log includes the author name if it's set in
756
        the revision properties
757
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
758
        wt = self.make_standard_commit('test_author_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
759
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
760
------------------------------------------------------------
761
revno: 1
762
author: John Doe <jdoe@example.com>
763
committer: Lorem Ipsum <test@example.com>
764
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
765
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
766
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
767
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
768
""",
769
            wt.branch, log.LongLogFormatter,
770
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
771
772
    def test_long_properties_in_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
773
        """Log includes the custom properties returned by the registered
3947.1.2 by Ian Clatworthy
formatter tests
774
        handlers.
775
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
776
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
777
        def trivial_custom_prop_handler(revision):
778
            return {'test_prop':'test_value'}
3947.1.2 by Ian Clatworthy
formatter tests
779
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
780
        log.properties_handler_registry.register(
781
            'trivial_custom_prop_handler',
782
            trivial_custom_prop_handler)
783
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
784
------------------------------------------------------------
785
revno: 1
786
test_prop: test_value
787
author: John Doe <jdoe@example.com>
788
committer: Lorem Ipsum <test@example.com>
789
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
790
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
791
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
792
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
793
""",
794
            wt.branch, log.LongLogFormatter,
795
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
796
797
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
798
class TestLineLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
799
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
800
    def test_line_log(self):
801
        """Line log should show revno
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
802
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
803
        bug #5162
804
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
805
        wt = self.make_standard_commit('test-line-log',
806
                committer='Line-Log-Formatter Tester <test@line.log>',
807
                authors=[])
808
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
809
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
810
""",
811
            wt.branch, log.LineLogFormatter)
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
812
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
813
    def test_trailing_newlines(self):
814
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
815
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
816
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
817
3: Joe Foo 2005-11-22 single line with trailing newline
818
2: Joe Foo 2005-11-22 multiline
819
1: Joe Foo 2005-11-22 simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
820
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
821
            b, log.LineLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
822
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
823
    def test_line_log_single_merge_revision(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
824
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
825
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
826
        rev = revspec.in_history(wt.branch)
827
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
828
1.1.1: Joe Foo 2005-11-22 rev-merged
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
829
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
830
            wt.branch, log.LineLogFormatter,
831
            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.
832
3946.3.2 by Ian Clatworthy
add tests & NEWS item
833
    def test_line_log_with_tags(self):
834
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
835
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
836
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
837
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
3946.3.2 by Ian Clatworthy
add tests & NEWS item
838
1: Joe Foo 2005-11-22 rev-1
839
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
840
            wt.branch, log.LineLogFormatter)
841
842
843
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
844
845
    def test_line_merge_revs_log(self):
846
        """Line log should show revno
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
847
3947.1.2 by Ian Clatworthy
formatter tests
848
        bug #5162
849
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
850
        wt = self.make_standard_commit('test-line-log',
851
                committer='Line-Log-Formatter Tester <test@line.log>',
852
                authors=[])
853
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
854
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
855
""",
856
            wt.branch, log.LineLogFormatter)
3947.1.2 by Ian Clatworthy
formatter tests
857
858
    def test_line_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
859
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
860
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
861
        rev = revspec.in_history(wt.branch)
862
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
863
1.1.1: Joe Foo 2005-11-22 rev-merged
864
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
865
            wt.branch, log.LineLogFormatter,
866
            formatter_kwargs=dict(levels=0),
867
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
868
869
    def test_line_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
870
        wt = self._prepare_tree_with_merges()
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
871
        self.assertFormatterResult("""\
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
872
2: Joe Foo 2005-11-22 [merge] rev-2
3947.1.2 by Ian Clatworthy
formatter tests
873
  1.1.1: Joe Foo 2005-11-22 rev-merged
874
1: Joe Foo 2005-11-22 rev-1
875
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
876
            wt.branch, log.LineLogFormatter,
877
            formatter_kwargs=dict(levels=0))
878
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
879
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
880
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
881
882
    def test_gnu_changelog(self):
883
        wt = self.make_standard_commit('nicky', authors=[])
884
        self.assertFormatterResult('''\
885
2005-11-22  Lorem Ipsum  <test@example.com>
886
887
\tadd a
888
889
''',
890
            wt.branch, log.GnuChangelogLogFormatter)
891
892
    def test_with_authors(self):
893
        wt = self.make_standard_commit('nicky',
894
            authors=['Fooa Fooz <foo@example.com>',
895
                     'Bari Baro <bar@example.com>'])
896
        self.assertFormatterResult('''\
897
2005-11-22  Fooa Fooz  <foo@example.com>
898
899
\tadd a
900
901
''',
902
            wt.branch, log.GnuChangelogLogFormatter)
903
904
    def test_verbose(self):
905
        wt = self.make_standard_commit('nicky')
906
        self.assertFormatterResult('''\
907
2005-11-22  John Doe  <jdoe@example.com>
908
909
\t* a:
910
911
\tadd a
912
913
''',
914
            wt.branch, log.GnuChangelogLogFormatter,
915
            show_log_kwargs=dict(verbose=True))
916
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
917
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
918
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
919
    def _get_view_revisions(self, *args, **kwargs):
920
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
921
                                    log.get_view_revisions, *args, **kwargs)
922
1756.2.22 by Aaron Bentley
Apply review comments
923
    def make_tree_with_commits(self):
924
        """Create a tree with well-known revision ids"""
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
925
        wt = self.make_branch_and_tree('tree1')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
926
        self.wt_commit(wt, 'commit one', rev_id='1')
927
        self.wt_commit(wt, 'commit two', rev_id='2')
928
        self.wt_commit(wt, 'commit three', rev_id='3')
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
929
        mainline_revs = [None, '1', '2', '3']
1756.2.22 by Aaron Bentley
Apply review comments
930
        rev_nos = {'1': 1, '2': 2, '3': 3}
931
        return mainline_revs, rev_nos, wt
932
933
    def make_tree_with_merges(self):
934
        """Create a tree with well-known revision ids and a merge"""
935
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
936
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
937
        self.wt_commit(tree2, 'four-a', rev_id='4a')
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
938
        wt.merge_from_branch(tree2.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
939
        self.wt_commit(wt, 'four-b', rev_id='4b')
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
940
        mainline_revs.append('4b')
1756.2.22 by Aaron Bentley
Apply review comments
941
        rev_nos['4b'] = 4
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
942
        # 4a: 3.1.1
1756.2.22 by Aaron Bentley
Apply review comments
943
        return mainline_revs, rev_nos, wt
944
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
945
    def make_branch_with_many_merges(self):
1756.2.24 by Aaron Bentley
Forward sorting shows merges under mainline revision
946
        """Create a tree with well-known revision ids"""
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
947
        builder = self.make_branch_builder('tree1')
948
        builder.start_series()
949
        builder.build_snapshot('1', None, [
950
            ('add', ('', 'TREE_ROOT', 'directory', '')),
951
            ('add', ('f', 'f-id', 'file', '1\n'))])
952
        builder.build_snapshot('2', ['1'], [])
953
        builder.build_snapshot('3a', ['2'], [
954
            ('modify', ('f-id', '1\n2\n3a\n'))])
955
        builder.build_snapshot('3b', ['2', '3a'], [
956
            ('modify', ('f-id', '1\n2\n3a\n'))])
957
        builder.build_snapshot('3c', ['2', '3b'], [
958
            ('modify', ('f-id', '1\n2\n3a\n'))])
959
        builder.build_snapshot('4a', ['3b'], [])
960
        builder.build_snapshot('4b', ['3c', '4a'], [])
961
        builder.finish_series()
962
963
        # 1
964
        # |
965
        # 2-.
966
        # |\ \
967
        # | | 3a
968
        # | |/
969
        # | 3b
970
        # |/|
971
        # 3c4a
972
        # |/
973
        # 4b
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
974
1756.2.24 by Aaron Bentley
Forward sorting shows merges under mainline revision
975
        mainline_revs = [None, '1', '2', '3c', '4b']
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
976
        rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
977
        full_rev_nos_for_reference = {
978
            '1': '1',
979
            '2': '2',
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
980
            '3a': '2.1.1', #first commit tree 3
981
            '3b': '2.2.1', # first commit tree 2
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
982
            '3c': '3', #merges 3b to main
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
983
            '4a': '2.2.2', # second commit tree 2
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
984
            '4b': '4', # merges 4a to main
985
            }
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
986
        return mainline_revs, rev_nos, builder.get_branch()
1756.2.24 by Aaron Bentley
Forward sorting shows merges under mainline revision
987
1756.2.22 by Aaron Bentley
Apply review comments
988
    def test_get_view_revisions_forward(self):
989
        """Test the get_view_revisions method"""
990
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
991
        wt.lock_read()
992
        self.addCleanup(wt.unlock)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
993
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
994
                mainline_revs, rev_nos, wt.branch, 'forward'))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
995
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
996
                         revisions)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
997
        revisions2 = list(self._get_view_revisions(
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
998
                mainline_revs, rev_nos, wt.branch, 'forward',
999
                include_merges=False))
1756.2.22 by Aaron Bentley
Apply review comments
1000
        self.assertEqual(revisions, revisions2)
1001
1002
    def test_get_view_revisions_reverse(self):
1003
        """Test the get_view_revisions with reverse"""
1004
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
1005
        wt.lock_read()
1006
        self.addCleanup(wt.unlock)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1007
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1008
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1009
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1010
                         revisions)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1011
        revisions2 = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1012
                mainline_revs, rev_nos, wt.branch, 'reverse',
1013
                include_merges=False))
1756.2.22 by Aaron Bentley
Apply review comments
1014
        self.assertEqual(revisions, revisions2)
1015
1016
    def test_get_view_revisions_merge(self):
1017
        """Test get_view_revisions when there are merges"""
1018
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
1019
        wt.lock_read()
1020
        self.addCleanup(wt.unlock)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1021
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1022
                mainline_revs, rev_nos, wt.branch, 'forward'))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1023
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1024
                          ('4b', '4', 0), ('4a', '3.1.1', 1)],
1025
                         revisions)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1026
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1027
                mainline_revs, rev_nos, wt.branch, 'forward',
1028
                include_merges=False))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1029
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1030
                          ('4b', '4', 0)],
1031
                         revisions)
1756.2.24 by Aaron Bentley
Forward sorting shows merges under mainline revision
1032
1033
    def test_get_view_revisions_merge_reverse(self):
1034
        """Test get_view_revisions in reverse when there are merges"""
1035
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
1036
        wt.lock_read()
1037
        self.addCleanup(wt.unlock)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1038
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1039
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1040
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1041
                          ('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1042
                         revisions)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1043
        revisions = list(self._get_view_revisions(
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1044
                mainline_revs, rev_nos, wt.branch, 'reverse',
1045
                include_merges=False))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1046
        self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1047
                          ('1', '1', 0)],
1048
                         revisions)
1756.2.24 by Aaron Bentley
Forward sorting shows merges under mainline revision
1049
1050
    def test_get_view_revisions_merge2(self):
1051
        """Test get_view_revisions when there are merges"""
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1052
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1053
        b.lock_read()
1054
        self.addCleanup(b.unlock)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1055
        revisions = list(self._get_view_revisions(
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1056
                mainline_revs, rev_nos, b, 'forward'))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1057
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
4615.1.3 by John Arbash Meinel
Since the merge depth changed, it causes log to change slightly as well.
1058
                    ('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1059
                    ('4a', '2.2.2', 1)]
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1060
        self.assertEqual(expected, revisions)
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1061
        revisions = list(self._get_view_revisions(
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1062
                mainline_revs, rev_nos, b, 'forward',
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1063
                include_merges=False))
1988.4.2 by Robert Collins
``bzr log`` Now shows dotted-decimal revision numbers for all revisions,
1064
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1065
                          ('4b', '4', 0)],
1066
                         revisions)
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1067
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1068
    def test_file_id_for_range(self):
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1069
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1070
        b.lock_read()
1071
        self.addCleanup(b.unlock)
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1072
1073
        def rev_from_rev_id(revid, branch):
1074
            revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1075
            return revspec.in_history(branch)
1076
1077
        def view_revs(start_rev, end_rev, file_id, direction):
4955.4.14 by Vincent Ladeuil
Properly deprecate log.calculate_view_revisions.
1078
            revs = self.applyDeprecated(
1079
                symbol_versioning.deprecated_in((2, 2, 0)),
1080
                log.calculate_view_revisions,
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1081
                b,
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1082
                start_rev, # start_revision
1083
                end_rev, # end_revision
1084
                direction, # direction
1085
                file_id, # specific_fileid
1086
                True, # generate_merge_revisions
1087
                )
1088
            return revs
1089
4615.1.2 by John Arbash Meinel
clarify the test a bit by using BranchBuilder.
1090
        rev_3a = rev_from_rev_id('3a', b)
1091
        rev_4b = rev_from_rev_id('4b', b)
4955.5.3 by Vincent Ladeuil
Cleanup.
1092
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1093
                          ('3a', '2.1.1', 2)],
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1094
                          view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
3936.3.30 by Ian Clatworthy
use iter_merge_sorted_revisions() with stop_range feature
1095
        # Note: 3c still appears before 3a here because of depth-based sorting
4955.5.3 by Vincent Ladeuil
Cleanup.
1096
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1097
                          ('3a', '2.1.1', 2)],
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1098
                          view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1099
1100
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1101
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1102
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1103
    def get_view_revisions(self, *args):
1104
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1105
                                    log.get_view_revisions, *args)
1106
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1107
    def create_tree_with_single_merge(self):
1108
        """Create a branch with a moderate layout.
1109
1110
        The revision graph looks like:
1111
1112
           A
1113
           |\
1114
           B C
1115
           |/
1116
           D
1117
1118
        In this graph, A introduced files f1 and f2 and f3.
1119
        B modifies f1 and f3, and C modifies f2 and f3.
1120
        D merges the changes from B and C and resolves the conflict for f3.
1121
        """
1122
        # TODO: jam 20070218 This seems like it could really be done
1123
        #       with make_branch_and_memory_tree() if we could just
1124
        #       create the content of those files.
1125
        # TODO: jam 20070218 Another alternative is that we would really
1126
        #       like to only create this tree 1 time for all tests that
1127
        #       use it. Since 'log' only uses the tree in a readonly
1128
        #       fashion, it seems a shame to regenerate an identical
1129
        #       tree for each test.
4955.4.21 by Vincent Ladeuil
Mention an idea about memory tree re-use.
1130
        # TODO: vila 20100122 One way to address the shame above will be to
1131
        #       create a memory tree during test parametrization and give a
1132
        #       *copy* of this tree to each test. Copying a memory tree ought
1133
        #       to be cheap, at least cheaper than creating them with such
1134
        #       complex setups.
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1135
        tree = self.make_branch_and_tree('tree')
1136
        tree.lock_write()
1137
        self.addCleanup(tree.unlock)
1138
1139
        self.build_tree_contents([('tree/f1', 'A\n'),
1140
                                  ('tree/f2', 'A\n'),
1141
                                  ('tree/f3', 'A\n'),
1142
                                 ])
1143
        tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1144
        tree.commit('A', rev_id='A')
1145
1146
        self.build_tree_contents([('tree/f2', 'A\nC\n'),
1147
                                  ('tree/f3', 'A\nC\n'),
1148
                                 ])
1149
        tree.commit('C', rev_id='C')
1150
        # Revert back to A to build the other history.
1151
        tree.set_last_revision('A')
1152
        tree.branch.set_last_revision_info(1, 'A')
1153
        self.build_tree_contents([('tree/f1', 'A\nB\n'),
1154
                                  ('tree/f2', 'A\n'),
1155
                                  ('tree/f3', 'A\nB\n'),
1156
                                 ])
1157
        tree.commit('B', rev_id='B')
1158
        tree.set_parent_ids(['B', 'C'])
1159
        self.build_tree_contents([('tree/f1', 'A\nB\n'),
1160
                                  ('tree/f2', 'A\nC\n'),
1161
                                  ('tree/f3', 'A\nB\nC\n'),
1162
                                 ])
1163
        tree.commit('D', rev_id='D')
1164
1165
        # Switch to a read lock for this tree.
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
1166
        # We still have an addCleanup(tree.unlock) pending
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1167
        tree.unlock()
1168
        tree.lock_read()
1169
        return tree
1170
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1171
    def check_delta(self, delta, **kw):
1172
        """Check the filenames touched by a delta are as expected.
1173
1174
        Caller only have to pass in the list of files for each part, all
1175
        unspecified parts are considered empty (and checked as such).
1176
        """
1177
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1178
            # By default we expect an empty list
1179
            expected = kw.get(n, [])
1180
            # strip out only the path components
1181
            got = [x[0] for x in getattr(delta, n)]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
1182
            self.assertEqual(expected, got)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1183
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1184
    def test_tree_with_single_merge(self):
1185
        """Make sure the tree layout is correct."""
1186
        tree = self.create_tree_with_single_merge()
1187
        rev_A_tree = tree.branch.repository.revision_tree('A')
1188
        rev_B_tree = tree.branch.repository.revision_tree('B')
1189
        rev_C_tree = tree.branch.repository.revision_tree('C')
1190
        rev_D_tree = tree.branch.repository.revision_tree('D')
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1191
1192
        self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1193
                         modified=['f1', 'f3'])
1194
1195
        self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1196
                         modified=['f2', 'f3'])
1197
1198
        self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1199
                         modified=['f2', 'f3'])
1200
1201
        self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1202
                         modified=['f1', 'f3'])
2359.1.6 by John Arbash Meinel
Create a helper tree which has a semi-interesting history.
1203
2359.1.7 by John Arbash Meinel
Create a direct test for _get_revisions_touching_file_id
1204
    def assertAllRevisionsForFileID(self, tree, file_id, revisions):
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1205
        """Ensure _filter_revisions_touching_file_id returns the right values.
2359.1.7 by John Arbash Meinel
Create a direct test for _get_revisions_touching_file_id
1206
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
1207
        Get the return value from _filter_revisions_touching_file_id and make
2359.1.7 by John Arbash Meinel
Create a direct test for _get_revisions_touching_file_id
1208
        sure they are correct.
1209
        """
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1210
        # The api for _filter_revisions_touching_file_id is a little crazy.
2359.1.7 by John Arbash Meinel
Create a direct test for _get_revisions_touching_file_id
1211
        # So we do the setup here.
1212
        mainline = tree.branch.revision_history()
1213
        mainline.insert(0, None)
1214
        revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1215
        view_revs_iter = self.get_view_revisions(
1216
            mainline, revnos, tree.branch, 'reverse', True)
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
1217
        actual_revs = log._filter_revisions_touching_file_id(
4955.4.20 by Vincent Ladeuil
Properly deprecate dead code.
1218
            tree.branch, file_id, list(view_revs_iter))
2359.1.7 by John Arbash Meinel
Create a direct test for _get_revisions_touching_file_id
1219
        self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1220
1221
    def test_file_id_f1(self):
1222
        tree = self.create_tree_with_single_merge()
1223
        # f1 should be marked as modified by revisions A and B
1224
        self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1225
1226
    def test_file_id_f2(self):
1227
        tree = self.create_tree_with_single_merge()
1228
        # f2 should be marked as modified by revisions A, C, and D
1229
        # because D merged the changes from C.
1230
        self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1231
1232
    def test_file_id_f3(self):
1233
        tree = self.create_tree_with_single_merge()
1234
        # f3 should be marked as modified by revisions A, B, C, and D
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1235
        self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1236
3373.2.1 by John Arbash Meinel
Fix bug #209948, properly skip over ghosts when displaying the changes for a single file.
1237
    def test_file_id_with_ghosts(self):
1238
        # This is testing bug #209948, where having a ghost would cause
1239
        # _filter_revisions_touching_file_id() to fail.
1240
        tree = self.create_tree_with_single_merge()
1241
        # We need to add a revision, so switch back to a write-locked tree
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1242
        # (still a single addCleanup(tree.unlock) pending).
3373.2.1 by John Arbash Meinel
Fix bug #209948, properly skip over ghosts when displaying the changes for a single file.
1243
        tree.unlock()
1244
        tree.lock_write()
1245
        first_parent = tree.last_revision()
1246
        tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1247
        self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1248
        tree.commit('commit with a ghost', rev_id='XX')
1249
        self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1250
        self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1251
4183.3.1 by Vincent Ladeuil
Fix bug #346431 by allowing log._filter_revisions_touching_file_id to be
1252
    def test_unknown_file_id(self):
1253
        tree = self.create_tree_with_single_merge()
1254
        self.assertAllRevisionsForFileID(tree, 'unknown', [])
1255
1256
    def test_empty_branch_unknown_file_id(self):
1257
        tree = self.make_branch_and_tree('tree')
1258
        self.assertAllRevisionsForFileID(tree, 'unknown', [])
1259
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1260
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1261
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1262
1263
    def test_show_changed_revisions_verbose(self):
1264
        tree = self.make_branch_and_tree('tree_a')
1265
        self.build_tree(['tree_a/foo'])
1266
        tree.add('foo')
1267
        tree.commit('bar', rev_id='bar-id')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
1268
        s = self.make_utf8_encoded_stringio()
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1269
        log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1270
        self.assertContainsRe(s.getvalue(), 'bar')
1271
        self.assertNotContainsRe(s.getvalue(), 'foo')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1272
1273
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1274
class TestLogFormatter(tests.TestCase):
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1275
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1276
    def setUp(self):
1277
        super(TestLogFormatter, self).setUp()
1278
        self.rev = revision.Revision('a-id')
1279
        self.lf = log.LogFormatter(None)
1280
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1281
    def test_short_committer(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1282
        def assertCommitter(expected, committer):
1283
            self.rev.committer = committer
1284
            self.assertEqual(expected, self.lf.short_committer(self.rev))
1285
1286
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1287
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1288
        assertCommitter('John Smith', 'John Smith')
1289
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
1290
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1291
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1292
1293
    def test_short_author(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1294
        def assertAuthor(expected, author):
1295
            self.rev.properties['author'] = author
1296
            self.assertEqual(expected, self.lf.short_author(self.rev))
1297
1298
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1299
        assertAuthor('John Smith', 'John Smith')
1300
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
1301
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1302
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
1303
1304
    def test_short_author_from_committer(self):
1305
        self.rev.committer = 'John Doe <jdoe@example.com>'
1306
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
1307
1308
    def test_short_author_from_authors(self):
1309
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1310
                                          'Jane Rey <jrey@example.com>')
1311
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1312
1313
1314
class TestReverseByDepth(tests.TestCase):
1315
    """Test reverse_by_depth behavior.
1316
1317
    This is used to present revisions in forward (oldest first) order in a nice
1318
    layout.
1319
1320
    The tests use lighter revision description to ease reading.
1321
    """
1322
1323
    def assertReversed(self, forward, backward):
1324
        # Transform the descriptions to suit the API: tests use (revno, depth),
1325
        # while the API expects (revid, revno, depth)
1326
        def complete_revisions(l):
1327
            """Transform the description to suit the API.
1328
1329
            Tests use (revno, depth) whil the API expects (revid, revno, depth).
1330
            Since the revid is arbitrary, we just duplicate revno
1331
            """
1332
            return [ (r, r, d) for r, d in l]
1333
        forward = complete_revisions(forward)
1334
        backward= complete_revisions(backward)
1335
        self.assertEqual(forward, log.reverse_by_depth(backward))
1336
1337
1338
    def test_mainline_revisions(self):
1339
        self.assertReversed([( '1', 0), ('2', 0)],
1340
                            [('2', 0), ('1', 0)])
1341
1342
    def test_merged_revisions(self):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1343
        self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1344
                            [('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1345
    def test_shifted_merged_revisions(self):
1346
        """Test irregular layout.
1347
1348
        Requesting revisions touching a file can produce "holes" in the depths.
1349
        """
1350
        self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1351
                            [('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.
1352
1353
    def test_merged_without_child_revisions(self):
1354
        """Test irregular layout.
1355
1356
        Revision ranges can produce "holes" in the depths.
1357
        """
1358
        # When a revision of higher depth doesn't follow one of lower depth, we
1359
        # assume a lower depth one is virtually there
1360
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1361
                            [('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1362
        # So we get the same order after reversing below even if the original
1363
        # revisions are not in the same order.
1364
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1365
                            [('3', 3), ('4', 4), ('2', 2), ('1', 2),])
3848.1.6 by Aaron Bentley
Implement get_history_change
1366
1367
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1368
class TestHistoryChange(tests.TestCaseWithTransport):
3848.1.6 by Aaron Bentley
Implement get_history_change
1369
1370
    def setup_a_tree(self):
1371
        tree = self.make_branch_and_tree('tree')
1372
        tree.lock_write()
1373
        self.addCleanup(tree.unlock)
1374
        tree.commit('1a', rev_id='1a')
1375
        tree.commit('2a', rev_id='2a')
1376
        tree.commit('3a', rev_id='3a')
1377
        return tree
1378
1379
    def setup_ab_tree(self):
1380
        tree = self.setup_a_tree()
1381
        tree.set_last_revision('1a')
1382
        tree.branch.set_last_revision_info(1, '1a')
1383
        tree.commit('2b', rev_id='2b')
1384
        tree.commit('3b', rev_id='3b')
1385
        return tree
1386
1387
    def setup_ac_tree(self):
1388
        tree = self.setup_a_tree()
1389
        tree.set_last_revision(revision.NULL_REVISION)
1390
        tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1391
        tree.commit('1c', rev_id='1c')
1392
        tree.commit('2c', rev_id='2c')
1393
        tree.commit('3c', rev_id='3c')
1394
        return tree
1395
1396
    def test_all_new(self):
1397
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1398
        old, new = log.get_history_change('1a', '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1399
        self.assertEqual([], old)
1400
        self.assertEqual(['2a', '3a'], new)
1401
1402
    def test_all_old(self):
1403
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1404
        old, new = log.get_history_change('3a', '1a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1405
        self.assertEqual([], new)
1406
        self.assertEqual(['2a', '3a'], old)
1407
1408
    def test_null_old(self):
1409
        tree = self.setup_ab_tree()
1410
        old, new = log.get_history_change(revision.NULL_REVISION,
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1411
                                          '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1412
        self.assertEqual([], old)
1413
        self.assertEqual(['1a', '2a', '3a'], new)
1414
1415
    def test_null_new(self):
1416
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1417
        old, new = log.get_history_change('3a', revision.NULL_REVISION,
1418
                                          tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1419
        self.assertEqual([], new)
1420
        self.assertEqual(['1a', '2a', '3a'], old)
1421
1422
    def test_diverged(self):
1423
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1424
        old, new = log.get_history_change('3a', '3b', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1425
        self.assertEqual(old, ['2a', '3a'])
1426
        self.assertEqual(new, ['2b', '3b'])
1427
1428
    def test_unrelated(self):
1429
        tree = self.setup_ac_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1430
        old, new = log.get_history_change('3a', '3c', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1431
        self.assertEqual(old, ['1a', '2a', '3a'])
1432
        self.assertEqual(new, ['1c', '2c', '3c'])
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1433
1434
    def test_show_branch_change(self):
1435
        tree = self.setup_ab_tree()
1436
        s = StringIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1437
        log.show_branch_change(tree.branch, s, 3, '3a')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1438
        self.assertContainsRe(s.getvalue(),
1439
            '[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1440
            '[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1441
1442
    def test_show_branch_change_no_change(self):
1443
        tree = self.setup_ab_tree()
1444
        s = StringIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1445
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1446
        self.assertEqual(s.getvalue(),
1447
            'Nothing seems to have changed\n')
1448
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1449
    def test_show_branch_change_no_old(self):
1450
        tree = self.setup_ab_tree()
1451
        s = StringIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1452
        log.show_branch_change(tree.branch, s, 2, '2b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1453
        self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1454
        self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1455
1456
    def test_show_branch_change_no_new(self):
1457
        tree = self.setup_ab_tree()
1458
        tree.branch.set_last_revision_info(2, '2b')
1459
        s = StringIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1460
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1461
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1462
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1463
1464
1465
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1466
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1467
1468
    def setUp(self):
1469
        TestCaseForLogFormatter.setUp(self)
1470
        log.properties_handler_registry.register(
1471
            'bugs_properties_handler',
1472
            log._bugs_properties_handler)
1473
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1474
    def make_commits_with_bugs(self):
1475
        """Helper method for LogFormatter tests"""
1476
        tree = self.make_branch_and_tree(u'.')
1477
        self.build_tree(['a', 'b'])
1478
        tree.add('a')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1479
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1480
                       revprops={'bugs': 'test://bug/id fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1481
        tree.add('b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1482
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1483
                       authors=['Joe Bar <joe@bar.com>'],
1484
                       revprops={'bugs': 'test://bug/id fixed\n'
1485
                                 'test://bug/2 fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1486
        return tree
1487
1488
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1489
    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
1490
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1491
        self.assertFormatterResult("""\
1492
------------------------------------------------------------
1493
revno: 2
1494
fixes bug(s): test://bug/id test://bug/2
1495
author: Joe Bar <joe@bar.com>
1496
committer: Joe Foo <joe@foo.com>
1497
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1498
timestamp: Tue 2005-11-22 00:00:01 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1499
message:
1500
  multiline
1501
  log
1502
  message
1503
------------------------------------------------------------
1504
revno: 1
1505
fixes bug(s): test://bug/id
1506
committer: Joe Foo <joe@foo.com>
1507
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1508
timestamp: Tue 2005-11-22 00:00:00 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1509
message:
1510
  simple log message
1511
""",
1512
            tree.branch, log.LongLogFormatter)
1513
1514
    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
1515
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1516
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1517
    2 Joe Bar\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1518
      fixes bug(s): test://bug/id test://bug/2
1519
      multiline
1520
      log
1521
      message
1522
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1523
    1 Joe Foo\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1524
      fixes bug(s): test://bug/id
1525
      simple log message
1526
1527
""",
1528
            tree.branch, log.ShortLogFormatter)
1529
1530
    def test_wrong_bugs_property(self):
1531
        tree = self.make_branch_and_tree(u'.')
1532
        self.build_tree(['foo'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1533
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1534
                       revprops={'bugs': 'test://bug/id invalid_value'})
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1535
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1536
    1 Joe Foo\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1537
      simple log message
1538
1539
""",
1540
            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
1541
1542
    def test_bugs_handler_present(self):
1543
        self.properties_handler_registry.get('bugs_properties_handler')