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