~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
18
from cStringIO import StringIO
23
23
    registry,
24
24
    revision,
25
25
    revisionspec,
 
26
    symbol_versioning,
26
27
    tests,
27
28
    )
28
29
 
29
30
 
30
 
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
 
31
class TestLogMixin(object):
 
32
 
 
33
    def wt_commit(self, wt, message, **kwargs):
 
34
        """Use some mostly fixed values for commits to simplify tests.
 
35
 
 
36
        Tests can use this function to get some commit attributes. The time
 
37
        stamp is incremented at each commit.
 
38
        """
 
39
        if getattr(self, 'timestamp', None) is None:
 
40
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
 
41
        else:
 
42
            self.timestamp += 1 # 1 second between each commit
 
43
        kwargs.setdefault('timestamp', self.timestamp)
 
44
        kwargs.setdefault('timezone', 0) # UTC
 
45
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
 
46
 
 
47
        return wt.commit(message, **kwargs)
 
48
 
 
49
 
 
50
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
31
51
 
32
52
    def setUp(self):
33
 
        super(TestCaseWithoutPropsHandler, self).setUp()
 
53
        super(TestCaseForLogFormatter, self).setUp()
34
54
        # keep a reference to the "current" custom prop. handler registry
35
55
        self.properties_handler_registry = log.properties_handler_registry
36
 
        # clean up the registry in log
 
56
        # Use a clean registry for log
37
57
        log.properties_handler_registry = registry.Registry()
38
58
 
39
 
    def _cleanup(self):
40
 
        super(TestCaseWithoutPropsHandler, self)._cleanup()
41
 
        # restore the custom properties handler registry
42
 
        log.properties_handler_registry = self.properties_handler_registry
43
 
 
 
59
        def restore():
 
60
            log.properties_handler_registry = self.properties_handler_registry
 
61
        self.addCleanup(restore)
 
62
 
 
63
    def assertFormatterResult(self, result, branch, formatter_class,
 
64
                              formatter_kwargs=None, show_log_kwargs=None):
 
65
        logfile = self.make_utf8_encoded_stringio()
 
66
        if formatter_kwargs is None:
 
67
            formatter_kwargs = {}
 
68
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
 
69
        if show_log_kwargs is None:
 
70
            show_log_kwargs = {}
 
71
        log.show_log(branch, formatter, **show_log_kwargs)
 
72
        self.assertEqualDiff(result, logfile.getvalue())
 
73
 
 
74
    def make_standard_commit(self, branch_nick, **kwargs):
 
75
        wt = self.make_branch_and_tree('.')
 
76
        wt.lock_write()
 
77
        self.addCleanup(wt.unlock)
 
78
        self.build_tree(['a'])
 
79
        wt.add(['a'])
 
80
        wt.branch.nick = branch_nick
 
81
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
 
82
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
 
83
        self.wt_commit(wt, 'add a', **kwargs)
 
84
        return wt
 
85
 
 
86
    def make_commits_with_trailing_newlines(self, wt):
 
87
        """Helper method for LogFormatter tests"""
 
88
        b = wt.branch
 
89
        b.nick = 'test'
 
90
        self.build_tree_contents([('a', 'hello moto\n')])
 
91
        self.wt_commit(wt, 'simple log message', rev_id='a1')
 
92
        self.build_tree_contents([('b', 'goodbye\n')])
 
93
        wt.add('b')
 
94
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
 
95
 
 
96
        self.build_tree_contents([('c', 'just another manic monday\n')])
 
97
        wt.add('c')
 
98
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
 
99
        return b
 
100
 
 
101
    def _prepare_tree_with_merges(self, with_tags=False):
 
102
        wt = self.make_branch_and_memory_tree('.')
 
103
        wt.lock_write()
 
104
        self.addCleanup(wt.unlock)
 
105
        wt.add('')
 
106
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
 
107
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
 
108
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
109
        wt.branch.set_last_revision_info(1, 'rev-1')
 
110
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
 
111
        if with_tags:
 
112
            branch = wt.branch
 
113
            branch.tags.set_tag('v0.2', 'rev-2b')
 
114
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
 
115
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
116
            branch.tags.set_tag('v1.0', 'rev-3')
 
117
        return wt
44
118
 
45
119
class LogCatcher(log.LogFormatter):
46
 
    """Pull log messages into list rather than displaying them.
47
 
 
48
 
    For ease of testing we save log messages here rather than actually
49
 
    formatting them, so that we can precisely check the result without
50
 
    being too dependent on the exact formatting.
51
 
 
52
 
    We should also test the LogFormatter.
 
120
    """Pull log messages into a list rather than displaying them.
 
121
 
 
122
    To simplify testing we save logged revisions here rather than actually
 
123
    formatting anything, so that we can precisely check the result without
 
124
    being dependent on the formatting.
53
125
    """
54
126
 
 
127
    supports_merge_revisions = True
55
128
    supports_delta = True
 
129
    supports_diff = True
 
130
    preferred_levels = 0
56
131
 
57
 
    def __init__(self):
58
 
        super(LogCatcher, self).__init__(to_file=None)
59
 
        self.logs = []
 
132
    def __init__(self, *args, **kwargs):
 
133
        kwargs.update(dict(to_file=None))
 
134
        super(LogCatcher, self).__init__(*args, **kwargs)
 
135
        self.revisions = []
60
136
 
61
137
    def log_revision(self, revision):
62
 
        self.logs.append(revision)
 
138
        self.revisions.append(revision)
63
139
 
64
140
 
65
141
class TestShowLog(tests.TestCaseWithTransport):
106
182
        lf = LogCatcher()
107
183
        log.show_log(wt.branch, lf)
108
184
        # no entries yet
109
 
        self.assertEqual([], lf.logs)
 
185
        self.assertEqual([], lf.revisions)
110
186
 
111
187
    def test_empty_commit(self):
112
188
        wt = self.make_branch_and_tree('.')
114
190
        wt.commit('empty commit')
115
191
        lf = LogCatcher()
116
192
        log.show_log(wt.branch, lf, verbose=True)
117
 
        self.assertEqual(1, len(lf.logs))
118
 
        self.assertEqual('1', lf.logs[0].revno)
119
 
        self.assertEqual('empty commit', lf.logs[0].rev.message)
120
 
        self.checkDelta(lf.logs[0].delta)
 
193
        revs = lf.revisions
 
194
        self.assertEqual(1, len(revs))
 
195
        self.assertEqual('1', revs[0].revno)
 
196
        self.assertEqual('empty commit', revs[0].rev.message)
 
197
        self.checkDelta(revs[0].delta)
121
198
 
122
199
    def test_simple_commit(self):
123
200
        wt = self.make_branch_and_tree('.')
129
206
                            u'<test@example.com>')
130
207
        lf = LogCatcher()
131
208
        log.show_log(wt.branch, lf, verbose=True)
132
 
        self.assertEqual(2, len(lf.logs))
 
209
        self.assertEqual(2, len(lf.revisions))
133
210
        # first one is most recent
134
 
        log_entry = lf.logs[0]
 
211
        log_entry = lf.revisions[0]
135
212
        self.assertEqual('2', log_entry.revno)
136
213
        self.assertEqual('add one file', log_entry.rev.message)
137
214
        self.checkDelta(log_entry.delta, added=['hello'])
143
220
        wt.commit(msg)
144
221
        lf = LogCatcher()
145
222
        log.show_log(wt.branch, lf, verbose=True)
146
 
        committed_msg = lf.logs[0].rev.message
147
 
        self.assertNotEqual(msg, committed_msg)
148
 
        self.assertTrue(len(committed_msg) > len(msg))
 
223
        committed_msg = lf.revisions[0].rev.message
 
224
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
 
225
            self.assertNotEqual(msg, committed_msg)
 
226
            self.assertTrue(len(committed_msg) > len(msg))
 
227
        else:
 
228
            self.assertEqual(msg, committed_msg)
149
229
 
150
230
    def test_commit_message_without_control_chars(self):
151
231
        wt = self.make_branch_and_tree('.')
157
237
        wt.commit(msg)
158
238
        lf = LogCatcher()
159
239
        log.show_log(wt.branch, lf, verbose=True)
160
 
        committed_msg = lf.logs[0].rev.message
 
240
        committed_msg = lf.revisions[0].rev.message
161
241
        self.assertEqual(msg, committed_msg)
162
242
 
163
243
    def test_deltas_in_merge_revisions(self):
181
261
        lf.supports_merge_revisions = True
182
262
        log.show_log(b, lf, verbose=True)
183
263
 
184
 
        self.assertEqual(3, len(lf.logs))
 
264
        revs = lf.revisions
 
265
        self.assertEqual(3, len(revs))
185
266
 
186
 
        logentry = lf.logs[0]
 
267
        logentry = revs[0]
187
268
        self.assertEqual('2', logentry.revno)
188
269
        self.assertEqual('merge child branch', logentry.rev.message)
189
270
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
190
271
 
191
 
        logentry = lf.logs[1]
 
272
        logentry = revs[1]
192
273
        self.assertEqual('1.1.1', logentry.revno)
193
274
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
194
275
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
195
276
 
196
 
        logentry = lf.logs[2]
 
277
        logentry = revs[2]
197
278
        self.assertEqual('1', logentry.revno)
198
279
        self.assertEqual('add file1 and file2', logentry.rev.message)
199
280
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
200
281
 
201
 
    def test_merges_nonsupporting_formatter(self):
202
 
        """Tests that show_log will raise if the formatter doesn't
203
 
        support merge revisions."""
204
 
        wt = self.make_branch_and_memory_tree('.')
205
 
        wt.lock_write()
206
 
        self.addCleanup(wt.unlock)
207
 
        wt.add('')
208
 
        wt.commit('rev-1', rev_id='rev-1',
209
 
                  timestamp=1132586655, timezone=36000,
210
 
                  committer='Joe Foo <joe@foo.com>')
211
 
        wt.commit('rev-merged', rev_id='rev-2a',
212
 
                  timestamp=1132586700, timezone=36000,
213
 
                  committer='Joe Foo <joe@foo.com>')
214
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
215
 
        wt.branch.set_last_revision_info(1, 'rev-1')
216
 
        wt.commit('rev-2', rev_id='rev-2b',
217
 
                  timestamp=1132586800, timezone=36000,
218
 
                  committer='Joe Foo <joe@foo.com>')
219
 
        logfile = self.make_utf8_encoded_stringio()
220
 
        formatter = log.ShortLogFormatter(to_file=logfile)
221
 
        wtb = wt.branch
222
 
        lf = LogCatcher()
223
 
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
224
 
        rev = revspec.in_history(wtb)
225
 
        self.assertRaises(errors.BzrCommandError, log.show_log, wtb, lf,
226
 
                          start_revision=rev, end_revision=rev)
227
 
 
228
 
 
229
 
def make_commits_with_trailing_newlines(wt):
230
 
    """Helper method for LogFormatter tests"""
231
 
    b = wt.branch
232
 
    b.nick='test'
233
 
    open('a', 'wb').write('hello moto\n')
234
 
    wt.add('a')
235
 
    wt.commit('simple log message', rev_id='a1',
236
 
              timestamp=1132586655.459960938, timezone=-6*3600,
237
 
              committer='Joe Foo <joe@foo.com>')
238
 
    open('b', 'wb').write('goodbye\n')
239
 
    wt.add('b')
240
 
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
241
 
              timestamp=1132586842.411175966, timezone=-6*3600,
242
 
              committer='Joe Foo <joe@foo.com>',
243
 
              author='Joe Bar <joe@bar.com>')
244
 
 
245
 
    open('c', 'wb').write('just another manic monday\n')
246
 
    wt.add('c')
247
 
    wt.commit('single line with trailing newline\n', rev_id='a3',
248
 
              timestamp=1132587176.835228920, timezone=-6*3600,
249
 
              committer = 'Joe Foo <joe@foo.com>')
250
 
    return b
251
 
 
252
 
 
253
 
def normalize_log(log):
254
 
    """Replaces the variable lines of logs with fixed lines"""
255
 
    author = 'author: Dolor Sit <test@example.com>'
256
 
    committer = 'committer: Lorem Ipsum <test@example.com>'
257
 
    lines = log.splitlines(True)
258
 
    for idx,line in enumerate(lines):
259
 
        stripped_line = line.lstrip()
260
 
        indent = ' ' * (len(line) - len(stripped_line))
261
 
        if stripped_line.startswith('author:'):
262
 
            lines[idx] = indent + author + '\n'
263
 
        elif stripped_line.startswith('committer:'):
264
 
            lines[idx] = indent + committer + '\n'
265
 
        elif stripped_line.startswith('timestamp:'):
266
 
            lines[idx] = indent + 'timestamp: Just now\n'
267
 
    return ''.join(lines)
268
 
 
269
 
 
270
 
class TestShortLogFormatter(tests.TestCaseWithTransport):
 
282
 
 
283
class TestShortLogFormatter(TestCaseForLogFormatter):
271
284
 
272
285
    def test_trailing_newlines(self):
273
286
        wt = self.make_branch_and_tree('.')
274
 
        b = make_commits_with_trailing_newlines(wt)
275
 
        sio = self.make_utf8_encoded_stringio()
276
 
        lf = log.ShortLogFormatter(to_file=sio)
277
 
        log.show_log(b, lf)
278
 
        self.assertEqualDiff("""\
279
 
    3 Joe Foo\t2005-11-21
 
287
        b = self.make_commits_with_trailing_newlines(wt)
 
288
        self.assertFormatterResult("""\
 
289
    3 Joe Foo\t2005-11-22
280
290
      single line with trailing newline
281
291
 
282
 
    2 Joe Bar\t2005-11-21
 
292
    2 Joe Foo\t2005-11-22
283
293
      multiline
284
294
      log
285
295
      message
286
296
 
287
 
    1 Joe Foo\t2005-11-21
 
297
    1 Joe Foo\t2005-11-22
288
298
      simple log message
289
299
 
290
300
""",
291
 
                             sio.getvalue())
292
 
 
293
 
    def _prepare_tree_with_merges(self, with_tags=False):
294
 
        wt = self.make_branch_and_memory_tree('.')
295
 
        wt.lock_write()
296
 
        self.addCleanup(wt.unlock)
297
 
        wt.add('')
298
 
        wt.commit('rev-1', rev_id='rev-1',
299
 
                  timestamp=1132586655, timezone=36000,
300
 
                  committer='Joe Foo <joe@foo.com>')
301
 
        wt.commit('rev-merged', rev_id='rev-2a',
302
 
                  timestamp=1132586700, timezone=36000,
303
 
                  committer='Joe Foo <joe@foo.com>')
304
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
305
 
        wt.branch.set_last_revision_info(1, 'rev-1')
306
 
        wt.commit('rev-2', rev_id='rev-2b',
307
 
                  timestamp=1132586800, timezone=36000,
308
 
                  committer='Joe Foo <joe@foo.com>')
309
 
        if with_tags:
310
 
            branch = wt.branch
311
 
            branch.tags.set_tag('v0.2', 'rev-2b')
312
 
            wt.commit('rev-3', rev_id='rev-3',
313
 
                      timestamp=1132586900, timezone=36000,
314
 
                      committer='Jane Foo <jane@foo.com>')
315
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
316
 
            branch.tags.set_tag('v1.0', 'rev-3')
317
 
        return wt
 
301
            b, log.ShortLogFormatter)
318
302
 
319
303
    def test_short_log_with_merges(self):
320
304
        wt = self._prepare_tree_with_merges()
321
 
        logfile = self.make_utf8_encoded_stringio()
322
 
        formatter = log.ShortLogFormatter(to_file=logfile)
323
 
        log.show_log(wt.branch, formatter)
324
 
        self.assertEqualDiff("""\
325
 
    2 Joe Foo\t2005-11-22 [merge]
326
 
      rev-2
327
 
 
328
 
    1 Joe Foo\t2005-11-22
329
 
      rev-1
330
 
 
331
 
""",
332
 
                             logfile.getvalue())
 
305
        self.assertFormatterResult("""\
 
306
    2 Joe Foo\t2005-11-22 [merge]
 
307
      rev-2
 
308
 
 
309
    1 Joe Foo\t2005-11-22
 
310
      rev-1
 
311
 
 
312
""",
 
313
            wt.branch, log.ShortLogFormatter)
 
314
 
 
315
    def test_short_log_with_merges_and_advice(self):
 
316
        wt = self._prepare_tree_with_merges()
 
317
        self.assertFormatterResult("""\
 
318
    2 Joe Foo\t2005-11-22 [merge]
 
319
      rev-2
 
320
 
 
321
    1 Joe Foo\t2005-11-22
 
322
      rev-1
 
323
 
 
324
Use --include-merges or -n0 to see merged revisions.
 
325
""",
 
326
            wt.branch, log.ShortLogFormatter,
 
327
            formatter_kwargs=dict(show_advice=True))
333
328
 
334
329
    def test_short_log_with_merges_and_range(self):
335
 
        wt = self.make_branch_and_memory_tree('.')
336
 
        wt.lock_write()
337
 
        self.addCleanup(wt.unlock)
338
 
        wt.add('')
339
 
        wt.commit('rev-1', rev_id='rev-1',
340
 
                  timestamp=1132586655, timezone=36000,
341
 
                  committer='Joe Foo <joe@foo.com>')
342
 
        wt.commit('rev-merged', rev_id='rev-2a',
343
 
                  timestamp=1132586700, timezone=36000,
344
 
                  committer='Joe Foo <joe@foo.com>')
345
 
        wt.branch.set_last_revision_info(1, 'rev-1')
346
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
347
 
        wt.commit('rev-2b', rev_id='rev-2b',
348
 
                  timestamp=1132586800, timezone=36000,
349
 
                  committer='Joe Foo <joe@foo.com>')
350
 
        wt.commit('rev-3a', rev_id='rev-3a',
351
 
                  timestamp=1132586800, timezone=36000,
352
 
                  committer='Joe Foo <joe@foo.com>')
 
330
        wt = self._prepare_tree_with_merges()
 
331
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
353
332
        wt.branch.set_last_revision_info(2, 'rev-2b')
354
333
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
355
 
        wt.commit('rev-3b', rev_id='rev-3b',
356
 
                  timestamp=1132586800, timezone=36000,
357
 
                  committer='Joe Foo <joe@foo.com>')
358
 
        logfile = self.make_utf8_encoded_stringio()
359
 
        formatter = log.ShortLogFormatter(to_file=logfile)
360
 
        log.show_log(wt.branch, formatter,
361
 
            start_revision=2, end_revision=3)
362
 
        self.assertEqualDiff("""\
 
334
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
 
335
        self.assertFormatterResult("""\
363
336
    3 Joe Foo\t2005-11-22 [merge]
364
337
      rev-3b
365
338
 
366
339
    2 Joe Foo\t2005-11-22 [merge]
367
 
      rev-2b
 
340
      rev-2
368
341
 
369
342
""",
370
 
                             logfile.getvalue())
 
343
            wt.branch, log.ShortLogFormatter,
 
344
            show_log_kwargs=dict(start_revision=2, end_revision=3))
371
345
 
372
346
    def test_short_log_with_tags(self):
373
347
        wt = self._prepare_tree_with_merges(with_tags=True)
374
 
        logfile = self.make_utf8_encoded_stringio()
375
 
        formatter = log.ShortLogFormatter(to_file=logfile)
376
 
        log.show_log(wt.branch, formatter)
377
 
        self.assertEqualDiff("""\
378
 
    3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
 
348
        self.assertFormatterResult("""\
 
349
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
379
350
      rev-3
380
351
 
381
352
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
385
356
      rev-1
386
357
 
387
358
""",
388
 
                             logfile.getvalue())
 
359
            wt.branch, log.ShortLogFormatter)
389
360
 
390
361
    def test_short_log_single_merge_revision(self):
391
 
        wt = self.make_branch_and_memory_tree('.')
392
 
        wt.lock_write()
393
 
        self.addCleanup(wt.unlock)
394
 
        wt.add('')
395
 
        wt.commit('rev-1', rev_id='rev-1',
396
 
                  timestamp=1132586655, timezone=36000,
397
 
                  committer='Joe Foo <joe@foo.com>')
398
 
        wt.commit('rev-merged', rev_id='rev-2a',
399
 
                  timestamp=1132586700, timezone=36000,
400
 
                  committer='Joe Foo <joe@foo.com>')
401
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
402
 
        wt.branch.set_last_revision_info(1, 'rev-1')
403
 
        wt.commit('rev-2', rev_id='rev-2b',
404
 
                  timestamp=1132586800, timezone=36000,
405
 
                  committer='Joe Foo <joe@foo.com>')
406
 
        logfile = self.make_utf8_encoded_stringio()
407
 
        formatter = log.ShortLogFormatter(to_file=logfile)
 
362
        wt = self._prepare_tree_with_merges()
408
363
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
409
 
        wtb = wt.branch
410
 
        rev = revspec.in_history(wtb)
411
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
412
 
        self.assertEqualDiff("""\
 
364
        rev = revspec.in_history(wt.branch)
 
365
        self.assertFormatterResult("""\
413
366
      1.1.1 Joe Foo\t2005-11-22
414
367
            rev-merged
415
368
 
416
369
""",
417
 
                             logfile.getvalue())
418
 
 
419
 
 
420
 
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
370
            wt.branch, log.ShortLogFormatter,
 
371
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
372
 
 
373
 
 
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
421
375
 
422
376
    def test_short_merge_revs_log_with_merges(self):
423
 
        wt = self.make_branch_and_memory_tree('.')
424
 
        wt.lock_write()
425
 
        self.addCleanup(wt.unlock)
426
 
        wt.add('')
427
 
        wt.commit('rev-1', rev_id='rev-1',
428
 
                  timestamp=1132586655, timezone=36000,
429
 
                  committer='Joe Foo <joe@foo.com>')
430
 
        wt.commit('rev-merged', rev_id='rev-2a',
431
 
                  timestamp=1132586700, timezone=36000,
432
 
                  committer='Joe Foo <joe@foo.com>')
433
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
434
 
        wt.branch.set_last_revision_info(1, 'rev-1')
435
 
        wt.commit('rev-2', rev_id='rev-2b',
436
 
                  timestamp=1132586800, timezone=36000,
437
 
                  committer='Joe Foo <joe@foo.com>')
438
 
        logfile = self.make_utf8_encoded_stringio()
439
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
440
 
        log.show_log(wt.branch, formatter)
 
377
        wt = self._prepare_tree_with_merges()
441
378
        # Note that the 1.1.1 indenting is in fact correct given that
442
379
        # the revision numbers are right justified within 5 characters
443
380
        # for mainline revnos and 9 characters for dotted revnos.
444
 
        self.assertEqualDiff("""\
 
381
        self.assertFormatterResult("""\
445
382
    2 Joe Foo\t2005-11-22 [merge]
446
383
      rev-2
447
384
 
452
389
      rev-1
453
390
 
454
391
""",
455
 
                             logfile.getvalue())
 
392
            wt.branch, log.ShortLogFormatter,
 
393
            formatter_kwargs=dict(levels=0))
456
394
 
457
395
    def test_short_merge_revs_log_single_merge_revision(self):
458
 
        wt = self.make_branch_and_memory_tree('.')
459
 
        wt.lock_write()
460
 
        self.addCleanup(wt.unlock)
461
 
        wt.add('')
462
 
        wt.commit('rev-1', rev_id='rev-1',
463
 
                  timestamp=1132586655, timezone=36000,
464
 
                  committer='Joe Foo <joe@foo.com>')
465
 
        wt.commit('rev-merged', rev_id='rev-2a',
466
 
                  timestamp=1132586700, timezone=36000,
467
 
                  committer='Joe Foo <joe@foo.com>')
468
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
469
 
        wt.branch.set_last_revision_info(1, 'rev-1')
470
 
        wt.commit('rev-2', rev_id='rev-2b',
471
 
                  timestamp=1132586800, timezone=36000,
472
 
                  committer='Joe Foo <joe@foo.com>')
473
 
        logfile = self.make_utf8_encoded_stringio()
474
 
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
396
        wt = self._prepare_tree_with_merges()
475
397
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
476
 
        wtb = wt.branch
477
 
        rev = revspec.in_history(wtb)
478
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
479
 
        self.assertEqualDiff("""\
 
398
        rev = revspec.in_history(wt.branch)
 
399
        self.assertFormatterResult("""\
480
400
      1.1.1 Joe Foo\t2005-11-22
481
401
            rev-merged
482
402
 
483
403
""",
484
 
                             logfile.getvalue())
485
 
 
486
 
 
487
 
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
 
404
            wt.branch, log.ShortLogFormatter,
 
405
            formatter_kwargs=dict(levels=0),
 
406
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
407
 
 
408
 
 
409
class TestLongLogFormatter(TestCaseForLogFormatter):
488
410
 
489
411
    def test_verbose_log(self):
490
412
        """Verbose log includes changed files
491
 
        
 
413
 
492
414
        bug #4676
493
415
        """
494
 
        wt = self.make_branch_and_tree('.')
495
 
        b = wt.branch
496
 
        self.build_tree(['a'])
497
 
        wt.add('a')
498
 
        # XXX: why does a longer nick show up?
499
 
        b.nick = 'test_verbose_log'
500
 
        wt.commit(message='add a',
501
 
                  timestamp=1132711707,
502
 
                  timezone=36000,
503
 
                  committer='Lorem Ipsum <test@example.com>')
504
 
        logfile = file('out.tmp', 'w+')
505
 
        formatter = log.LongLogFormatter(to_file=logfile)
506
 
        log.show_log(b, formatter, verbose=True)
507
 
        logfile.flush()
508
 
        logfile.seek(0)
509
 
        log_contents = logfile.read()
510
 
        self.assertEqualDiff('''\
 
416
        wt = self.make_standard_commit('test_verbose_log', authors=[])
 
417
        self.assertFormatterResult('''\
511
418
------------------------------------------------------------
512
419
revno: 1
513
420
committer: Lorem Ipsum <test@example.com>
514
421
branch nick: test_verbose_log
515
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
422
timestamp: Tue 2005-11-22 00:00:00 +0000
516
423
message:
517
424
  add a
518
425
added:
519
426
  a
520
427
''',
521
 
                             log_contents)
 
428
            wt.branch, log.LongLogFormatter,
 
429
            show_log_kwargs=dict(verbose=True))
522
430
 
523
431
    def test_merges_are_indented_by_level(self):
524
432
        wt = self.make_branch_and_tree('parent')
525
 
        wt.commit('first post')
526
 
        self.run_bzr('branch parent child')
527
 
        self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
528
 
        self.run_bzr('branch child smallerchild')
529
 
        self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
530
 
            'smallerchild'])
531
 
        os.chdir('child')
532
 
        self.run_bzr('merge ../smallerchild')
533
 
        self.run_bzr(['commit', '-m', 'merge branch 2'])
534
 
        os.chdir('../parent')
535
 
        self.run_bzr('merge ../child')
536
 
        wt.commit('merge branch 1')
537
 
        b = wt.branch
538
 
        sio = self.make_utf8_encoded_stringio()
539
 
        lf = log.LongLogFormatter(to_file=sio)
540
 
        log.show_log(b, lf, verbose=True)
541
 
        the_log = normalize_log(sio.getvalue())
542
 
        self.assertEqualDiff("""\
 
433
        self.wt_commit(wt, 'first post')
 
434
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
435
        self.wt_commit(child_wt, 'branch 1')
 
436
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
 
437
        self.wt_commit(smallerchild_wt, 'branch 2')
 
438
        child_wt.merge_from_branch(smallerchild_wt.branch)
 
439
        self.wt_commit(child_wt, 'merge branch 2')
 
440
        wt.merge_from_branch(child_wt.branch)
 
441
        self.wt_commit(wt, 'merge branch 1')
 
442
        self.assertFormatterResult("""\
543
443
------------------------------------------------------------
544
 
revno: 2
545
 
committer: Lorem Ipsum <test@example.com>
 
444
revno: 2 [merge]
 
445
committer: Joe Foo <joe@foo.com>
546
446
branch nick: parent
547
 
timestamp: Just now
 
447
timestamp: Tue 2005-11-22 00:00:04 +0000
548
448
message:
549
449
  merge branch 1
550
450
    ------------------------------------------------------------
551
 
    revno: 1.1.2
552
 
    committer: Lorem Ipsum <test@example.com>
 
451
    revno: 1.1.2 [merge]
 
452
    committer: Joe Foo <joe@foo.com>
553
453
    branch nick: child
554
 
    timestamp: Just now
 
454
    timestamp: Tue 2005-11-22 00:00:03 +0000
555
455
    message:
556
456
      merge branch 2
557
457
        ------------------------------------------------------------
558
458
        revno: 1.2.1
559
 
        committer: Lorem Ipsum <test@example.com>
 
459
        committer: Joe Foo <joe@foo.com>
560
460
        branch nick: smallerchild
561
 
        timestamp: Just now
 
461
        timestamp: Tue 2005-11-22 00:00:02 +0000
562
462
        message:
563
463
          branch 2
564
464
    ------------------------------------------------------------
565
465
    revno: 1.1.1
566
 
    committer: Lorem Ipsum <test@example.com>
 
466
    committer: Joe Foo <joe@foo.com>
567
467
    branch nick: child
568
 
    timestamp: Just now
 
468
    timestamp: Tue 2005-11-22 00:00:01 +0000
569
469
    message:
570
470
      branch 1
571
471
------------------------------------------------------------
572
472
revno: 1
573
 
committer: Lorem Ipsum <test@example.com>
 
473
committer: Joe Foo <joe@foo.com>
574
474
branch nick: parent
575
 
timestamp: Just now
 
475
timestamp: Tue 2005-11-22 00:00:00 +0000
576
476
message:
577
477
  first post
578
478
""",
579
 
                             the_log)
 
479
            wt.branch, log.LongLogFormatter,
 
480
            formatter_kwargs=dict(levels=0),
 
481
            show_log_kwargs=dict(verbose=True))
580
482
 
581
483
    def test_verbose_merge_revisions_contain_deltas(self):
582
484
        wt = self.make_branch_and_tree('parent')
583
485
        self.build_tree(['parent/f1', 'parent/f2'])
584
486
        wt.add(['f1','f2'])
585
 
        wt.commit('first post')
586
 
        self.run_bzr('branch parent child')
 
487
        self.wt_commit(wt, 'first post')
 
488
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
587
489
        os.unlink('child/f1')
588
 
        file('child/f2', 'wb').write('hello\n')
589
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
590
 
            'child'])
591
 
        os.chdir('parent')
592
 
        self.run_bzr('merge ../child')
593
 
        wt.commit('merge branch 1')
594
 
        b = wt.branch
595
 
        sio = self.make_utf8_encoded_stringio()
596
 
        lf = log.LongLogFormatter(to_file=sio)
597
 
        log.show_log(b, lf, verbose=True)
598
 
        the_log = normalize_log(sio.getvalue())
599
 
        self.assertEqualDiff("""\
 
490
        self.build_tree_contents([('child/f2', 'hello\n')])
 
491
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
492
        wt.merge_from_branch(child_wt.branch)
 
493
        self.wt_commit(wt, 'merge branch 1')
 
494
        self.assertFormatterResult("""\
600
495
------------------------------------------------------------
601
 
revno: 2
602
 
committer: Lorem Ipsum <test@example.com>
 
496
revno: 2 [merge]
 
497
committer: Joe Foo <joe@foo.com>
603
498
branch nick: parent
604
 
timestamp: Just now
 
499
timestamp: Tue 2005-11-22 00:00:02 +0000
605
500
message:
606
501
  merge branch 1
607
502
removed:
610
505
  f2
611
506
    ------------------------------------------------------------
612
507
    revno: 1.1.1
613
 
    committer: Lorem Ipsum <test@example.com>
 
508
    committer: Joe Foo <joe@foo.com>
614
509
    branch nick: child
615
 
    timestamp: Just now
 
510
    timestamp: Tue 2005-11-22 00:00:01 +0000
616
511
    message:
617
512
      removed f1 and modified f2
618
513
    removed:
621
516
      f2
622
517
------------------------------------------------------------
623
518
revno: 1
624
 
committer: Lorem Ipsum <test@example.com>
 
519
committer: Joe Foo <joe@foo.com>
625
520
branch nick: parent
626
 
timestamp: Just now
 
521
timestamp: Tue 2005-11-22 00:00:00 +0000
627
522
message:
628
523
  first post
629
524
added:
630
525
  f1
631
526
  f2
632
527
""",
633
 
                             the_log)
 
528
            wt.branch, log.LongLogFormatter,
 
529
            formatter_kwargs=dict(levels=0),
 
530
            show_log_kwargs=dict(verbose=True))
634
531
 
635
532
    def test_trailing_newlines(self):
636
533
        wt = self.make_branch_and_tree('.')
637
 
        b = make_commits_with_trailing_newlines(wt)
638
 
        sio = self.make_utf8_encoded_stringio()
639
 
        lf = log.LongLogFormatter(to_file=sio)
640
 
        log.show_log(b, lf)
641
 
        self.assertEqualDiff("""\
 
534
        b = self.make_commits_with_trailing_newlines(wt)
 
535
        self.assertFormatterResult("""\
642
536
------------------------------------------------------------
643
537
revno: 3
644
538
committer: Joe Foo <joe@foo.com>
645
539
branch nick: test
646
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
540
timestamp: Tue 2005-11-22 00:00:02 +0000
647
541
message:
648
542
  single line with trailing newline
649
543
------------------------------------------------------------
650
544
revno: 2
651
 
author: Joe Bar <joe@bar.com>
652
545
committer: Joe Foo <joe@foo.com>
653
546
branch nick: test
654
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
547
timestamp: Tue 2005-11-22 00:00:01 +0000
655
548
message:
656
549
  multiline
657
550
  log
660
553
revno: 1
661
554
committer: Joe Foo <joe@foo.com>
662
555
branch nick: test
663
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
556
timestamp: Tue 2005-11-22 00:00:00 +0000
664
557
message:
665
558
  simple log message
666
559
""",
667
 
                             sio.getvalue())
 
560
        b, log.LongLogFormatter)
668
561
 
669
562
    def test_author_in_log(self):
670
563
        """Log includes the author name if it's set in
671
564
        the revision properties
672
565
        """
673
 
        wt = self.make_branch_and_tree('.')
674
 
        b = wt.branch
675
 
        self.build_tree(['a'])
676
 
        wt.add('a')
677
 
        b.nick = 'test_author_log'
678
 
        wt.commit(message='add a',
679
 
                  timestamp=1132711707,
680
 
                  timezone=36000,
681
 
                  committer='Lorem Ipsum <test@example.com>',
682
 
                  author='John Doe <jdoe@example.com>')
683
 
        sio = StringIO()
684
 
        formatter = log.LongLogFormatter(to_file=sio)
685
 
        log.show_log(b, formatter)
686
 
        self.assertEqualDiff('''\
 
566
        wt = self.make_standard_commit('test_author_log',
 
567
            authors=['John Doe <jdoe@example.com>',
 
568
                     'Jane Rey <jrey@example.com>'])
 
569
        self.assertFormatterResult("""\
687
570
------------------------------------------------------------
688
571
revno: 1
689
 
author: John Doe <jdoe@example.com>
 
572
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
690
573
committer: Lorem Ipsum <test@example.com>
691
574
branch nick: test_author_log
692
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
575
timestamp: Tue 2005-11-22 00:00:00 +0000
693
576
message:
694
577
  add a
695
 
''',
696
 
                             sio.getvalue())
 
578
""",
 
579
        wt.branch, log.LongLogFormatter)
697
580
 
698
581
    def test_properties_in_log(self):
699
 
        """Log includes the custom properties returned by the registered 
 
582
        """Log includes the custom properties returned by the registered
700
583
        handlers.
701
584
        """
702
 
        wt = self.make_branch_and_tree('.')
703
 
        b = wt.branch
704
 
        self.build_tree(['a'])
705
 
        wt.add('a')
706
 
        b.nick = 'test_properties_in_log'
707
 
        wt.commit(message='add a',
708
 
                  timestamp=1132711707,
709
 
                  timezone=36000,
710
 
                  committer='Lorem Ipsum <test@example.com>',
711
 
                  author='John Doe <jdoe@example.com>')
712
 
        sio = StringIO()
713
 
        formatter = log.LongLogFormatter(to_file=sio)
714
 
        try:
715
 
            def trivial_custom_prop_handler(revision):
716
 
                return {'test_prop':'test_value'}
 
585
        wt = self.make_standard_commit('test_properties_in_log')
 
586
        def trivial_custom_prop_handler(revision):
 
587
            return {'test_prop':'test_value'}
717
588
 
718
 
            log.properties_handler_registry.register(
719
 
                'trivial_custom_prop_handler',
720
 
                trivial_custom_prop_handler)
721
 
            log.show_log(b, formatter)
722
 
        finally:
723
 
            log.properties_handler_registry.remove(
724
 
                'trivial_custom_prop_handler')
725
 
            self.assertEqualDiff('''\
 
589
        # Cleaned up in setUp()
 
590
        log.properties_handler_registry.register(
 
591
            'trivial_custom_prop_handler',
 
592
            trivial_custom_prop_handler)
 
593
        self.assertFormatterResult("""\
726
594
------------------------------------------------------------
727
595
revno: 1
728
596
test_prop: test_value
729
597
author: John Doe <jdoe@example.com>
730
598
committer: Lorem Ipsum <test@example.com>
731
599
branch nick: test_properties_in_log
732
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
600
timestamp: Tue 2005-11-22 00:00:00 +0000
733
601
message:
734
602
  add a
735
 
''',
736
 
                                 sio.getvalue())
 
603
""",
 
604
            wt.branch, log.LongLogFormatter)
737
605
 
738
606
    def test_properties_in_short_log(self):
739
 
        """Log includes the custom properties returned by the registered 
 
607
        """Log includes the custom properties returned by the registered
740
608
        handlers.
741
609
        """
742
 
        wt = self.make_branch_and_tree('.')
743
 
        b = wt.branch
744
 
        self.build_tree(['a'])
745
 
        wt.add('a')
746
 
        b.nick = 'test_properties_in_short_log'
747
 
        wt.commit(message='add a',
748
 
                  timestamp=1132711707,
749
 
                  timezone=36000,
750
 
                  committer='Lorem Ipsum <test@example.com>',
751
 
                  author='John Doe <jdoe@example.com>')
752
 
        sio = StringIO()
753
 
        formatter = log.ShortLogFormatter(to_file=sio)
754
 
        try:
755
 
            def trivial_custom_prop_handler(revision):
756
 
                return {'test_prop':'test_value'}
 
610
        wt = self.make_standard_commit('test_properties_in_short_log')
 
611
        def trivial_custom_prop_handler(revision):
 
612
            return {'test_prop':'test_value'}
757
613
 
758
 
            log.properties_handler_registry.register(
759
 
                'trivial_custom_prop_handler',
760
 
                trivial_custom_prop_handler)
761
 
            log.show_log(b, formatter)
762
 
        finally:
763
 
            log.properties_handler_registry.remove(
764
 
                'trivial_custom_prop_handler')
765
 
            self.assertEqualDiff('''\
766
 
    1 John Doe\t2005-11-23
 
614
        log.properties_handler_registry.register(
 
615
            'trivial_custom_prop_handler',
 
616
            trivial_custom_prop_handler)
 
617
        self.assertFormatterResult("""\
 
618
    1 John Doe\t2005-11-22
767
619
      test_prop: test_value
768
620
      add a
769
621
 
770
 
''',
771
 
                                 sio.getvalue())
 
622
""",
 
623
            wt.branch, log.ShortLogFormatter)
772
624
 
773
625
    def test_error_in_properties_handler(self):
774
 
        """Log includes the custom properties returned by the registered 
 
626
        """Log includes the custom properties returned by the registered
775
627
        handlers.
776
628
        """
777
 
        wt = self.make_branch_and_tree('.')
778
 
        b = wt.branch
779
 
        self.build_tree(['a'])
780
 
        wt.add('a')
781
 
        b.nick = 'test_author_log'
782
 
        wt.commit(message='add a',
783
 
                  timestamp=1132711707,
784
 
                  timezone=36000,
785
 
                  committer='Lorem Ipsum <test@example.com>',
786
 
                  author='John Doe <jdoe@example.com>',
787
 
                  revprops={'first_prop':'first_value'})
788
 
        sio = StringIO()
 
629
        wt = self.make_standard_commit('error_in_properties_handler',
 
630
            revprops={'first_prop':'first_value'})
 
631
        sio = self.make_utf8_encoded_stringio()
789
632
        formatter = log.LongLogFormatter(to_file=sio)
790
 
        try:
791
 
            def trivial_custom_prop_handler(revision):
792
 
                raise StandardError("a test error")
 
633
        def trivial_custom_prop_handler(revision):
 
634
            raise StandardError("a test error")
793
635
 
794
 
            log.properties_handler_registry.register(
795
 
                'trivial_custom_prop_handler',
796
 
                trivial_custom_prop_handler)
797
 
            self.assertRaises(StandardError, log.show_log, b, formatter,)
798
 
        finally:
799
 
            log.properties_handler_registry.remove(
800
 
                'trivial_custom_prop_handler')
 
636
        log.properties_handler_registry.register(
 
637
            'trivial_custom_prop_handler',
 
638
            trivial_custom_prop_handler)
 
639
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
801
640
 
802
641
    def test_properties_handler_bad_argument(self):
803
 
        wt = self.make_branch_and_tree('.')
804
 
        b = wt.branch
805
 
        self.build_tree(['a'])
806
 
        wt.add('a')
807
 
        b.nick = 'test_author_log'
808
 
        wt.commit(message='add a',
809
 
                  timestamp=1132711707,
810
 
                  timezone=36000,
811
 
                  committer='Lorem Ipsum <test@example.com>',
812
 
                  author='John Doe <jdoe@example.com>',
813
 
                  revprops={'a_prop':'test_value'})
814
 
        sio = StringIO()
 
642
        wt = self.make_standard_commit('bad_argument',
 
643
              revprops={'a_prop':'test_value'})
 
644
        sio = self.make_utf8_encoded_stringio()
815
645
        formatter = log.LongLogFormatter(to_file=sio)
816
 
        try:
817
 
            def bad_argument_prop_handler(revision):
818
 
                return {'custom_prop_name':revision.properties['a_prop']}
819
 
 
820
 
            log.properties_handler_registry.register(
821
 
                'bad_argument_prop_handler',
822
 
                bad_argument_prop_handler)
823
 
 
824
 
            self.assertRaises(AttributeError, formatter.show_properties,
825
 
                              'a revision', '')
826
 
 
827
 
            revision = b.repository.get_revision(b.last_revision())
828
 
            formatter.show_properties(revision, '')
829
 
            self.assertEqualDiff('''custom_prop_name: test_value\n''',
830
 
                                 sio.getvalue())
831
 
        finally:
832
 
            log.properties_handler_registry.remove(
833
 
                'bad_argument_prop_handler')
834
 
 
835
 
 
836
 
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
 
646
        def bad_argument_prop_handler(revision):
 
647
            return {'custom_prop_name':revision.properties['a_prop']}
 
648
 
 
649
        log.properties_handler_registry.register(
 
650
            'bad_argument_prop_handler',
 
651
            bad_argument_prop_handler)
 
652
 
 
653
        self.assertRaises(AttributeError, formatter.show_properties,
 
654
                          'a revision', '')
 
655
 
 
656
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
 
657
        formatter.show_properties(revision, '')
 
658
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
 
659
                             sio.getvalue())
 
660
 
 
661
 
 
662
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
837
663
 
838
664
    def test_long_verbose_log(self):
839
665
        """Verbose log includes changed files
840
 
        
 
666
 
841
667
        bug #4676
842
668
        """
843
 
        wt = self.make_branch_and_tree('.')
844
 
        b = wt.branch
845
 
        self.build_tree(['a'])
846
 
        wt.add('a')
847
 
        # XXX: why does a longer nick show up?
848
 
        b.nick = 'test_verbose_log'
849
 
        wt.commit(message='add a',
850
 
                  timestamp=1132711707,
851
 
                  timezone=36000,
852
 
                  committer='Lorem Ipsum <test@example.com>')
853
 
        logfile = file('out.tmp', 'w+')
854
 
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
855
 
        log.show_log(b, formatter, verbose=True)
856
 
        logfile.flush()
857
 
        logfile.seek(0)
858
 
        log_contents = logfile.read()
859
 
        self.assertEqualDiff('''\
 
669
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
 
670
        self.assertFormatterResult("""\
860
671
------------------------------------------------------------
861
672
revno: 1
862
673
committer: Lorem Ipsum <test@example.com>
863
 
branch nick: test_verbose_log
864
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
674
branch nick: test_long_verbose_log
 
675
timestamp: Tue 2005-11-22 00:00:00 +0000
865
676
message:
866
677
  add a
867
678
added:
868
679
  a
869
 
''',
870
 
                             log_contents)
 
680
""",
 
681
            wt.branch, log.LongLogFormatter,
 
682
            formatter_kwargs=dict(levels=1),
 
683
            show_log_kwargs=dict(verbose=True))
871
684
 
872
685
    def test_long_verbose_contain_deltas(self):
873
686
        wt = self.make_branch_and_tree('parent')
874
687
        self.build_tree(['parent/f1', 'parent/f2'])
875
688
        wt.add(['f1','f2'])
876
 
        wt.commit('first post')
877
 
        self.run_bzr('branch parent child')
 
689
        self.wt_commit(wt, 'first post')
 
690
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
878
691
        os.unlink('child/f1')
879
 
        file('child/f2', 'wb').write('hello\n')
880
 
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
881
 
            'child'])
882
 
        os.chdir('parent')
883
 
        self.run_bzr('merge ../child')
884
 
        wt.commit('merge branch 1')
885
 
        b = wt.branch
886
 
        sio = self.make_utf8_encoded_stringio()
887
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
888
 
        log.show_log(b, lf, verbose=True)
889
 
        the_log = normalize_log(sio.getvalue())
890
 
        self.assertEqualDiff("""\
 
692
        self.build_tree_contents([('child/f2', 'hello\n')])
 
693
        self.wt_commit(child_wt, 'removed f1 and modified f2')
 
694
        wt.merge_from_branch(child_wt.branch)
 
695
        self.wt_commit(wt, 'merge branch 1')
 
696
        self.assertFormatterResult("""\
891
697
------------------------------------------------------------
892
 
revno: 2
893
 
committer: Lorem Ipsum <test@example.com>
 
698
revno: 2 [merge]
 
699
committer: Joe Foo <joe@foo.com>
894
700
branch nick: parent
895
 
timestamp: Just now
 
701
timestamp: Tue 2005-11-22 00:00:02 +0000
896
702
message:
897
703
  merge branch 1
898
704
removed:
901
707
  f2
902
708
------------------------------------------------------------
903
709
revno: 1
904
 
committer: Lorem Ipsum <test@example.com>
 
710
committer: Joe Foo <joe@foo.com>
905
711
branch nick: parent
906
 
timestamp: Just now
 
712
timestamp: Tue 2005-11-22 00:00:00 +0000
907
713
message:
908
714
  first post
909
715
added:
910
716
  f1
911
717
  f2
912
718
""",
913
 
                             the_log)
 
719
            wt.branch, log.LongLogFormatter,
 
720
            formatter_kwargs=dict(levels=1),
 
721
            show_log_kwargs=dict(verbose=True))
914
722
 
915
723
    def test_long_trailing_newlines(self):
916
724
        wt = self.make_branch_and_tree('.')
917
 
        b = make_commits_with_trailing_newlines(wt)
918
 
        sio = self.make_utf8_encoded_stringio()
919
 
        lf = log.LongLogFormatter(to_file=sio, levels=1)
920
 
        log.show_log(b, lf)
921
 
        self.assertEqualDiff("""\
 
725
        b = self.make_commits_with_trailing_newlines(wt)
 
726
        self.assertFormatterResult("""\
922
727
------------------------------------------------------------
923
728
revno: 3
924
729
committer: Joe Foo <joe@foo.com>
925
730
branch nick: test
926
 
timestamp: Mon 2005-11-21 09:32:56 -0600
 
731
timestamp: Tue 2005-11-22 00:00:02 +0000
927
732
message:
928
733
  single line with trailing newline
929
734
------------------------------------------------------------
930
735
revno: 2
931
 
author: Joe Bar <joe@bar.com>
932
736
committer: Joe Foo <joe@foo.com>
933
737
branch nick: test
934
 
timestamp: Mon 2005-11-21 09:27:22 -0600
 
738
timestamp: Tue 2005-11-22 00:00:01 +0000
935
739
message:
936
740
  multiline
937
741
  log
940
744
revno: 1
941
745
committer: Joe Foo <joe@foo.com>
942
746
branch nick: test
943
 
timestamp: Mon 2005-11-21 09:24:15 -0600
 
747
timestamp: Tue 2005-11-22 00:00:00 +0000
944
748
message:
945
749
  simple log message
946
750
""",
947
 
                             sio.getvalue())
 
751
        b, log.LongLogFormatter,
 
752
        formatter_kwargs=dict(levels=1))
948
753
 
949
754
    def test_long_author_in_log(self):
950
755
        """Log includes the author name if it's set in
951
756
        the revision properties
952
757
        """
953
 
        wt = self.make_branch_and_tree('.')
954
 
        b = wt.branch
955
 
        self.build_tree(['a'])
956
 
        wt.add('a')
957
 
        b.nick = 'test_author_log'
958
 
        wt.commit(message='add a',
959
 
                  timestamp=1132711707,
960
 
                  timezone=36000,
961
 
                  committer='Lorem Ipsum <test@example.com>',
962
 
                  author='John Doe <jdoe@example.com>')
963
 
        sio = StringIO()
964
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
965
 
        log.show_log(b, formatter)
966
 
        self.assertEqualDiff('''\
 
758
        wt = self.make_standard_commit('test_author_log')
 
759
        self.assertFormatterResult("""\
967
760
------------------------------------------------------------
968
761
revno: 1
969
762
author: John Doe <jdoe@example.com>
970
763
committer: Lorem Ipsum <test@example.com>
971
764
branch nick: test_author_log
972
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
765
timestamp: Tue 2005-11-22 00:00:00 +0000
973
766
message:
974
767
  add a
975
 
''',
976
 
                             sio.getvalue())
 
768
""",
 
769
            wt.branch, log.LongLogFormatter,
 
770
            formatter_kwargs=dict(levels=1))
977
771
 
978
772
    def test_long_properties_in_log(self):
979
 
        """Log includes the custom properties returned by the registered 
 
773
        """Log includes the custom properties returned by the registered
980
774
        handlers.
981
775
        """
982
 
        wt = self.make_branch_and_tree('.')
983
 
        b = wt.branch
984
 
        self.build_tree(['a'])
985
 
        wt.add('a')
986
 
        b.nick = 'test_properties_in_log'
987
 
        wt.commit(message='add a',
988
 
                  timestamp=1132711707,
989
 
                  timezone=36000,
990
 
                  committer='Lorem Ipsum <test@example.com>',
991
 
                  author='John Doe <jdoe@example.com>')
992
 
        sio = StringIO()
993
 
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
994
 
        try:
995
 
            def trivial_custom_prop_handler(revision):
996
 
                return {'test_prop':'test_value'}
 
776
        wt = self.make_standard_commit('test_properties_in_log')
 
777
        def trivial_custom_prop_handler(revision):
 
778
            return {'test_prop':'test_value'}
997
779
 
998
 
            log.properties_handler_registry.register(
999
 
                'trivial_custom_prop_handler',
1000
 
                trivial_custom_prop_handler)
1001
 
            log.show_log(b, formatter)
1002
 
        finally:
1003
 
            log.properties_handler_registry.remove(
1004
 
                'trivial_custom_prop_handler')
1005
 
            self.assertEqualDiff('''\
 
780
        log.properties_handler_registry.register(
 
781
            'trivial_custom_prop_handler',
 
782
            trivial_custom_prop_handler)
 
783
        self.assertFormatterResult("""\
1006
784
------------------------------------------------------------
1007
785
revno: 1
1008
786
test_prop: test_value
1009
787
author: John Doe <jdoe@example.com>
1010
788
committer: Lorem Ipsum <test@example.com>
1011
789
branch nick: test_properties_in_log
1012
 
timestamp: Wed 2005-11-23 12:08:27 +1000
 
790
timestamp: Tue 2005-11-22 00:00:00 +0000
1013
791
message:
1014
792
  add a
1015
 
''',
1016
 
                                 sio.getvalue())
1017
 
 
1018
 
 
1019
 
class TestLineLogFormatter(tests.TestCaseWithTransport):
 
793
""",
 
794
            wt.branch, log.LongLogFormatter,
 
795
            formatter_kwargs=dict(levels=1))
 
796
 
 
797
 
 
798
class TestLineLogFormatter(TestCaseForLogFormatter):
1020
799
 
1021
800
    def test_line_log(self):
1022
801
        """Line log should show revno
1023
 
        
 
802
 
1024
803
        bug #5162
1025
804
        """
1026
 
        wt = self.make_branch_and_tree('.')
1027
 
        b = wt.branch
1028
 
        self.build_tree(['a'])
1029
 
        wt.add('a')
1030
 
        b.nick = 'test-line-log'
1031
 
        wt.commit(message='add a',
1032
 
                  timestamp=1132711707,
1033
 
                  timezone=36000,
1034
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1035
 
        logfile = file('out.tmp', 'w+')
1036
 
        formatter = log.LineLogFormatter(to_file=logfile)
1037
 
        log.show_log(b, formatter)
1038
 
        logfile.flush()
1039
 
        logfile.seek(0)
1040
 
        log_contents = logfile.read()
1041
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1042
 
                             log_contents)
 
805
        wt = self.make_standard_commit('test-line-log',
 
806
                committer='Line-Log-Formatter Tester <test@line.log>',
 
807
                authors=[])
 
808
        self.assertFormatterResult("""\
 
809
1: Line-Log-Formatte... 2005-11-22 add a
 
810
""",
 
811
            wt.branch, log.LineLogFormatter)
1043
812
 
1044
813
    def test_trailing_newlines(self):
1045
814
        wt = self.make_branch_and_tree('.')
1046
 
        b = make_commits_with_trailing_newlines(wt)
1047
 
        sio = self.make_utf8_encoded_stringio()
1048
 
        lf = log.LineLogFormatter(to_file=sio)
1049
 
        log.show_log(b, lf)
1050
 
        self.assertEqualDiff("""\
1051
 
3: Joe Foo 2005-11-21 single line with trailing newline
1052
 
2: Joe Bar 2005-11-21 multiline
1053
 
1: Joe Foo 2005-11-21 simple log message
 
815
        b = self.make_commits_with_trailing_newlines(wt)
 
816
        self.assertFormatterResult("""\
 
817
3: Joe Foo 2005-11-22 single line with trailing newline
 
818
2: Joe Foo 2005-11-22 multiline
 
819
1: Joe Foo 2005-11-22 simple log message
1054
820
""",
1055
 
                             sio.getvalue())
1056
 
 
1057
 
    def _prepare_tree_with_merges(self, with_tags=False):
1058
 
        wt = self.make_branch_and_memory_tree('.')
1059
 
        wt.lock_write()
1060
 
        self.addCleanup(wt.unlock)
1061
 
        wt.add('')
1062
 
        wt.commit('rev-1', rev_id='rev-1',
1063
 
                  timestamp=1132586655, timezone=36000,
1064
 
                  committer='Joe Foo <joe@foo.com>')
1065
 
        wt.commit('rev-merged', rev_id='rev-2a',
1066
 
                  timestamp=1132586700, timezone=36000,
1067
 
                  committer='Joe Foo <joe@foo.com>')
1068
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1069
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1070
 
        wt.commit('rev-2', rev_id='rev-2b',
1071
 
                  timestamp=1132586800, timezone=36000,
1072
 
                  committer='Joe Foo <joe@foo.com>')
1073
 
        if with_tags:
1074
 
            branch = wt.branch
1075
 
            branch.tags.set_tag('v0.2', 'rev-2b')
1076
 
            wt.commit('rev-3', rev_id='rev-3',
1077
 
                      timestamp=1132586900, timezone=36000,
1078
 
                      committer='Jane Foo <jane@foo.com>')
1079
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
1080
 
            branch.tags.set_tag('v1.0', 'rev-3')
1081
 
        return wt
 
821
            b, log.LineLogFormatter)
1082
822
 
1083
823
    def test_line_log_single_merge_revision(self):
1084
824
        wt = self._prepare_tree_with_merges()
1085
 
        logfile = self.make_utf8_encoded_stringio()
1086
 
        formatter = log.LineLogFormatter(to_file=logfile)
1087
825
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1088
 
        wtb = wt.branch
1089
 
        rev = revspec.in_history(wtb)
1090
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1091
 
        self.assertEqualDiff("""\
 
826
        rev = revspec.in_history(wt.branch)
 
827
        self.assertFormatterResult("""\
1092
828
1.1.1: Joe Foo 2005-11-22 rev-merged
1093
829
""",
1094
 
                             logfile.getvalue())
 
830
            wt.branch, log.LineLogFormatter,
 
831
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1095
832
 
1096
833
    def test_line_log_with_tags(self):
1097
834
        wt = self._prepare_tree_with_merges(with_tags=True)
1098
 
        logfile = self.make_utf8_encoded_stringio()
1099
 
        formatter = log.LineLogFormatter(to_file=logfile)
1100
 
        log.show_log(wt.branch, formatter)
1101
 
        self.assertEqualDiff("""\
1102
 
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
1103
 
2: Joe Foo 2005-11-22 {v0.2} rev-2
 
835
        self.assertFormatterResult("""\
 
836
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
 
837
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
1104
838
1: Joe Foo 2005-11-22 rev-1
1105
839
""",
1106
 
                             logfile.getvalue())
1107
 
 
1108
 
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
 
840
            wt.branch, log.LineLogFormatter)
 
841
 
 
842
 
 
843
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
1109
844
 
1110
845
    def test_line_merge_revs_log(self):
1111
846
        """Line log should show revno
1112
 
        
 
847
 
1113
848
        bug #5162
1114
849
        """
1115
 
        wt = self.make_branch_and_tree('.')
1116
 
        b = wt.branch
1117
 
        self.build_tree(['a'])
1118
 
        wt.add('a')
1119
 
        b.nick = 'test-line-log'
1120
 
        wt.commit(message='add a',
1121
 
                  timestamp=1132711707,
1122
 
                  timezone=36000,
1123
 
                  committer='Line-Log-Formatter Tester <test@line.log>')
1124
 
        logfile = file('out.tmp', 'w+')
1125
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1126
 
        log.show_log(b, formatter)
1127
 
        logfile.flush()
1128
 
        logfile.seek(0)
1129
 
        log_contents = logfile.read()
1130
 
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
1131
 
                             log_contents)
 
850
        wt = self.make_standard_commit('test-line-log',
 
851
                committer='Line-Log-Formatter Tester <test@line.log>',
 
852
                authors=[])
 
853
        self.assertFormatterResult("""\
 
854
1: Line-Log-Formatte... 2005-11-22 add a
 
855
""",
 
856
            wt.branch, log.LineLogFormatter)
1132
857
 
1133
858
    def test_line_merge_revs_log_single_merge_revision(self):
1134
 
        wt = self.make_branch_and_memory_tree('.')
1135
 
        wt.lock_write()
1136
 
        self.addCleanup(wt.unlock)
1137
 
        wt.add('')
1138
 
        wt.commit('rev-1', rev_id='rev-1',
1139
 
                  timestamp=1132586655, timezone=36000,
1140
 
                  committer='Joe Foo <joe@foo.com>')
1141
 
        wt.commit('rev-merged', rev_id='rev-2a',
1142
 
                  timestamp=1132586700, timezone=36000,
1143
 
                  committer='Joe Foo <joe@foo.com>')
1144
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1145
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1146
 
        wt.commit('rev-2', rev_id='rev-2b',
1147
 
                  timestamp=1132586800, timezone=36000,
1148
 
                  committer='Joe Foo <joe@foo.com>')
1149
 
        logfile = self.make_utf8_encoded_stringio()
1150
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
859
        wt = self._prepare_tree_with_merges()
1151
860
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
1152
 
        wtb = wt.branch
1153
 
        rev = revspec.in_history(wtb)
1154
 
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
1155
 
        self.assertEqualDiff("""\
 
861
        rev = revspec.in_history(wt.branch)
 
862
        self.assertFormatterResult("""\
1156
863
1.1.1: Joe Foo 2005-11-22 rev-merged
1157
864
""",
1158
 
                             logfile.getvalue())
 
865
            wt.branch, log.LineLogFormatter,
 
866
            formatter_kwargs=dict(levels=0),
 
867
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
1159
868
 
1160
869
    def test_line_merge_revs_log_with_merges(self):
1161
 
        wt = self.make_branch_and_memory_tree('.')
1162
 
        wt.lock_write()
1163
 
        self.addCleanup(wt.unlock)
1164
 
        wt.add('')
1165
 
        wt.commit('rev-1', rev_id='rev-1',
1166
 
                  timestamp=1132586655, timezone=36000,
1167
 
                  committer='Joe Foo <joe@foo.com>')
1168
 
        wt.commit('rev-merged', rev_id='rev-2a',
1169
 
                  timestamp=1132586700, timezone=36000,
1170
 
                  committer='Joe Foo <joe@foo.com>')
1171
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
1172
 
        wt.branch.set_last_revision_info(1, 'rev-1')
1173
 
        wt.commit('rev-2', rev_id='rev-2b',
1174
 
                  timestamp=1132586800, timezone=36000,
1175
 
                  committer='Joe Foo <joe@foo.com>')
1176
 
        logfile = self.make_utf8_encoded_stringio()
1177
 
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
1178
 
        log.show_log(wt.branch, formatter)
1179
 
        self.assertEqualDiff("""\
1180
 
2: Joe Foo 2005-11-22 rev-2
 
870
        wt = self._prepare_tree_with_merges()
 
871
        self.assertFormatterResult("""\
 
872
2: Joe Foo 2005-11-22 [merge] rev-2
1181
873
  1.1.1: Joe Foo 2005-11-22 rev-merged
1182
874
1: Joe Foo 2005-11-22 rev-1
1183
875
""",
1184
 
                             logfile.getvalue())
1185
 
 
1186
 
class TestGetViewRevisions(tests.TestCaseWithTransport):
 
876
            wt.branch, log.LineLogFormatter,
 
877
            formatter_kwargs=dict(levels=0))
 
878
 
 
879
 
 
880
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
 
881
 
 
882
    def _get_view_revisions(self, *args, **kwargs):
 
883
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
884
                                    log.get_view_revisions, *args, **kwargs)
1187
885
 
1188
886
    def make_tree_with_commits(self):
1189
887
        """Create a tree with well-known revision ids"""
1190
888
        wt = self.make_branch_and_tree('tree1')
1191
 
        wt.commit('commit one', rev_id='1')
1192
 
        wt.commit('commit two', rev_id='2')
1193
 
        wt.commit('commit three', rev_id='3')
 
889
        self.wt_commit(wt, 'commit one', rev_id='1')
 
890
        self.wt_commit(wt, 'commit two', rev_id='2')
 
891
        self.wt_commit(wt, 'commit three', rev_id='3')
1194
892
        mainline_revs = [None, '1', '2', '3']
1195
893
        rev_nos = {'1': 1, '2': 2, '3': 3}
1196
894
        return mainline_revs, rev_nos, wt
1199
897
        """Create a tree with well-known revision ids and a merge"""
1200
898
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1201
899
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1202
 
        tree2.commit('four-a', rev_id='4a')
 
900
        self.wt_commit(tree2, 'four-a', rev_id='4a')
1203
901
        wt.merge_from_branch(tree2.branch)
1204
 
        wt.commit('four-b', rev_id='4b')
 
902
        self.wt_commit(wt, 'four-b', rev_id='4b')
1205
903
        mainline_revs.append('4b')
1206
904
        rev_nos['4b'] = 4
1207
905
        # 4a: 3.1.1
1208
906
        return mainline_revs, rev_nos, wt
1209
907
 
1210
 
    def make_tree_with_many_merges(self):
 
908
    def make_branch_with_many_merges(self):
1211
909
        """Create a tree with well-known revision ids"""
1212
 
        wt = self.make_branch_and_tree('tree1')
1213
 
        self.build_tree_contents([('tree1/f', '1\n')])
1214
 
        wt.add(['f'], ['f-id'])
1215
 
        wt.commit('commit one', rev_id='1')
1216
 
        wt.commit('commit two', rev_id='2')
1217
 
 
1218
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
1219
 
        self.build_tree_contents([('tree3/f', '1\n2\n3a\n')])
1220
 
        tree3.commit('commit three a', rev_id='3a')
1221
 
 
1222
 
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1223
 
        tree2.merge_from_branch(tree3.branch)
1224
 
        tree2.commit('commit three b', rev_id='3b')
1225
 
 
1226
 
        wt.merge_from_branch(tree2.branch)
1227
 
        wt.commit('commit three c', rev_id='3c')
1228
 
        tree2.commit('four-a', rev_id='4a')
1229
 
 
1230
 
        wt.merge_from_branch(tree2.branch)
1231
 
        wt.commit('four-b', rev_id='4b')
 
910
        builder = self.make_branch_builder('tree1')
 
911
        builder.start_series()
 
912
        builder.build_snapshot('1', None, [
 
913
            ('add', ('', 'TREE_ROOT', 'directory', '')),
 
914
            ('add', ('f', 'f-id', 'file', '1\n'))])
 
915
        builder.build_snapshot('2', ['1'], [])
 
916
        builder.build_snapshot('3a', ['2'], [
 
917
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
918
        builder.build_snapshot('3b', ['2', '3a'], [
 
919
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
920
        builder.build_snapshot('3c', ['2', '3b'], [
 
921
            ('modify', ('f-id', '1\n2\n3a\n'))])
 
922
        builder.build_snapshot('4a', ['3b'], [])
 
923
        builder.build_snapshot('4b', ['3c', '4a'], [])
 
924
        builder.finish_series()
 
925
 
 
926
        # 1
 
927
        # |
 
928
        # 2-.
 
929
        # |\ \
 
930
        # | | 3a
 
931
        # | |/
 
932
        # | 3b
 
933
        # |/|
 
934
        # 3c4a
 
935
        # |/
 
936
        # 4b
1232
937
 
1233
938
        mainline_revs = [None, '1', '2', '3c', '4b']
1234
939
        rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
1241
946
            '4a': '2.2.2', # second commit tree 2
1242
947
            '4b': '4', # merges 4a to main
1243
948
            }
1244
 
        return mainline_revs, rev_nos, wt
 
949
        return mainline_revs, rev_nos, builder.get_branch()
1245
950
 
1246
951
    def test_get_view_revisions_forward(self):
1247
952
        """Test the get_view_revisions method"""
1248
953
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1249
954
        wt.lock_read()
1250
955
        self.addCleanup(wt.unlock)
1251
 
        revisions = list(log.get_view_revisions(
 
956
        revisions = list(self._get_view_revisions(
1252
957
                mainline_revs, rev_nos, wt.branch, 'forward'))
1253
958
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1254
959
                         revisions)
1255
 
        revisions2 = list(log.get_view_revisions(
 
960
        revisions2 = list(self._get_view_revisions(
1256
961
                mainline_revs, rev_nos, wt.branch, 'forward',
1257
962
                include_merges=False))
1258
963
        self.assertEqual(revisions, revisions2)
1262
967
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1263
968
        wt.lock_read()
1264
969
        self.addCleanup(wt.unlock)
1265
 
        revisions = list(log.get_view_revisions(
 
970
        revisions = list(self._get_view_revisions(
1266
971
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1267
972
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1268
973
                         revisions)
1269
 
        revisions2 = list(log.get_view_revisions(
 
974
        revisions2 = list(self._get_view_revisions(
1270
975
                mainline_revs, rev_nos, wt.branch, 'reverse',
1271
976
                include_merges=False))
1272
977
        self.assertEqual(revisions, revisions2)
1276
981
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1277
982
        wt.lock_read()
1278
983
        self.addCleanup(wt.unlock)
1279
 
        revisions = list(log.get_view_revisions(
 
984
        revisions = list(self._get_view_revisions(
1280
985
                mainline_revs, rev_nos, wt.branch, 'forward'))
1281
986
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1282
987
                          ('4b', '4', 0), ('4a', '3.1.1', 1)],
1283
988
                         revisions)
1284
 
        revisions = list(log.get_view_revisions(
 
989
        revisions = list(self._get_view_revisions(
1285
990
                mainline_revs, rev_nos, wt.branch, 'forward',
1286
991
                include_merges=False))
1287
992
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1293
998
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1294
999
        wt.lock_read()
1295
1000
        self.addCleanup(wt.unlock)
1296
 
        revisions = list(log.get_view_revisions(
 
1001
        revisions = list(self._get_view_revisions(
1297
1002
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1298
1003
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1299
1004
                          ('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1300
1005
                         revisions)
1301
 
        revisions = list(log.get_view_revisions(
 
1006
        revisions = list(self._get_view_revisions(
1302
1007
                mainline_revs, rev_nos, wt.branch, 'reverse',
1303
1008
                include_merges=False))
1304
1009
        self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1307
1012
 
1308
1013
    def test_get_view_revisions_merge2(self):
1309
1014
        """Test get_view_revisions when there are merges"""
1310
 
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1311
 
        wt.lock_read()
1312
 
        self.addCleanup(wt.unlock)
1313
 
        revisions = list(log.get_view_revisions(
1314
 
                mainline_revs, rev_nos, wt.branch, 'forward'))
 
1015
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
 
1016
        b.lock_read()
 
1017
        self.addCleanup(b.unlock)
 
1018
        revisions = list(self._get_view_revisions(
 
1019
                mainline_revs, rev_nos, b, 'forward'))
1315
1020
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1316
 
                    ('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
 
1021
                    ('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1317
1022
                    ('4a', '2.2.2', 1)]
1318
1023
        self.assertEqual(expected, revisions)
1319
 
        revisions = list(log.get_view_revisions(
1320
 
                mainline_revs, rev_nos, wt.branch, 'forward',
 
1024
        revisions = list(self._get_view_revisions(
 
1025
                mainline_revs, rev_nos, b, 'forward',
1321
1026
                include_merges=False))
1322
1027
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1323
1028
                          ('4b', '4', 0)],
1324
1029
                         revisions)
1325
1030
 
1326
 
 
1327
1031
    def test_file_id_for_range(self):
1328
 
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
1329
 
        wt.lock_read()
1330
 
        self.addCleanup(wt.unlock)
 
1032
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
 
1033
        b.lock_read()
 
1034
        self.addCleanup(b.unlock)
1331
1035
 
1332
1036
        def rev_from_rev_id(revid, branch):
1333
1037
            revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1334
1038
            return revspec.in_history(branch)
1335
1039
 
1336
1040
        def view_revs(start_rev, end_rev, file_id, direction):
1337
 
            revs = log.calculate_view_revisions(
1338
 
                wt.branch,
 
1041
            revs = self.applyDeprecated(
 
1042
                symbol_versioning.deprecated_in((2, 2, 0)),
 
1043
                log.calculate_view_revisions,
 
1044
                b,
1339
1045
                start_rev, # start_revision
1340
1046
                end_rev, # end_revision
1341
1047
                direction, # direction
1342
1048
                file_id, # specific_fileid
1343
1049
                True, # generate_merge_revisions
1344
 
                True, # allow_single_merge_revision
1345
1050
                )
1346
1051
            return revs
1347
1052
 
1348
 
        rev_3a = rev_from_rev_id('3a', wt.branch)
1349
 
        rev_4b = rev_from_rev_id('4b', wt.branch)
1350
 
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
 
1053
        rev_3a = rev_from_rev_id('3a', b)
 
1054
        rev_4b = rev_from_rev_id('4b', b)
 
1055
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1056
                          ('3a', '2.1.1', 2)],
1351
1057
                          view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1352
1058
        # Note: 3c still appears before 3a here because of depth-based sorting
1353
 
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
 
1059
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
 
1060
                          ('3a', '2.1.1', 2)],
1354
1061
                          view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1355
1062
 
1356
1063
 
1357
1064
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1358
1065
 
 
1066
    def get_view_revisions(self, *args):
 
1067
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
 
1068
                                    log.get_view_revisions, *args)
 
1069
 
1359
1070
    def create_tree_with_single_merge(self):
1360
1071
        """Create a branch with a moderate layout.
1361
1072
 
1379
1090
        #       use it. Since 'log' only uses the tree in a readonly
1380
1091
        #       fashion, it seems a shame to regenerate an identical
1381
1092
        #       tree for each test.
 
1093
        # TODO: vila 20100122 One way to address the shame above will be to
 
1094
        #       create a memory tree during test parametrization and give a
 
1095
        #       *copy* of this tree to each test. Copying a memory tree ought
 
1096
        #       to be cheap, at least cheaper than creating them with such
 
1097
        #       complex setups.
1382
1098
        tree = self.make_branch_and_tree('tree')
1383
1099
        tree.lock_write()
1384
1100
        self.addCleanup(tree.unlock)
1459
1175
        mainline = tree.branch.revision_history()
1460
1176
        mainline.insert(0, None)
1461
1177
        revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1462
 
        view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
1463
 
                                                'reverse', True)
 
1178
        view_revs_iter = self.get_view_revisions(
 
1179
            mainline, revnos, tree.branch, 'reverse', True)
1464
1180
        actual_revs = log._filter_revisions_touching_file_id(
1465
 
                            tree.branch,
1466
 
                            file_id,
1467
 
                            list(view_revs_iter))
 
1181
            tree.branch, file_id, list(view_revs_iter))
1468
1182
        self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1469
1183
 
1470
1184
    def test_file_id_f1(self):
1498
1212
        self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1499
1213
        self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1500
1214
 
 
1215
    def test_unknown_file_id(self):
 
1216
        tree = self.create_tree_with_single_merge()
 
1217
        self.assertAllRevisionsForFileID(tree, 'unknown', [])
 
1218
 
 
1219
    def test_empty_branch_unknown_file_id(self):
 
1220
        tree = self.make_branch_and_tree('tree')
 
1221
        self.assertAllRevisionsForFileID(tree, 'unknown', [])
 
1222
 
1501
1223
 
1502
1224
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1503
1225
 
1514
1236
 
1515
1237
class TestLogFormatter(tests.TestCase):
1516
1238
 
 
1239
    def setUp(self):
 
1240
        super(TestLogFormatter, self).setUp()
 
1241
        self.rev = revision.Revision('a-id')
 
1242
        self.lf = log.LogFormatter(None)
 
1243
 
1517
1244
    def test_short_committer(self):
1518
 
        rev = revision.Revision('a-id')
1519
 
        rev.committer = 'John Doe <jdoe@example.com>'
1520
 
        lf = log.LogFormatter(None)
1521
 
        self.assertEqual('John Doe', lf.short_committer(rev))
1522
 
        rev.committer = 'John Smith <jsmith@example.com>'
1523
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1524
 
        rev.committer = 'John Smith'
1525
 
        self.assertEqual('John Smith', lf.short_committer(rev))
1526
 
        rev.committer = 'jsmith@example.com'
1527
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1528
 
        rev.committer = '<jsmith@example.com>'
1529
 
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
1530
 
        rev.committer = 'John Smith jsmith@example.com'
1531
 
        self.assertEqual('John Smith', lf.short_committer(rev))
 
1245
        def assertCommitter(expected, committer):
 
1246
            self.rev.committer = committer
 
1247
            self.assertEqual(expected, self.lf.short_committer(self.rev))
 
1248
 
 
1249
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
 
1250
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
 
1251
        assertCommitter('John Smith', 'John Smith')
 
1252
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
 
1253
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
 
1254
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
1532
1255
 
1533
1256
    def test_short_author(self):
1534
 
        rev = revision.Revision('a-id')
1535
 
        rev.committer = 'John Doe <jdoe@example.com>'
1536
 
        lf = log.LogFormatter(None)
1537
 
        self.assertEqual('John Doe', lf.short_author(rev))
1538
 
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
1539
 
        self.assertEqual('John Smith', lf.short_author(rev))
1540
 
        rev.properties['author'] = 'John Smith'
1541
 
        self.assertEqual('John Smith', lf.short_author(rev))
1542
 
        rev.properties['author'] = 'jsmith@example.com'
1543
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1544
 
        rev.properties['author'] = '<jsmith@example.com>'
1545
 
        self.assertEqual('jsmith@example.com', lf.short_author(rev))
1546
 
        rev.properties['author'] = 'John Smith jsmith@example.com'
1547
 
        self.assertEqual('John Smith', lf.short_author(rev))
 
1257
        def assertAuthor(expected, author):
 
1258
            self.rev.properties['author'] = author
 
1259
            self.assertEqual(expected, self.lf.short_author(self.rev))
 
1260
 
 
1261
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
 
1262
        assertAuthor('John Smith', 'John Smith')
 
1263
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
 
1264
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
 
1265
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
 
1266
 
 
1267
    def test_short_author_from_committer(self):
 
1268
        self.rev.committer = 'John Doe <jdoe@example.com>'
 
1269
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
 
1270
 
 
1271
    def test_short_author_from_authors(self):
 
1272
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
 
1273
                                          'Jane Rey <jrey@example.com>')
 
1274
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
1548
1275
 
1549
1276
 
1550
1277
class TestReverseByDepth(tests.TestCase):
1696
1423
        log.show_branch_change(tree.branch, s, 3, '3b')
1697
1424
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1698
1425
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
 
1426
 
 
1427
 
 
1428
 
 
1429
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
 
1430
 
 
1431
    def setUp(self):
 
1432
        TestCaseForLogFormatter.setUp(self)
 
1433
        log.properties_handler_registry.register(
 
1434
            'bugs_properties_handler',
 
1435
            log._bugs_properties_handler)
 
1436
 
 
1437
    def make_commits_with_bugs(self):
 
1438
        """Helper method for LogFormatter tests"""
 
1439
        tree = self.make_branch_and_tree(u'.')
 
1440
        self.build_tree(['a', 'b'])
 
1441
        tree.add('a')
 
1442
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1443
                       revprops={'bugs': 'test://bug/id fixed'})
 
1444
        tree.add('b')
 
1445
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
 
1446
                       authors=['Joe Bar <joe@bar.com>'],
 
1447
                       revprops={'bugs': 'test://bug/id fixed\n'
 
1448
                                 'test://bug/2 fixed'})
 
1449
        return tree
 
1450
 
 
1451
 
 
1452
    def test_long_bugs(self):
 
1453
        tree = self.make_commits_with_bugs()
 
1454
        self.assertFormatterResult("""\
 
1455
------------------------------------------------------------
 
1456
revno: 2
 
1457
fixes bug(s): test://bug/id test://bug/2
 
1458
author: Joe Bar <joe@bar.com>
 
1459
committer: Joe Foo <joe@foo.com>
 
1460
branch nick: work
 
1461
timestamp: Tue 2005-11-22 00:00:01 +0000
 
1462
message:
 
1463
  multiline
 
1464
  log
 
1465
  message
 
1466
------------------------------------------------------------
 
1467
revno: 1
 
1468
fixes bug(s): test://bug/id
 
1469
committer: Joe Foo <joe@foo.com>
 
1470
branch nick: work
 
1471
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1472
message:
 
1473
  simple log message
 
1474
""",
 
1475
            tree.branch, log.LongLogFormatter)
 
1476
 
 
1477
    def test_short_bugs(self):
 
1478
        tree = self.make_commits_with_bugs()
 
1479
        self.assertFormatterResult("""\
 
1480
    2 Joe Bar\t2005-11-22
 
1481
      fixes bug(s): test://bug/id test://bug/2
 
1482
      multiline
 
1483
      log
 
1484
      message
 
1485
 
 
1486
    1 Joe Foo\t2005-11-22
 
1487
      fixes bug(s): test://bug/id
 
1488
      simple log message
 
1489
 
 
1490
""",
 
1491
            tree.branch, log.ShortLogFormatter)
 
1492
 
 
1493
    def test_wrong_bugs_property(self):
 
1494
        tree = self.make_branch_and_tree(u'.')
 
1495
        self.build_tree(['foo'])
 
1496
        self.wt_commit(tree, 'simple log message', rev_id='a1',
 
1497
                       revprops={'bugs': 'test://bug/id invalid_value'})
 
1498
        self.assertFormatterResult("""\
 
1499
    1 Joe Foo\t2005-11-22
 
1500
      simple log message
 
1501
 
 
1502
""",
 
1503
            tree.branch, log.ShortLogFormatter)
 
1504
 
 
1505
    def test_bugs_handler_present(self):
 
1506
        self.properties_handler_registry.get('bugs_properties_handler')