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