~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-27 22:07:03 UTC
  • mfrom: (4301.2.5 bzr.ab.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090427220703-oy9b0mxobrksvuyq
(gbache) Handle symlinks better in bzr add

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    errors,
23
22
    log,
24
23
    registry,
25
24
    revision,
26
25
    revisionspec,
27
 
    symbol_versioning,
28
26
    tests,
29
27
    )
30
28
 
31
29
 
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):
 
30
class TestCaseWithoutPropsHandler(tests.TestCaseWithTransport):
52
31
 
53
32
    def setUp(self):
54
 
        super(TestCaseForLogFormatter, self).setUp()
 
33
        super(TestCaseWithoutPropsHandler, self).setUp()
55
34
        # keep a reference to the "current" custom prop. handler registry
56
35
        self.properties_handler_registry = log.properties_handler_registry
57
 
        # Use a clean registry for log
 
36
        # clean up the registry in log
58
37
        log.properties_handler_registry = registry.Registry()
59
38
 
60
 
        def restore():
61
 
            log.properties_handler_registry = self.properties_handler_registry
62
 
        self.addCleanup(restore)
63
 
 
64
 
    def assertFormatterResult(self, result, branch, formatter_class,
65
 
                              formatter_kwargs=None, show_log_kwargs=None):
66
 
        logfile = self.make_utf8_encoded_stringio()
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)
73
 
        self.assertEqualDiff(result, logfile.getvalue())
74
 
 
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>'])
84
 
        self.wt_commit(wt, 'add a', **kwargs)
85
 
        return wt
86
 
 
87
 
    def make_commits_with_trailing_newlines(self, wt):
88
 
        """Helper method for LogFormatter tests"""
89
 
        b = wt.branch
90
 
        b.nick = 'test'
91
 
        self.build_tree_contents([('a', 'hello moto\n')])
92
 
        self.wt_commit(wt, 'simple log message', rev_id='a1')
93
 
        self.build_tree_contents([('b', 'goodbye\n')])
94
 
        wt.add('b')
95
 
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
96
 
 
97
 
        self.build_tree_contents([('c', 'just another manic monday\n')])
98
 
        wt.add('c')
99
 
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
100
 
        return b
101
 
 
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('')
107
 
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
108
 
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
109
 
        wt.set_parent_ids(['rev-1', 'rev-2a'])
110
 
        wt.branch.set_last_revision_info(1, 'rev-1')
111
 
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
112
 
        if with_tags:
113
 
            branch = wt.branch
114
 
            branch.tags.set_tag('v0.2', 'rev-2b')
115
 
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
116
 
            branch.tags.set_tag('v1.0rc1', 'rev-3')
117
 
            branch.tags.set_tag('v1.0', 'rev-3')
118
 
        return wt
 
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
119
43
 
120
44
 
121
45
class LogCatcher(log.LogFormatter):
122
 
    """Pull log messages into a list rather than displaying them.
123
 
 
124
 
    To simplify testing we save logged revisions here rather than actually
125
 
    formatting anything, so that we can precisely check the result without
126
 
    being dependent on the formatting.
 
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.
127
53
    """
128
54
 
129
 
    supports_merge_revisions = True
130
55
    supports_delta = True
131
 
    supports_diff = True
132
 
    preferred_levels = 0
133
56
 
134
 
    def __init__(self, *args, **kwargs):
135
 
        kwargs.update(dict(to_file=None))
136
 
        super(LogCatcher, self).__init__(*args, **kwargs)
137
 
        self.revisions = []
 
57
    def __init__(self):
 
58
        super(LogCatcher, self).__init__(to_file=None)
 
59
        self.logs = []
138
60
 
139
61
    def log_revision(self, revision):
140
 
        self.revisions.append(revision)
 
62
        self.logs.append(revision)
141
63
 
142
64
 
143
65
class TestShowLog(tests.TestCaseWithTransport):
184
106
        lf = LogCatcher()
185
107
        log.show_log(wt.branch, lf)
186
108
        # no entries yet
187
 
        self.assertEqual([], lf.revisions)
 
109
        self.assertEqual([], lf.logs)
188
110
 
189
111
    def test_empty_commit(self):
190
112
        wt = self.make_branch_and_tree('.')
192
114
        wt.commit('empty commit')
193
115
        lf = LogCatcher()
194
116
        log.show_log(wt.branch, lf, verbose=True)
195
 
        revs = lf.revisions
196
 
        self.assertEqual(1, len(revs))
197
 
        self.assertEqual('1', revs[0].revno)
198
 
        self.assertEqual('empty commit', revs[0].rev.message)
199
 
        self.checkDelta(revs[0].delta)
 
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)
200
121
 
201
122
    def test_simple_commit(self):
202
123
        wt = self.make_branch_and_tree('.')
208
129
                            u'<test@example.com>')
209
130
        lf = LogCatcher()
210
131
        log.show_log(wt.branch, lf, verbose=True)
211
 
        self.assertEqual(2, len(lf.revisions))
 
132
        self.assertEqual(2, len(lf.logs))
212
133
        # first one is most recent
213
 
        log_entry = lf.revisions[0]
 
134
        log_entry = lf.logs[0]
214
135
        self.assertEqual('2', log_entry.revno)
215
136
        self.assertEqual('add one file', log_entry.rev.message)
216
137
        self.checkDelta(log_entry.delta, added=['hello'])
222
143
        wt.commit(msg)
223
144
        lf = LogCatcher()
224
145
        log.show_log(wt.branch, lf, verbose=True)
225
 
        committed_msg = lf.revisions[0].rev.message
226
 
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
227
 
            self.assertNotEqual(msg, committed_msg)
228
 
            self.assertTrue(len(committed_msg) > len(msg))
229
 
        else:
230
 
            self.assertEqual(msg, committed_msg)
 
146
        committed_msg = lf.logs[0].rev.message
 
147
        self.assertNotEqual(msg, committed_msg)
 
148
        self.assertTrue(len(committed_msg) > len(msg))
231
149
 
232
150
    def test_commit_message_without_control_chars(self):
233
151
        wt = self.make_branch_and_tree('.')
239
157
        wt.commit(msg)
240
158
        lf = LogCatcher()
241
159
        log.show_log(wt.branch, lf, verbose=True)
242
 
        committed_msg = lf.revisions[0].rev.message
 
160
        committed_msg = lf.logs[0].rev.message
243
161
        self.assertEqual(msg, committed_msg)
244
162
 
245
163
    def test_deltas_in_merge_revisions(self):
263
181
        lf.supports_merge_revisions = True
264
182
        log.show_log(b, lf, verbose=True)
265
183
 
266
 
        revs = lf.revisions
267
 
        self.assertEqual(3, len(revs))
 
184
        self.assertEqual(3, len(lf.logs))
268
185
 
269
 
        logentry = revs[0]
 
186
        logentry = lf.logs[0]
270
187
        self.assertEqual('2', logentry.revno)
271
188
        self.assertEqual('merge child branch', logentry.rev.message)
272
189
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
273
190
 
274
 
        logentry = revs[1]
 
191
        logentry = lf.logs[1]
275
192
        self.assertEqual('1.1.1', logentry.revno)
276
193
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
277
194
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
278
195
 
279
 
        logentry = revs[2]
 
196
        logentry = lf.logs[2]
280
197
        self.assertEqual('1', logentry.revno)
281
198
        self.assertEqual('add file1 and file2', logentry.rev.message)
282
199
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
283
200
 
284
201
 
285
 
class TestShortLogFormatter(TestCaseForLogFormatter):
 
202
def make_commits_with_trailing_newlines(wt):
 
203
    """Helper method for LogFormatter tests"""
 
204
    b = wt.branch
 
205
    b.nick='test'
 
206
    open('a', 'wb').write('hello moto\n')
 
207
    wt.add('a')
 
208
    wt.commit('simple log message', rev_id='a1',
 
209
              timestamp=1132586655.459960938, timezone=-6*3600,
 
210
              committer='Joe Foo <joe@foo.com>')
 
211
    open('b', 'wb').write('goodbye\n')
 
212
    wt.add('b')
 
213
    wt.commit('multiline\nlog\nmessage\n', rev_id='a2',
 
214
              timestamp=1132586842.411175966, timezone=-6*3600,
 
215
              committer='Joe Foo <joe@foo.com>',
 
216
              authors=['Joe Bar <joe@bar.com>'])
 
217
 
 
218
    open('c', 'wb').write('just another manic monday\n')
 
219
    wt.add('c')
 
220
    wt.commit('single line with trailing newline\n', rev_id='a3',
 
221
              timestamp=1132587176.835228920, timezone=-6*3600,
 
222
              committer = 'Joe Foo <joe@foo.com>')
 
223
    return b
 
224
 
 
225
 
 
226
def normalize_log(log):
 
227
    """Replaces the variable lines of logs with fixed lines"""
 
228
    author = 'author: Dolor Sit <test@example.com>'
 
229
    committer = 'committer: Lorem Ipsum <test@example.com>'
 
230
    lines = log.splitlines(True)
 
231
    for idx,line in enumerate(lines):
 
232
        stripped_line = line.lstrip()
 
233
        indent = ' ' * (len(line) - len(stripped_line))
 
234
        if stripped_line.startswith('author:'):
 
235
            lines[idx] = indent + author + '\n'
 
236
        elif stripped_line.startswith('committer:'):
 
237
            lines[idx] = indent + committer + '\n'
 
238
        elif stripped_line.startswith('timestamp:'):
 
239
            lines[idx] = indent + 'timestamp: Just now\n'
 
240
    return ''.join(lines)
 
241
 
 
242
 
 
243
class TestShortLogFormatter(tests.TestCaseWithTransport):
286
244
 
287
245
    def test_trailing_newlines(self):
288
246
        wt = self.make_branch_and_tree('.')
289
 
        b = self.make_commits_with_trailing_newlines(wt)
290
 
        self.assertFormatterResult("""\
291
 
    3 Joe Foo\t2005-11-22
 
247
        b = make_commits_with_trailing_newlines(wt)
 
248
        sio = self.make_utf8_encoded_stringio()
 
249
        lf = log.ShortLogFormatter(to_file=sio)
 
250
        log.show_log(b, lf)
 
251
        self.assertEqualDiff("""\
 
252
    3 Joe Foo\t2005-11-21
292
253
      single line with trailing newline
293
254
 
294
 
    2 Joe Foo\t2005-11-22
 
255
    2 Joe Bar\t2005-11-21
295
256
      multiline
296
257
      log
297
258
      message
298
259
 
299
 
    1 Joe Foo\t2005-11-22
 
260
    1 Joe Foo\t2005-11-21
300
261
      simple log message
301
262
 
302
263
""",
303
 
            b, log.ShortLogFormatter)
 
264
                             sio.getvalue())
 
265
 
 
266
    def _prepare_tree_with_merges(self, with_tags=False):
 
267
        wt = self.make_branch_and_memory_tree('.')
 
268
        wt.lock_write()
 
269
        self.addCleanup(wt.unlock)
 
270
        wt.add('')
 
271
        wt.commit('rev-1', rev_id='rev-1',
 
272
                  timestamp=1132586655, timezone=36000,
 
273
                  committer='Joe Foo <joe@foo.com>')
 
274
        wt.commit('rev-merged', rev_id='rev-2a',
 
275
                  timestamp=1132586700, timezone=36000,
 
276
                  committer='Joe Foo <joe@foo.com>')
 
277
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
278
        wt.branch.set_last_revision_info(1, 'rev-1')
 
279
        wt.commit('rev-2', rev_id='rev-2b',
 
280
                  timestamp=1132586800, timezone=36000,
 
281
                  committer='Joe Foo <joe@foo.com>')
 
282
        if with_tags:
 
283
            branch = wt.branch
 
284
            branch.tags.set_tag('v0.2', 'rev-2b')
 
285
            wt.commit('rev-3', rev_id='rev-3',
 
286
                      timestamp=1132586900, timezone=36000,
 
287
                      committer='Jane Foo <jane@foo.com>')
 
288
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
289
            branch.tags.set_tag('v1.0', 'rev-3')
 
290
        return wt
304
291
 
305
292
    def test_short_log_with_merges(self):
306
293
        wt = self._prepare_tree_with_merges()
307
 
        self.assertFormatterResult("""\
 
294
        logfile = self.make_utf8_encoded_stringio()
 
295
        formatter = log.ShortLogFormatter(to_file=logfile)
 
296
        log.show_log(wt.branch, formatter)
 
297
        self.assertEqualDiff("""\
308
298
    2 Joe Foo\t2005-11-22 [merge]
309
299
      rev-2
310
300
 
312
302
      rev-1
313
303
 
314
304
""",
315
 
            wt.branch, log.ShortLogFormatter)
 
305
                             logfile.getvalue())
316
306
 
317
307
    def test_short_log_with_merges_and_advice(self):
318
308
        wt = self._prepare_tree_with_merges()
319
 
        self.assertFormatterResult("""\
 
309
        logfile = self.make_utf8_encoded_stringio()
 
310
        formatter = log.ShortLogFormatter(to_file=logfile,
 
311
            show_advice=True)
 
312
        log.show_log(wt.branch, formatter)
 
313
        self.assertEqualDiff("""\
320
314
    2 Joe Foo\t2005-11-22 [merge]
321
315
      rev-2
322
316
 
325
319
 
326
320
Use --include-merges or -n0 to see merged revisions.
327
321
""",
328
 
            wt.branch, log.ShortLogFormatter,
329
 
            formatter_kwargs=dict(show_advice=True))
 
322
                             logfile.getvalue())
330
323
 
331
324
    def test_short_log_with_merges_and_range(self):
332
 
        wt = self._prepare_tree_with_merges()
333
 
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
 
325
        wt = self.make_branch_and_memory_tree('.')
 
326
        wt.lock_write()
 
327
        self.addCleanup(wt.unlock)
 
328
        wt.add('')
 
329
        wt.commit('rev-1', rev_id='rev-1',
 
330
                  timestamp=1132586655, timezone=36000,
 
331
                  committer='Joe Foo <joe@foo.com>')
 
332
        wt.commit('rev-merged', rev_id='rev-2a',
 
333
                  timestamp=1132586700, timezone=36000,
 
334
                  committer='Joe Foo <joe@foo.com>')
 
335
        wt.branch.set_last_revision_info(1, 'rev-1')
 
336
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
337
        wt.commit('rev-2b', rev_id='rev-2b',
 
338
                  timestamp=1132586800, timezone=36000,
 
339
                  committer='Joe Foo <joe@foo.com>')
 
340
        wt.commit('rev-3a', rev_id='rev-3a',
 
341
                  timestamp=1132586800, timezone=36000,
 
342
                  committer='Joe Foo <joe@foo.com>')
334
343
        wt.branch.set_last_revision_info(2, 'rev-2b')
335
344
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
336
 
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
337
 
        self.assertFormatterResult("""\
 
345
        wt.commit('rev-3b', rev_id='rev-3b',
 
346
                  timestamp=1132586800, timezone=36000,
 
347
                  committer='Joe Foo <joe@foo.com>')
 
348
        logfile = self.make_utf8_encoded_stringio()
 
349
        formatter = log.ShortLogFormatter(to_file=logfile)
 
350
        log.show_log(wt.branch, formatter,
 
351
            start_revision=2, end_revision=3)
 
352
        self.assertEqualDiff("""\
338
353
    3 Joe Foo\t2005-11-22 [merge]
339
354
      rev-3b
340
355
 
341
356
    2 Joe Foo\t2005-11-22 [merge]
342
 
      rev-2
 
357
      rev-2b
343
358
 
344
359
""",
345
 
            wt.branch, log.ShortLogFormatter,
346
 
            show_log_kwargs=dict(start_revision=2, end_revision=3))
 
360
                             logfile.getvalue())
347
361
 
348
362
    def test_short_log_with_tags(self):
349
363
        wt = self._prepare_tree_with_merges(with_tags=True)
350
 
        self.assertFormatterResult("""\
351
 
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
 
364
        logfile = self.make_utf8_encoded_stringio()
 
365
        formatter = log.ShortLogFormatter(to_file=logfile)
 
366
        log.show_log(wt.branch, formatter)
 
367
        self.assertEqualDiff("""\
 
368
    3 Jane Foo\t2005-11-22 {v1.0, v1.0rc1}
352
369
      rev-3
353
370
 
354
371
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
358
375
      rev-1
359
376
 
360
377
""",
361
 
            wt.branch, log.ShortLogFormatter)
 
378
                             logfile.getvalue())
362
379
 
363
380
    def test_short_log_single_merge_revision(self):
364
 
        wt = self._prepare_tree_with_merges()
 
381
        wt = self.make_branch_and_memory_tree('.')
 
382
        wt.lock_write()
 
383
        self.addCleanup(wt.unlock)
 
384
        wt.add('')
 
385
        wt.commit('rev-1', rev_id='rev-1',
 
386
                  timestamp=1132586655, timezone=36000,
 
387
                  committer='Joe Foo <joe@foo.com>')
 
388
        wt.commit('rev-merged', rev_id='rev-2a',
 
389
                  timestamp=1132586700, timezone=36000,
 
390
                  committer='Joe Foo <joe@foo.com>')
 
391
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
392
        wt.branch.set_last_revision_info(1, 'rev-1')
 
393
        wt.commit('rev-2', rev_id='rev-2b',
 
394
                  timestamp=1132586800, timezone=36000,
 
395
                  committer='Joe Foo <joe@foo.com>')
 
396
        logfile = self.make_utf8_encoded_stringio()
 
397
        formatter = log.ShortLogFormatter(to_file=logfile)
365
398
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
366
 
        rev = revspec.in_history(wt.branch)
367
 
        self.assertFormatterResult("""\
 
399
        wtb = wt.branch
 
400
        rev = revspec.in_history(wtb)
 
401
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
402
        self.assertEqualDiff("""\
368
403
      1.1.1 Joe Foo\t2005-11-22
369
404
            rev-merged
370
405
 
371
406
""",
372
 
            wt.branch, log.ShortLogFormatter,
373
 
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
374
 
 
375
 
    def test_show_ids(self):
376
 
        wt = self.make_branch_and_tree('parent')
377
 
        self.build_tree(['parent/f1', 'parent/f2'])
378
 
        wt.add(['f1','f2'])
379
 
        self.wt_commit(wt, 'first post', rev_id='a')
380
 
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
381
 
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
382
 
        wt.merge_from_branch(child_wt.branch)
383
 
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
384
 
        self.assertFormatterResult("""\
385
 
    2 Joe Foo\t2005-11-22 [merge]
386
 
      revision-id:c
387
 
      merge branch 1
388
 
 
389
 
          1.1.1 Joe Foo\t2005-11-22
390
 
                revision-id:b
391
 
                branch 1 changes
392
 
 
393
 
    1 Joe Foo\t2005-11-22
394
 
      revision-id:a
395
 
      first post
396
 
 
397
 
""",
398
 
            wt.branch, log.ShortLogFormatter,
399
 
            formatter_kwargs=dict(levels=0,show_ids=True))
400
 
 
401
 
 
402
 
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
 
407
                             logfile.getvalue())
 
408
 
 
409
 
 
410
class TestShortLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
403
411
 
404
412
    def test_short_merge_revs_log_with_merges(self):
405
 
        wt = self._prepare_tree_with_merges()
 
413
        wt = self.make_branch_and_memory_tree('.')
 
414
        wt.lock_write()
 
415
        self.addCleanup(wt.unlock)
 
416
        wt.add('')
 
417
        wt.commit('rev-1', rev_id='rev-1',
 
418
                  timestamp=1132586655, timezone=36000,
 
419
                  committer='Joe Foo <joe@foo.com>')
 
420
        wt.commit('rev-merged', rev_id='rev-2a',
 
421
                  timestamp=1132586700, timezone=36000,
 
422
                  committer='Joe Foo <joe@foo.com>')
 
423
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
424
        wt.branch.set_last_revision_info(1, 'rev-1')
 
425
        wt.commit('rev-2', rev_id='rev-2b',
 
426
                  timestamp=1132586800, timezone=36000,
 
427
                  committer='Joe Foo <joe@foo.com>')
 
428
        logfile = self.make_utf8_encoded_stringio()
 
429
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
 
430
        log.show_log(wt.branch, formatter)
406
431
        # Note that the 1.1.1 indenting is in fact correct given that
407
432
        # the revision numbers are right justified within 5 characters
408
433
        # for mainline revnos and 9 characters for dotted revnos.
409
 
        self.assertFormatterResult("""\
 
434
        self.assertEqualDiff("""\
410
435
    2 Joe Foo\t2005-11-22 [merge]
411
436
      rev-2
412
437
 
417
442
      rev-1
418
443
 
419
444
""",
420
 
            wt.branch, log.ShortLogFormatter,
421
 
            formatter_kwargs=dict(levels=0))
 
445
                             logfile.getvalue())
422
446
 
423
447
    def test_short_merge_revs_log_single_merge_revision(self):
424
 
        wt = self._prepare_tree_with_merges()
 
448
        wt = self.make_branch_and_memory_tree('.')
 
449
        wt.lock_write()
 
450
        self.addCleanup(wt.unlock)
 
451
        wt.add('')
 
452
        wt.commit('rev-1', rev_id='rev-1',
 
453
                  timestamp=1132586655, timezone=36000,
 
454
                  committer='Joe Foo <joe@foo.com>')
 
455
        wt.commit('rev-merged', rev_id='rev-2a',
 
456
                  timestamp=1132586700, timezone=36000,
 
457
                  committer='Joe Foo <joe@foo.com>')
 
458
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
459
        wt.branch.set_last_revision_info(1, 'rev-1')
 
460
        wt.commit('rev-2', rev_id='rev-2b',
 
461
                  timestamp=1132586800, timezone=36000,
 
462
                  committer='Joe Foo <joe@foo.com>')
 
463
        logfile = self.make_utf8_encoded_stringio()
 
464
        formatter = log.ShortLogFormatter(to_file=logfile, levels=0)
425
465
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
426
 
        rev = revspec.in_history(wt.branch)
427
 
        self.assertFormatterResult("""\
 
466
        wtb = wt.branch
 
467
        rev = revspec.in_history(wtb)
 
468
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
469
        self.assertEqualDiff("""\
428
470
      1.1.1 Joe Foo\t2005-11-22
429
471
            rev-merged
430
472
 
431
473
""",
432
 
            wt.branch, log.ShortLogFormatter,
433
 
            formatter_kwargs=dict(levels=0),
434
 
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
435
 
 
436
 
 
437
 
class TestLongLogFormatter(TestCaseForLogFormatter):
 
474
                             logfile.getvalue())
 
475
 
 
476
 
 
477
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
438
478
 
439
479
    def test_verbose_log(self):
440
480
        """Verbose log includes changed files
441
481
 
442
482
        bug #4676
443
483
        """
444
 
        wt = self.make_standard_commit('test_verbose_log', authors=[])
445
 
        self.assertFormatterResult('''\
 
484
        wt = self.make_branch_and_tree('.')
 
485
        b = wt.branch
 
486
        self.build_tree(['a'])
 
487
        wt.add('a')
 
488
        # XXX: why does a longer nick show up?
 
489
        b.nick = 'test_verbose_log'
 
490
        wt.commit(message='add a',
 
491
                  timestamp=1132711707,
 
492
                  timezone=36000,
 
493
                  committer='Lorem Ipsum <test@example.com>')
 
494
        logfile = file('out.tmp', 'w+')
 
495
        formatter = log.LongLogFormatter(to_file=logfile)
 
496
        log.show_log(b, formatter, verbose=True)
 
497
        logfile.flush()
 
498
        logfile.seek(0)
 
499
        log_contents = logfile.read()
 
500
        self.assertEqualDiff('''\
446
501
------------------------------------------------------------
447
502
revno: 1
448
503
committer: Lorem Ipsum <test@example.com>
449
504
branch nick: test_verbose_log
450
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
505
timestamp: Wed 2005-11-23 12:08:27 +1000
451
506
message:
452
507
  add a
453
508
added:
454
509
  a
455
510
''',
456
 
            wt.branch, log.LongLogFormatter,
457
 
            show_log_kwargs=dict(verbose=True))
 
511
                             log_contents)
458
512
 
459
513
    def test_merges_are_indented_by_level(self):
460
514
        wt = self.make_branch_and_tree('parent')
461
 
        self.wt_commit(wt, 'first post')
462
 
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
463
 
        self.wt_commit(child_wt, 'branch 1')
464
 
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
465
 
        self.wt_commit(smallerchild_wt, 'branch 2')
466
 
        child_wt.merge_from_branch(smallerchild_wt.branch)
467
 
        self.wt_commit(child_wt, 'merge branch 2')
468
 
        wt.merge_from_branch(child_wt.branch)
469
 
        self.wt_commit(wt, 'merge branch 1')
470
 
        self.assertFormatterResult("""\
 
515
        wt.commit('first post')
 
516
        self.run_bzr('branch parent child')
 
517
        self.run_bzr(['commit', '-m', 'branch 1', '--unchanged', 'child'])
 
518
        self.run_bzr('branch child smallerchild')
 
519
        self.run_bzr(['commit', '-m', 'branch 2', '--unchanged',
 
520
            'smallerchild'])
 
521
        os.chdir('child')
 
522
        self.run_bzr('merge ../smallerchild')
 
523
        self.run_bzr(['commit', '-m', 'merge branch 2'])
 
524
        os.chdir('../parent')
 
525
        self.run_bzr('merge ../child')
 
526
        wt.commit('merge branch 1')
 
527
        b = wt.branch
 
528
        sio = self.make_utf8_encoded_stringio()
 
529
        lf = log.LongLogFormatter(to_file=sio, levels=0)
 
530
        log.show_log(b, lf, verbose=True)
 
531
        the_log = normalize_log(sio.getvalue())
 
532
        self.assertEqualDiff("""\
471
533
------------------------------------------------------------
472
534
revno: 2 [merge]
473
 
committer: Joe Foo <joe@foo.com>
 
535
committer: Lorem Ipsum <test@example.com>
474
536
branch nick: parent
475
 
timestamp: Tue 2005-11-22 00:00:04 +0000
 
537
timestamp: Just now
476
538
message:
477
539
  merge branch 1
478
540
    ------------------------------------------------------------
479
541
    revno: 1.1.2 [merge]
480
 
    committer: Joe Foo <joe@foo.com>
 
542
    committer: Lorem Ipsum <test@example.com>
481
543
    branch nick: child
482
 
    timestamp: Tue 2005-11-22 00:00:03 +0000
 
544
    timestamp: Just now
483
545
    message:
484
546
      merge branch 2
485
547
        ------------------------------------------------------------
486
548
        revno: 1.2.1
487
 
        committer: Joe Foo <joe@foo.com>
 
549
        committer: Lorem Ipsum <test@example.com>
488
550
        branch nick: smallerchild
489
 
        timestamp: Tue 2005-11-22 00:00:02 +0000
 
551
        timestamp: Just now
490
552
        message:
491
553
          branch 2
492
554
    ------------------------------------------------------------
493
555
    revno: 1.1.1
494
 
    committer: Joe Foo <joe@foo.com>
 
556
    committer: Lorem Ipsum <test@example.com>
495
557
    branch nick: child
496
 
    timestamp: Tue 2005-11-22 00:00:01 +0000
 
558
    timestamp: Just now
497
559
    message:
498
560
      branch 1
499
561
------------------------------------------------------------
500
562
revno: 1
501
 
committer: Joe Foo <joe@foo.com>
 
563
committer: Lorem Ipsum <test@example.com>
502
564
branch nick: parent
503
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
565
timestamp: Just now
504
566
message:
505
567
  first post
506
568
""",
507
 
            wt.branch, log.LongLogFormatter,
508
 
            formatter_kwargs=dict(levels=0),
509
 
            show_log_kwargs=dict(verbose=True))
 
569
                             the_log)
510
570
 
511
571
    def test_verbose_merge_revisions_contain_deltas(self):
512
572
        wt = self.make_branch_and_tree('parent')
513
573
        self.build_tree(['parent/f1', 'parent/f2'])
514
574
        wt.add(['f1','f2'])
515
 
        self.wt_commit(wt, 'first post')
516
 
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
575
        wt.commit('first post')
 
576
        self.run_bzr('branch parent child')
517
577
        os.unlink('child/f1')
518
 
        self.build_tree_contents([('child/f2', 'hello\n')])
519
 
        self.wt_commit(child_wt, 'removed f1 and modified f2')
520
 
        wt.merge_from_branch(child_wt.branch)
521
 
        self.wt_commit(wt, 'merge branch 1')
522
 
        self.assertFormatterResult("""\
 
578
        file('child/f2', 'wb').write('hello\n')
 
579
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
 
580
            'child'])
 
581
        os.chdir('parent')
 
582
        self.run_bzr('merge ../child')
 
583
        wt.commit('merge branch 1')
 
584
        b = wt.branch
 
585
        sio = self.make_utf8_encoded_stringio()
 
586
        lf = log.LongLogFormatter(to_file=sio, levels=0)
 
587
        log.show_log(b, lf, verbose=True)
 
588
        the_log = normalize_log(sio.getvalue())
 
589
        self.assertEqualDiff("""\
523
590
------------------------------------------------------------
524
591
revno: 2 [merge]
525
 
committer: Joe Foo <joe@foo.com>
 
592
committer: Lorem Ipsum <test@example.com>
526
593
branch nick: parent
527
 
timestamp: Tue 2005-11-22 00:00:02 +0000
 
594
timestamp: Just now
528
595
message:
529
596
  merge branch 1
530
597
removed:
533
600
  f2
534
601
    ------------------------------------------------------------
535
602
    revno: 1.1.1
536
 
    committer: Joe Foo <joe@foo.com>
 
603
    committer: Lorem Ipsum <test@example.com>
537
604
    branch nick: child
538
 
    timestamp: Tue 2005-11-22 00:00:01 +0000
 
605
    timestamp: Just now
539
606
    message:
540
607
      removed f1 and modified f2
541
608
    removed:
544
611
      f2
545
612
------------------------------------------------------------
546
613
revno: 1
547
 
committer: Joe Foo <joe@foo.com>
 
614
committer: Lorem Ipsum <test@example.com>
548
615
branch nick: parent
549
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
616
timestamp: Just now
550
617
message:
551
618
  first post
552
619
added:
553
620
  f1
554
621
  f2
555
622
""",
556
 
            wt.branch, log.LongLogFormatter,
557
 
            formatter_kwargs=dict(levels=0),
558
 
            show_log_kwargs=dict(verbose=True))
 
623
                             the_log)
559
624
 
560
625
    def test_trailing_newlines(self):
561
626
        wt = self.make_branch_and_tree('.')
562
 
        b = self.make_commits_with_trailing_newlines(wt)
563
 
        self.assertFormatterResult("""\
 
627
        b = make_commits_with_trailing_newlines(wt)
 
628
        sio = self.make_utf8_encoded_stringio()
 
629
        lf = log.LongLogFormatter(to_file=sio)
 
630
        log.show_log(b, lf)
 
631
        self.assertEqualDiff("""\
564
632
------------------------------------------------------------
565
633
revno: 3
566
634
committer: Joe Foo <joe@foo.com>
567
635
branch nick: test
568
 
timestamp: Tue 2005-11-22 00:00:02 +0000
 
636
timestamp: Mon 2005-11-21 09:32:56 -0600
569
637
message:
570
638
  single line with trailing newline
571
639
------------------------------------------------------------
572
640
revno: 2
 
641
author: Joe Bar <joe@bar.com>
573
642
committer: Joe Foo <joe@foo.com>
574
643
branch nick: test
575
 
timestamp: Tue 2005-11-22 00:00:01 +0000
 
644
timestamp: Mon 2005-11-21 09:27:22 -0600
576
645
message:
577
646
  multiline
578
647
  log
581
650
revno: 1
582
651
committer: Joe Foo <joe@foo.com>
583
652
branch nick: test
584
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
653
timestamp: Mon 2005-11-21 09:24:15 -0600
585
654
message:
586
655
  simple log message
587
656
""",
588
 
        b, log.LongLogFormatter)
 
657
                             sio.getvalue())
589
658
 
590
659
    def test_author_in_log(self):
591
660
        """Log includes the author name if it's set in
592
661
        the revision properties
593
662
        """
594
 
        wt = self.make_standard_commit('test_author_log',
595
 
            authors=['John Doe <jdoe@example.com>',
596
 
                     'Jane Rey <jrey@example.com>'])
597
 
        self.assertFormatterResult("""\
 
663
        wt = self.make_branch_and_tree('.')
 
664
        b = wt.branch
 
665
        self.build_tree(['a'])
 
666
        wt.add('a')
 
667
        b.nick = 'test_author_log'
 
668
        wt.commit(message='add a',
 
669
                  timestamp=1132711707,
 
670
                  timezone=36000,
 
671
                  committer='Lorem Ipsum <test@example.com>',
 
672
                  authors=['John Doe <jdoe@example.com>',
 
673
                           'Jane Rey <jrey@example.com>'])
 
674
        sio = StringIO()
 
675
        formatter = log.LongLogFormatter(to_file=sio)
 
676
        log.show_log(b, formatter)
 
677
        self.assertEqualDiff('''\
598
678
------------------------------------------------------------
599
679
revno: 1
600
680
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
601
681
committer: Lorem Ipsum <test@example.com>
602
682
branch nick: test_author_log
603
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
683
timestamp: Wed 2005-11-23 12:08:27 +1000
604
684
message:
605
685
  add a
606
 
""",
607
 
        wt.branch, log.LongLogFormatter)
 
686
''',
 
687
                             sio.getvalue())
608
688
 
609
689
    def test_properties_in_log(self):
610
690
        """Log includes the custom properties returned by the registered
611
691
        handlers.
612
692
        """
613
 
        wt = self.make_standard_commit('test_properties_in_log')
614
 
        def trivial_custom_prop_handler(revision):
615
 
            return {'test_prop':'test_value'}
 
693
        wt = self.make_branch_and_tree('.')
 
694
        b = wt.branch
 
695
        self.build_tree(['a'])
 
696
        wt.add('a')
 
697
        b.nick = 'test_properties_in_log'
 
698
        wt.commit(message='add a',
 
699
                  timestamp=1132711707,
 
700
                  timezone=36000,
 
701
                  committer='Lorem Ipsum <test@example.com>',
 
702
                  authors=['John Doe <jdoe@example.com>'])
 
703
        sio = StringIO()
 
704
        formatter = log.LongLogFormatter(to_file=sio)
 
705
        try:
 
706
            def trivial_custom_prop_handler(revision):
 
707
                return {'test_prop':'test_value'}
616
708
 
617
 
        # Cleaned up in setUp()
618
 
        log.properties_handler_registry.register(
619
 
            'trivial_custom_prop_handler',
620
 
            trivial_custom_prop_handler)
621
 
        self.assertFormatterResult("""\
 
709
            log.properties_handler_registry.register(
 
710
                'trivial_custom_prop_handler',
 
711
                trivial_custom_prop_handler)
 
712
            log.show_log(b, formatter)
 
713
        finally:
 
714
            log.properties_handler_registry.remove(
 
715
                'trivial_custom_prop_handler')
 
716
            self.assertEqualDiff('''\
622
717
------------------------------------------------------------
623
718
revno: 1
624
719
test_prop: test_value
625
720
author: John Doe <jdoe@example.com>
626
721
committer: Lorem Ipsum <test@example.com>
627
722
branch nick: test_properties_in_log
628
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
723
timestamp: Wed 2005-11-23 12:08:27 +1000
629
724
message:
630
725
  add a
631
 
""",
632
 
            wt.branch, log.LongLogFormatter)
 
726
''',
 
727
                                 sio.getvalue())
633
728
 
634
729
    def test_properties_in_short_log(self):
635
730
        """Log includes the custom properties returned by the registered
636
731
        handlers.
637
732
        """
638
 
        wt = self.make_standard_commit('test_properties_in_short_log')
639
 
        def trivial_custom_prop_handler(revision):
640
 
            return {'test_prop':'test_value'}
 
733
        wt = self.make_branch_and_tree('.')
 
734
        b = wt.branch
 
735
        self.build_tree(['a'])
 
736
        wt.add('a')
 
737
        b.nick = 'test_properties_in_short_log'
 
738
        wt.commit(message='add a',
 
739
                  timestamp=1132711707,
 
740
                  timezone=36000,
 
741
                  committer='Lorem Ipsum <test@example.com>',
 
742
                  authors=['John Doe <jdoe@example.com>'])
 
743
        sio = StringIO()
 
744
        formatter = log.ShortLogFormatter(to_file=sio)
 
745
        try:
 
746
            def trivial_custom_prop_handler(revision):
 
747
                return {'test_prop':'test_value'}
641
748
 
642
 
        log.properties_handler_registry.register(
643
 
            'trivial_custom_prop_handler',
644
 
            trivial_custom_prop_handler)
645
 
        self.assertFormatterResult("""\
646
 
    1 John Doe\t2005-11-22
 
749
            log.properties_handler_registry.register(
 
750
                'trivial_custom_prop_handler',
 
751
                trivial_custom_prop_handler)
 
752
            log.show_log(b, formatter)
 
753
        finally:
 
754
            log.properties_handler_registry.remove(
 
755
                'trivial_custom_prop_handler')
 
756
            self.assertEqualDiff('''\
 
757
    1 John Doe\t2005-11-23
647
758
      test_prop: test_value
648
759
      add a
649
760
 
650
 
""",
651
 
            wt.branch, log.ShortLogFormatter)
 
761
''',
 
762
                                 sio.getvalue())
652
763
 
653
764
    def test_error_in_properties_handler(self):
654
765
        """Log includes the custom properties returned by the registered
655
766
        handlers.
656
767
        """
657
 
        wt = self.make_standard_commit('error_in_properties_handler',
658
 
            revprops={'first_prop':'first_value'})
659
 
        sio = self.make_utf8_encoded_stringio()
 
768
        wt = self.make_branch_and_tree('.')
 
769
        b = wt.branch
 
770
        self.build_tree(['a'])
 
771
        wt.add('a')
 
772
        b.nick = 'test_author_log'
 
773
        wt.commit(message='add a',
 
774
                  timestamp=1132711707,
 
775
                  timezone=36000,
 
776
                  committer='Lorem Ipsum <test@example.com>',
 
777
                  authors=['John Doe <jdoe@example.com>'],
 
778
                  revprops={'first_prop':'first_value'})
 
779
        sio = StringIO()
660
780
        formatter = log.LongLogFormatter(to_file=sio)
661
 
        def trivial_custom_prop_handler(revision):
662
 
            raise StandardError("a test error")
 
781
        try:
 
782
            def trivial_custom_prop_handler(revision):
 
783
                raise StandardError("a test error")
663
784
 
664
 
        log.properties_handler_registry.register(
665
 
            'trivial_custom_prop_handler',
666
 
            trivial_custom_prop_handler)
667
 
        self.assertRaises(StandardError, log.show_log, wt.branch, formatter,)
 
785
            log.properties_handler_registry.register(
 
786
                'trivial_custom_prop_handler',
 
787
                trivial_custom_prop_handler)
 
788
            self.assertRaises(StandardError, log.show_log, b, formatter,)
 
789
        finally:
 
790
            log.properties_handler_registry.remove(
 
791
                'trivial_custom_prop_handler')
668
792
 
669
793
    def test_properties_handler_bad_argument(self):
670
 
        wt = self.make_standard_commit('bad_argument',
671
 
              revprops={'a_prop':'test_value'})
672
 
        sio = self.make_utf8_encoded_stringio()
 
794
        wt = self.make_branch_and_tree('.')
 
795
        b = wt.branch
 
796
        self.build_tree(['a'])
 
797
        wt.add('a')
 
798
        b.nick = 'test_author_log'
 
799
        wt.commit(message='add a',
 
800
                  timestamp=1132711707,
 
801
                  timezone=36000,
 
802
                  committer='Lorem Ipsum <test@example.com>',
 
803
                  authors=['John Doe <jdoe@example.com>'],
 
804
                  revprops={'a_prop':'test_value'})
 
805
        sio = StringIO()
673
806
        formatter = log.LongLogFormatter(to_file=sio)
674
 
        def bad_argument_prop_handler(revision):
675
 
            return {'custom_prop_name':revision.properties['a_prop']}
676
 
 
677
 
        log.properties_handler_registry.register(
678
 
            'bad_argument_prop_handler',
679
 
            bad_argument_prop_handler)
680
 
 
681
 
        self.assertRaises(AttributeError, formatter.show_properties,
682
 
                          'a revision', '')
683
 
 
684
 
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
685
 
        formatter.show_properties(revision, '')
686
 
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
687
 
                             sio.getvalue())
688
 
 
689
 
    def test_show_ids(self):
690
 
        wt = self.make_branch_and_tree('parent')
691
 
        self.build_tree(['parent/f1', 'parent/f2'])
692
 
        wt.add(['f1','f2'])
693
 
        self.wt_commit(wt, 'first post', rev_id='a')
694
 
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
695
 
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
696
 
        wt.merge_from_branch(child_wt.branch)
697
 
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
698
 
        self.assertFormatterResult("""\
699
 
------------------------------------------------------------
700
 
revno: 2 [merge]
701
 
revision-id: c
702
 
parent: a
703
 
parent: b
704
 
committer: Joe Foo <joe@foo.com>
705
 
branch nick: parent
706
 
timestamp: Tue 2005-11-22 00:00:02 +0000
707
 
message:
708
 
  merge branch 1
709
 
    ------------------------------------------------------------
710
 
    revno: 1.1.1
711
 
    revision-id: b
712
 
    parent: a
713
 
    committer: Joe Foo <joe@foo.com>
714
 
    branch nick: child
715
 
    timestamp: Tue 2005-11-22 00:00:01 +0000
716
 
    message:
717
 
      branch 1 changes
718
 
------------------------------------------------------------
719
 
revno: 1
720
 
revision-id: a
721
 
committer: Joe Foo <joe@foo.com>
722
 
branch nick: parent
723
 
timestamp: Tue 2005-11-22 00:00:00 +0000
724
 
message:
725
 
  first post
726
 
""",
727
 
            wt.branch, log.LongLogFormatter,
728
 
            formatter_kwargs=dict(levels=0,show_ids=True))
729
 
 
730
 
 
731
 
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
 
807
        try:
 
808
            def bad_argument_prop_handler(revision):
 
809
                return {'custom_prop_name':revision.properties['a_prop']}
 
810
 
 
811
            log.properties_handler_registry.register(
 
812
                'bad_argument_prop_handler',
 
813
                bad_argument_prop_handler)
 
814
 
 
815
            self.assertRaises(AttributeError, formatter.show_properties,
 
816
                              'a revision', '')
 
817
 
 
818
            revision = b.repository.get_revision(b.last_revision())
 
819
            formatter.show_properties(revision, '')
 
820
            self.assertEqualDiff('''custom_prop_name: test_value\n''',
 
821
                                 sio.getvalue())
 
822
        finally:
 
823
            log.properties_handler_registry.remove(
 
824
                'bad_argument_prop_handler')
 
825
 
 
826
 
 
827
class TestLongLogFormatterWithoutMergeRevisions(TestCaseWithoutPropsHandler):
732
828
 
733
829
    def test_long_verbose_log(self):
734
830
        """Verbose log includes changed files
735
831
 
736
832
        bug #4676
737
833
        """
738
 
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
739
 
        self.assertFormatterResult("""\
 
834
        wt = self.make_branch_and_tree('.')
 
835
        b = wt.branch
 
836
        self.build_tree(['a'])
 
837
        wt.add('a')
 
838
        # XXX: why does a longer nick show up?
 
839
        b.nick = 'test_verbose_log'
 
840
        wt.commit(message='add a',
 
841
                  timestamp=1132711707,
 
842
                  timezone=36000,
 
843
                  committer='Lorem Ipsum <test@example.com>')
 
844
        logfile = file('out.tmp', 'w+')
 
845
        formatter = log.LongLogFormatter(to_file=logfile, levels=1)
 
846
        log.show_log(b, formatter, verbose=True)
 
847
        logfile.flush()
 
848
        logfile.seek(0)
 
849
        log_contents = logfile.read()
 
850
        self.assertEqualDiff('''\
740
851
------------------------------------------------------------
741
852
revno: 1
742
853
committer: Lorem Ipsum <test@example.com>
743
 
branch nick: test_long_verbose_log
744
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
854
branch nick: test_verbose_log
 
855
timestamp: Wed 2005-11-23 12:08:27 +1000
745
856
message:
746
857
  add a
747
858
added:
748
859
  a
749
 
""",
750
 
            wt.branch, log.LongLogFormatter,
751
 
            formatter_kwargs=dict(levels=1),
752
 
            show_log_kwargs=dict(verbose=True))
 
860
''',
 
861
                             log_contents)
753
862
 
754
863
    def test_long_verbose_contain_deltas(self):
755
864
        wt = self.make_branch_and_tree('parent')
756
865
        self.build_tree(['parent/f1', 'parent/f2'])
757
866
        wt.add(['f1','f2'])
758
 
        self.wt_commit(wt, 'first post')
759
 
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
867
        wt.commit('first post')
 
868
        self.run_bzr('branch parent child')
760
869
        os.unlink('child/f1')
761
 
        self.build_tree_contents([('child/f2', 'hello\n')])
762
 
        self.wt_commit(child_wt, 'removed f1 and modified f2')
763
 
        wt.merge_from_branch(child_wt.branch)
764
 
        self.wt_commit(wt, 'merge branch 1')
765
 
        self.assertFormatterResult("""\
 
870
        file('child/f2', 'wb').write('hello\n')
 
871
        self.run_bzr(['commit', '-m', 'removed f1 and modified f2',
 
872
            'child'])
 
873
        os.chdir('parent')
 
874
        self.run_bzr('merge ../child')
 
875
        wt.commit('merge branch 1')
 
876
        b = wt.branch
 
877
        sio = self.make_utf8_encoded_stringio()
 
878
        lf = log.LongLogFormatter(to_file=sio, levels=1)
 
879
        log.show_log(b, lf, verbose=True)
 
880
        the_log = normalize_log(sio.getvalue())
 
881
        self.assertEqualDiff("""\
766
882
------------------------------------------------------------
767
883
revno: 2 [merge]
768
 
committer: Joe Foo <joe@foo.com>
 
884
committer: Lorem Ipsum <test@example.com>
769
885
branch nick: parent
770
 
timestamp: Tue 2005-11-22 00:00:02 +0000
 
886
timestamp: Just now
771
887
message:
772
888
  merge branch 1
773
889
removed:
776
892
  f2
777
893
------------------------------------------------------------
778
894
revno: 1
779
 
committer: Joe Foo <joe@foo.com>
 
895
committer: Lorem Ipsum <test@example.com>
780
896
branch nick: parent
781
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
897
timestamp: Just now
782
898
message:
783
899
  first post
784
900
added:
785
901
  f1
786
902
  f2
787
903
""",
788
 
            wt.branch, log.LongLogFormatter,
789
 
            formatter_kwargs=dict(levels=1),
790
 
            show_log_kwargs=dict(verbose=True))
 
904
                             the_log)
791
905
 
792
906
    def test_long_trailing_newlines(self):
793
907
        wt = self.make_branch_and_tree('.')
794
 
        b = self.make_commits_with_trailing_newlines(wt)
795
 
        self.assertFormatterResult("""\
 
908
        b = make_commits_with_trailing_newlines(wt)
 
909
        sio = self.make_utf8_encoded_stringio()
 
910
        lf = log.LongLogFormatter(to_file=sio, levels=1)
 
911
        log.show_log(b, lf)
 
912
        self.assertEqualDiff("""\
796
913
------------------------------------------------------------
797
914
revno: 3
798
915
committer: Joe Foo <joe@foo.com>
799
916
branch nick: test
800
 
timestamp: Tue 2005-11-22 00:00:02 +0000
 
917
timestamp: Mon 2005-11-21 09:32:56 -0600
801
918
message:
802
919
  single line with trailing newline
803
920
------------------------------------------------------------
804
921
revno: 2
 
922
author: Joe Bar <joe@bar.com>
805
923
committer: Joe Foo <joe@foo.com>
806
924
branch nick: test
807
 
timestamp: Tue 2005-11-22 00:00:01 +0000
 
925
timestamp: Mon 2005-11-21 09:27:22 -0600
808
926
message:
809
927
  multiline
810
928
  log
813
931
revno: 1
814
932
committer: Joe Foo <joe@foo.com>
815
933
branch nick: test
816
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
934
timestamp: Mon 2005-11-21 09:24:15 -0600
817
935
message:
818
936
  simple log message
819
937
""",
820
 
        b, log.LongLogFormatter,
821
 
        formatter_kwargs=dict(levels=1))
 
938
                             sio.getvalue())
822
939
 
823
940
    def test_long_author_in_log(self):
824
941
        """Log includes the author name if it's set in
825
942
        the revision properties
826
943
        """
827
 
        wt = self.make_standard_commit('test_author_log')
828
 
        self.assertFormatterResult("""\
 
944
        wt = self.make_branch_and_tree('.')
 
945
        b = wt.branch
 
946
        self.build_tree(['a'])
 
947
        wt.add('a')
 
948
        b.nick = 'test_author_log'
 
949
        wt.commit(message='add a',
 
950
                  timestamp=1132711707,
 
951
                  timezone=36000,
 
952
                  committer='Lorem Ipsum <test@example.com>',
 
953
                  authors=['John Doe <jdoe@example.com>'])
 
954
        sio = StringIO()
 
955
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
 
956
        log.show_log(b, formatter)
 
957
        self.assertEqualDiff('''\
829
958
------------------------------------------------------------
830
959
revno: 1
831
960
author: John Doe <jdoe@example.com>
832
961
committer: Lorem Ipsum <test@example.com>
833
962
branch nick: test_author_log
834
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
963
timestamp: Wed 2005-11-23 12:08:27 +1000
835
964
message:
836
965
  add a
837
 
""",
838
 
            wt.branch, log.LongLogFormatter,
839
 
            formatter_kwargs=dict(levels=1))
 
966
''',
 
967
                             sio.getvalue())
840
968
 
841
969
    def test_long_properties_in_log(self):
842
970
        """Log includes the custom properties returned by the registered
843
971
        handlers.
844
972
        """
845
 
        wt = self.make_standard_commit('test_properties_in_log')
846
 
        def trivial_custom_prop_handler(revision):
847
 
            return {'test_prop':'test_value'}
 
973
        wt = self.make_branch_and_tree('.')
 
974
        b = wt.branch
 
975
        self.build_tree(['a'])
 
976
        wt.add('a')
 
977
        b.nick = 'test_properties_in_log'
 
978
        wt.commit(message='add a',
 
979
                  timestamp=1132711707,
 
980
                  timezone=36000,
 
981
                  committer='Lorem Ipsum <test@example.com>',
 
982
                  authors=['John Doe <jdoe@example.com>'])
 
983
        sio = StringIO()
 
984
        formatter = log.LongLogFormatter(to_file=sio, levels=1)
 
985
        try:
 
986
            def trivial_custom_prop_handler(revision):
 
987
                return {'test_prop':'test_value'}
848
988
 
849
 
        log.properties_handler_registry.register(
850
 
            'trivial_custom_prop_handler',
851
 
            trivial_custom_prop_handler)
852
 
        self.assertFormatterResult("""\
 
989
            log.properties_handler_registry.register(
 
990
                'trivial_custom_prop_handler',
 
991
                trivial_custom_prop_handler)
 
992
            log.show_log(b, formatter)
 
993
        finally:
 
994
            log.properties_handler_registry.remove(
 
995
                'trivial_custom_prop_handler')
 
996
            self.assertEqualDiff('''\
853
997
------------------------------------------------------------
854
998
revno: 1
855
999
test_prop: test_value
856
1000
author: John Doe <jdoe@example.com>
857
1001
committer: Lorem Ipsum <test@example.com>
858
1002
branch nick: test_properties_in_log
859
 
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1003
timestamp: Wed 2005-11-23 12:08:27 +1000
860
1004
message:
861
1005
  add a
862
 
""",
863
 
            wt.branch, log.LongLogFormatter,
864
 
            formatter_kwargs=dict(levels=1))
865
 
 
866
 
 
867
 
class TestLineLogFormatter(TestCaseForLogFormatter):
 
1006
''',
 
1007
                                 sio.getvalue())
 
1008
 
 
1009
 
 
1010
class TestLineLogFormatter(tests.TestCaseWithTransport):
868
1011
 
869
1012
    def test_line_log(self):
870
1013
        """Line log should show revno
871
1014
 
872
1015
        bug #5162
873
1016
        """
874
 
        wt = self.make_standard_commit('test-line-log',
875
 
                committer='Line-Log-Formatter Tester <test@line.log>',
876
 
                authors=[])
877
 
        self.assertFormatterResult("""\
878
 
1: Line-Log-Formatte... 2005-11-22 add a
879
 
""",
880
 
            wt.branch, log.LineLogFormatter)
 
1017
        wt = self.make_branch_and_tree('.')
 
1018
        b = wt.branch
 
1019
        self.build_tree(['a'])
 
1020
        wt.add('a')
 
1021
        b.nick = 'test-line-log'
 
1022
        wt.commit(message='add a',
 
1023
                  timestamp=1132711707,
 
1024
                  timezone=36000,
 
1025
                  committer='Line-Log-Formatter Tester <test@line.log>')
 
1026
        logfile = file('out.tmp', 'w+')
 
1027
        formatter = log.LineLogFormatter(to_file=logfile)
 
1028
        log.show_log(b, formatter)
 
1029
        logfile.flush()
 
1030
        logfile.seek(0)
 
1031
        log_contents = logfile.read()
 
1032
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
 
1033
                             log_contents)
881
1034
 
882
1035
    def test_trailing_newlines(self):
883
1036
        wt = self.make_branch_and_tree('.')
884
 
        b = self.make_commits_with_trailing_newlines(wt)
885
 
        self.assertFormatterResult("""\
886
 
3: Joe Foo 2005-11-22 single line with trailing newline
887
 
2: Joe Foo 2005-11-22 multiline
888
 
1: Joe Foo 2005-11-22 simple log message
 
1037
        b = make_commits_with_trailing_newlines(wt)
 
1038
        sio = self.make_utf8_encoded_stringio()
 
1039
        lf = log.LineLogFormatter(to_file=sio)
 
1040
        log.show_log(b, lf)
 
1041
        self.assertEqualDiff("""\
 
1042
3: Joe Foo 2005-11-21 single line with trailing newline
 
1043
2: Joe Bar 2005-11-21 multiline
 
1044
1: Joe Foo 2005-11-21 simple log message
889
1045
""",
890
 
            b, log.LineLogFormatter)
 
1046
                             sio.getvalue())
 
1047
 
 
1048
    def _prepare_tree_with_merges(self, with_tags=False):
 
1049
        wt = self.make_branch_and_memory_tree('.')
 
1050
        wt.lock_write()
 
1051
        self.addCleanup(wt.unlock)
 
1052
        wt.add('')
 
1053
        wt.commit('rev-1', rev_id='rev-1',
 
1054
                  timestamp=1132586655, timezone=36000,
 
1055
                  committer='Joe Foo <joe@foo.com>')
 
1056
        wt.commit('rev-merged', rev_id='rev-2a',
 
1057
                  timestamp=1132586700, timezone=36000,
 
1058
                  committer='Joe Foo <joe@foo.com>')
 
1059
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
1060
        wt.branch.set_last_revision_info(1, 'rev-1')
 
1061
        wt.commit('rev-2', rev_id='rev-2b',
 
1062
                  timestamp=1132586800, timezone=36000,
 
1063
                  committer='Joe Foo <joe@foo.com>')
 
1064
        if with_tags:
 
1065
            branch = wt.branch
 
1066
            branch.tags.set_tag('v0.2', 'rev-2b')
 
1067
            wt.commit('rev-3', rev_id='rev-3',
 
1068
                      timestamp=1132586900, timezone=36000,
 
1069
                      committer='Jane Foo <jane@foo.com>')
 
1070
            branch.tags.set_tag('v1.0rc1', 'rev-3')
 
1071
            branch.tags.set_tag('v1.0', 'rev-3')
 
1072
        return wt
891
1073
 
892
1074
    def test_line_log_single_merge_revision(self):
893
1075
        wt = self._prepare_tree_with_merges()
 
1076
        logfile = self.make_utf8_encoded_stringio()
 
1077
        formatter = log.LineLogFormatter(to_file=logfile)
894
1078
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
895
 
        rev = revspec.in_history(wt.branch)
896
 
        self.assertFormatterResult("""\
 
1079
        wtb = wt.branch
 
1080
        rev = revspec.in_history(wtb)
 
1081
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
1082
        self.assertEqualDiff("""\
897
1083
1.1.1: Joe Foo 2005-11-22 rev-merged
898
1084
""",
899
 
            wt.branch, log.LineLogFormatter,
900
 
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
1085
                             logfile.getvalue())
901
1086
 
902
1087
    def test_line_log_with_tags(self):
903
1088
        wt = self._prepare_tree_with_merges(with_tags=True)
904
 
        self.assertFormatterResult("""\
905
 
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
 
1089
        logfile = self.make_utf8_encoded_stringio()
 
1090
        formatter = log.LineLogFormatter(to_file=logfile)
 
1091
        log.show_log(wt.branch, formatter)
 
1092
        self.assertEqualDiff("""\
 
1093
3: Jane Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
906
1094
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
907
1095
1: Joe Foo 2005-11-22 rev-1
908
1096
""",
909
 
            wt.branch, log.LineLogFormatter)
910
 
 
911
 
 
912
 
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
 
1097
                             logfile.getvalue())
 
1098
 
 
1099
class TestLineLogFormatterWithMergeRevisions(tests.TestCaseWithTransport):
913
1100
 
914
1101
    def test_line_merge_revs_log(self):
915
1102
        """Line log should show revno
916
1103
 
917
1104
        bug #5162
918
1105
        """
919
 
        wt = self.make_standard_commit('test-line-log',
920
 
                committer='Line-Log-Formatter Tester <test@line.log>',
921
 
                authors=[])
922
 
        self.assertFormatterResult("""\
923
 
1: Line-Log-Formatte... 2005-11-22 add a
924
 
""",
925
 
            wt.branch, log.LineLogFormatter)
 
1106
        wt = self.make_branch_and_tree('.')
 
1107
        b = wt.branch
 
1108
        self.build_tree(['a'])
 
1109
        wt.add('a')
 
1110
        b.nick = 'test-line-log'
 
1111
        wt.commit(message='add a',
 
1112
                  timestamp=1132711707,
 
1113
                  timezone=36000,
 
1114
                  committer='Line-Log-Formatter Tester <test@line.log>')
 
1115
        logfile = file('out.tmp', 'w+')
 
1116
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
1117
        log.show_log(b, formatter)
 
1118
        logfile.flush()
 
1119
        logfile.seek(0)
 
1120
        log_contents = logfile.read()
 
1121
        self.assertEqualDiff('1: Line-Log-Formatte... 2005-11-23 add a\n',
 
1122
                             log_contents)
926
1123
 
927
1124
    def test_line_merge_revs_log_single_merge_revision(self):
928
 
        wt = self._prepare_tree_with_merges()
 
1125
        wt = self.make_branch_and_memory_tree('.')
 
1126
        wt.lock_write()
 
1127
        self.addCleanup(wt.unlock)
 
1128
        wt.add('')
 
1129
        wt.commit('rev-1', rev_id='rev-1',
 
1130
                  timestamp=1132586655, timezone=36000,
 
1131
                  committer='Joe Foo <joe@foo.com>')
 
1132
        wt.commit('rev-merged', rev_id='rev-2a',
 
1133
                  timestamp=1132586700, timezone=36000,
 
1134
                  committer='Joe Foo <joe@foo.com>')
 
1135
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
1136
        wt.branch.set_last_revision_info(1, 'rev-1')
 
1137
        wt.commit('rev-2', rev_id='rev-2b',
 
1138
                  timestamp=1132586800, timezone=36000,
 
1139
                  committer='Joe Foo <joe@foo.com>')
 
1140
        logfile = self.make_utf8_encoded_stringio()
 
1141
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
929
1142
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
930
 
        rev = revspec.in_history(wt.branch)
931
 
        self.assertFormatterResult("""\
 
1143
        wtb = wt.branch
 
1144
        rev = revspec.in_history(wtb)
 
1145
        log.show_log(wtb, formatter, start_revision=rev, end_revision=rev)
 
1146
        self.assertEqualDiff("""\
932
1147
1.1.1: Joe Foo 2005-11-22 rev-merged
933
1148
""",
934
 
            wt.branch, log.LineLogFormatter,
935
 
            formatter_kwargs=dict(levels=0),
936
 
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
 
1149
                             logfile.getvalue())
937
1150
 
938
1151
    def test_line_merge_revs_log_with_merges(self):
939
 
        wt = self._prepare_tree_with_merges()
940
 
        self.assertFormatterResult("""\
 
1152
        wt = self.make_branch_and_memory_tree('.')
 
1153
        wt.lock_write()
 
1154
        self.addCleanup(wt.unlock)
 
1155
        wt.add('')
 
1156
        wt.commit('rev-1', rev_id='rev-1',
 
1157
                  timestamp=1132586655, timezone=36000,
 
1158
                  committer='Joe Foo <joe@foo.com>')
 
1159
        wt.commit('rev-merged', rev_id='rev-2a',
 
1160
                  timestamp=1132586700, timezone=36000,
 
1161
                  committer='Joe Foo <joe@foo.com>')
 
1162
        wt.set_parent_ids(['rev-1', 'rev-2a'])
 
1163
        wt.branch.set_last_revision_info(1, 'rev-1')
 
1164
        wt.commit('rev-2', rev_id='rev-2b',
 
1165
                  timestamp=1132586800, timezone=36000,
 
1166
                  committer='Joe Foo <joe@foo.com>')
 
1167
        logfile = self.make_utf8_encoded_stringio()
 
1168
        formatter = log.LineLogFormatter(to_file=logfile, levels=0)
 
1169
        log.show_log(wt.branch, formatter)
 
1170
        self.assertEqualDiff("""\
941
1171
2: Joe Foo 2005-11-22 [merge] rev-2
942
1172
  1.1.1: Joe Foo 2005-11-22 rev-merged
943
1173
1: Joe Foo 2005-11-22 rev-1
944
1174
""",
945
 
            wt.branch, log.LineLogFormatter,
946
 
            formatter_kwargs=dict(levels=0))
947
 
 
948
 
 
949
 
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
950
 
 
951
 
    def test_gnu_changelog(self):
952
 
        wt = self.make_standard_commit('nicky', authors=[])
953
 
        self.assertFormatterResult('''\
954
 
2005-11-22  Lorem Ipsum  <test@example.com>
955
 
 
956
 
\tadd a
957
 
 
958
 
''',
959
 
            wt.branch, log.GnuChangelogLogFormatter)
960
 
 
961
 
    def test_with_authors(self):
962
 
        wt = self.make_standard_commit('nicky',
963
 
            authors=['Fooa Fooz <foo@example.com>',
964
 
                     'Bari Baro <bar@example.com>'])
965
 
        self.assertFormatterResult('''\
966
 
2005-11-22  Fooa Fooz  <foo@example.com>
967
 
 
968
 
\tadd a
969
 
 
970
 
''',
971
 
            wt.branch, log.GnuChangelogLogFormatter)
972
 
 
973
 
    def test_verbose(self):
974
 
        wt = self.make_standard_commit('nicky')
975
 
        self.assertFormatterResult('''\
976
 
2005-11-22  John Doe  <jdoe@example.com>
977
 
 
978
 
\t* a:
979
 
 
980
 
\tadd a
981
 
 
982
 
''',
983
 
            wt.branch, log.GnuChangelogLogFormatter,
984
 
            show_log_kwargs=dict(verbose=True))
985
 
 
986
 
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
987
 
 
988
 
    def _get_view_revisions(self, *args, **kwargs):
989
 
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
990
 
                                    log.get_view_revisions, *args, **kwargs)
 
1175
                             logfile.getvalue())
 
1176
 
 
1177
class TestGetViewRevisions(tests.TestCaseWithTransport):
991
1178
 
992
1179
    def make_tree_with_commits(self):
993
1180
        """Create a tree with well-known revision ids"""
994
1181
        wt = self.make_branch_and_tree('tree1')
995
 
        self.wt_commit(wt, 'commit one', rev_id='1')
996
 
        self.wt_commit(wt, 'commit two', rev_id='2')
997
 
        self.wt_commit(wt, 'commit three', rev_id='3')
 
1182
        wt.commit('commit one', rev_id='1')
 
1183
        wt.commit('commit two', rev_id='2')
 
1184
        wt.commit('commit three', rev_id='3')
998
1185
        mainline_revs = [None, '1', '2', '3']
999
1186
        rev_nos = {'1': 1, '2': 2, '3': 3}
1000
1187
        return mainline_revs, rev_nos, wt
1003
1190
        """Create a tree with well-known revision ids and a merge"""
1004
1191
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1005
1192
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
1006
 
        self.wt_commit(tree2, 'four-a', rev_id='4a')
 
1193
        tree2.commit('four-a', rev_id='4a')
1007
1194
        wt.merge_from_branch(tree2.branch)
1008
 
        self.wt_commit(wt, 'four-b', rev_id='4b')
 
1195
        wt.commit('four-b', rev_id='4b')
1009
1196
        mainline_revs.append('4b')
1010
1197
        rev_nos['4b'] = 4
1011
1198
        # 4a: 3.1.1
1012
1199
        return mainline_revs, rev_nos, wt
1013
1200
 
1014
 
    def make_branch_with_many_merges(self):
 
1201
    def make_tree_with_many_merges(self):
1015
1202
        """Create a tree with well-known revision ids"""
1016
 
        builder = self.make_branch_builder('tree1')
1017
 
        builder.start_series()
1018
 
        builder.build_snapshot('1', None, [
1019
 
            ('add', ('', 'TREE_ROOT', 'directory', '')),
1020
 
            ('add', ('f', 'f-id', 'file', '1\n'))])
1021
 
        builder.build_snapshot('2', ['1'], [])
1022
 
        builder.build_snapshot('3a', ['2'], [
1023
 
            ('modify', ('f-id', '1\n2\n3a\n'))])
1024
 
        builder.build_snapshot('3b', ['2', '3a'], [
1025
 
            ('modify', ('f-id', '1\n2\n3a\n'))])
1026
 
        builder.build_snapshot('3c', ['2', '3b'], [
1027
 
            ('modify', ('f-id', '1\n2\n3a\n'))])
1028
 
        builder.build_snapshot('4a', ['3b'], [])
1029
 
        builder.build_snapshot('4b', ['3c', '4a'], [])
1030
 
        builder.finish_series()
1031
 
 
1032
 
        # 1
1033
 
        # |
1034
 
        # 2-.
1035
 
        # |\ \
1036
 
        # | | 3a
1037
 
        # | |/
1038
 
        # | 3b
1039
 
        # |/|
1040
 
        # 3c4a
1041
 
        # |/
1042
 
        # 4b
 
1203
        wt = self.make_branch_and_tree('tree1')
 
1204
        self.build_tree_contents([('tree1/f', '1\n')])
 
1205
        wt.add(['f'], ['f-id'])
 
1206
        wt.commit('commit one', rev_id='1')
 
1207
        wt.commit('commit two', rev_id='2')
 
1208
 
 
1209
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
1210
        self.build_tree_contents([('tree3/f', '1\n2\n3a\n')])
 
1211
        tree3.commit('commit three a', rev_id='3a')
 
1212
 
 
1213
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
 
1214
        tree2.merge_from_branch(tree3.branch)
 
1215
        tree2.commit('commit three b', rev_id='3b')
 
1216
 
 
1217
        wt.merge_from_branch(tree2.branch)
 
1218
        wt.commit('commit three c', rev_id='3c')
 
1219
        tree2.commit('four-a', rev_id='4a')
 
1220
 
 
1221
        wt.merge_from_branch(tree2.branch)
 
1222
        wt.commit('four-b', rev_id='4b')
1043
1223
 
1044
1224
        mainline_revs = [None, '1', '2', '3c', '4b']
1045
1225
        rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
1052
1232
            '4a': '2.2.2', # second commit tree 2
1053
1233
            '4b': '4', # merges 4a to main
1054
1234
            }
1055
 
        return mainline_revs, rev_nos, builder.get_branch()
 
1235
        return mainline_revs, rev_nos, wt
1056
1236
 
1057
1237
    def test_get_view_revisions_forward(self):
1058
1238
        """Test the get_view_revisions method"""
1059
1239
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1060
1240
        wt.lock_read()
1061
1241
        self.addCleanup(wt.unlock)
1062
 
        revisions = list(self._get_view_revisions(
 
1242
        revisions = list(log.get_view_revisions(
1063
1243
                mainline_revs, rev_nos, wt.branch, 'forward'))
1064
1244
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
1065
1245
                         revisions)
1066
 
        revisions2 = list(self._get_view_revisions(
 
1246
        revisions2 = list(log.get_view_revisions(
1067
1247
                mainline_revs, rev_nos, wt.branch, 'forward',
1068
1248
                include_merges=False))
1069
1249
        self.assertEqual(revisions, revisions2)
1073
1253
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1074
1254
        wt.lock_read()
1075
1255
        self.addCleanup(wt.unlock)
1076
 
        revisions = list(self._get_view_revisions(
 
1256
        revisions = list(log.get_view_revisions(
1077
1257
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1078
1258
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1079
1259
                         revisions)
1080
 
        revisions2 = list(self._get_view_revisions(
 
1260
        revisions2 = list(log.get_view_revisions(
1081
1261
                mainline_revs, rev_nos, wt.branch, 'reverse',
1082
1262
                include_merges=False))
1083
1263
        self.assertEqual(revisions, revisions2)
1087
1267
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1088
1268
        wt.lock_read()
1089
1269
        self.addCleanup(wt.unlock)
1090
 
        revisions = list(self._get_view_revisions(
 
1270
        revisions = list(log.get_view_revisions(
1091
1271
                mainline_revs, rev_nos, wt.branch, 'forward'))
1092
1272
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1093
1273
                          ('4b', '4', 0), ('4a', '3.1.1', 1)],
1094
1274
                         revisions)
1095
 
        revisions = list(self._get_view_revisions(
 
1275
        revisions = list(log.get_view_revisions(
1096
1276
                mainline_revs, rev_nos, wt.branch, 'forward',
1097
1277
                include_merges=False))
1098
1278
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1104
1284
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1105
1285
        wt.lock_read()
1106
1286
        self.addCleanup(wt.unlock)
1107
 
        revisions = list(self._get_view_revisions(
 
1287
        revisions = list(log.get_view_revisions(
1108
1288
                mainline_revs, rev_nos, wt.branch, 'reverse'))
1109
1289
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1110
1290
                          ('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1111
1291
                         revisions)
1112
 
        revisions = list(self._get_view_revisions(
 
1292
        revisions = list(log.get_view_revisions(
1113
1293
                mainline_revs, rev_nos, wt.branch, 'reverse',
1114
1294
                include_merges=False))
1115
1295
        self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1118
1298
 
1119
1299
    def test_get_view_revisions_merge2(self):
1120
1300
        """Test get_view_revisions when there are merges"""
1121
 
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1122
 
        b.lock_read()
1123
 
        self.addCleanup(b.unlock)
1124
 
        revisions = list(self._get_view_revisions(
1125
 
                mainline_revs, rev_nos, b, 'forward'))
 
1301
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
 
1302
        wt.lock_read()
 
1303
        self.addCleanup(wt.unlock)
 
1304
        revisions = list(log.get_view_revisions(
 
1305
                mainline_revs, rev_nos, wt.branch, 'forward'))
1126
1306
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1127
 
                    ('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
 
1307
                    ('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
1128
1308
                    ('4a', '2.2.2', 1)]
1129
1309
        self.assertEqual(expected, revisions)
1130
 
        revisions = list(self._get_view_revisions(
1131
 
                mainline_revs, rev_nos, b, 'forward',
 
1310
        revisions = list(log.get_view_revisions(
 
1311
                mainline_revs, rev_nos, wt.branch, 'forward',
1132
1312
                include_merges=False))
1133
1313
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1134
1314
                          ('4b', '4', 0)],
1135
1315
                         revisions)
1136
1316
 
 
1317
 
1137
1318
    def test_file_id_for_range(self):
1138
 
        mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1139
 
        b.lock_read()
1140
 
        self.addCleanup(b.unlock)
 
1319
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
 
1320
        wt.lock_read()
 
1321
        self.addCleanup(wt.unlock)
1141
1322
 
1142
1323
        def rev_from_rev_id(revid, branch):
1143
1324
            revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1144
1325
            return revspec.in_history(branch)
1145
1326
 
1146
1327
        def view_revs(start_rev, end_rev, file_id, direction):
1147
 
            revs = self.applyDeprecated(
1148
 
                symbol_versioning.deprecated_in((2, 2, 0)),
1149
 
                log.calculate_view_revisions,
1150
 
                b,
 
1328
            revs = log.calculate_view_revisions(
 
1329
                wt.branch,
1151
1330
                start_rev, # start_revision
1152
1331
                end_rev, # end_revision
1153
1332
                direction, # direction
1156
1335
                )
1157
1336
            return revs
1158
1337
 
1159
 
        rev_3a = rev_from_rev_id('3a', b)
1160
 
        rev_4b = rev_from_rev_id('4b', b)
1161
 
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1162
 
                          ('3a', '2.1.1', 2)],
 
1338
        rev_3a = rev_from_rev_id('3a', wt.branch)
 
1339
        rev_4b = rev_from_rev_id('4b', wt.branch)
 
1340
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
1163
1341
                          view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1164
1342
        # Note: 3c still appears before 3a here because of depth-based sorting
1165
 
        self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1166
 
                          ('3a', '2.1.1', 2)],
 
1343
        self.assertEqual([('3c', '3', 0), ('3a', '2.1.1', 1)],
1167
1344
                          view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1168
1345
 
1169
1346
 
1170
1347
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1171
1348
 
1172
 
    def get_view_revisions(self, *args):
1173
 
        return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1174
 
                                    log.get_view_revisions, *args)
1175
 
 
1176
1349
    def create_tree_with_single_merge(self):
1177
1350
        """Create a branch with a moderate layout.
1178
1351
 
1196
1369
        #       use it. Since 'log' only uses the tree in a readonly
1197
1370
        #       fashion, it seems a shame to regenerate an identical
1198
1371
        #       tree for each test.
1199
 
        # TODO: vila 20100122 One way to address the shame above will be to
1200
 
        #       create a memory tree during test parametrization and give a
1201
 
        #       *copy* of this tree to each test. Copying a memory tree ought
1202
 
        #       to be cheap, at least cheaper than creating them with such
1203
 
        #       complex setups.
1204
1372
        tree = self.make_branch_and_tree('tree')
1205
1373
        tree.lock_write()
1206
1374
        self.addCleanup(tree.unlock)
1281
1449
        mainline = tree.branch.revision_history()
1282
1450
        mainline.insert(0, None)
1283
1451
        revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1284
 
        view_revs_iter = self.get_view_revisions(
1285
 
            mainline, revnos, tree.branch, 'reverse', True)
 
1452
        view_revs_iter = log.get_view_revisions(mainline, revnos, tree.branch,
 
1453
                                                'reverse', True)
1286
1454
        actual_revs = log._filter_revisions_touching_file_id(
1287
 
            tree.branch, file_id, list(view_revs_iter))
 
1455
                            tree.branch,
 
1456
                            file_id,
 
1457
                            list(view_revs_iter))
1288
1458
        self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1289
1459
 
1290
1460
    def test_file_id_f1(self):
1342
1512
 
1343
1513
class TestLogFormatter(tests.TestCase):
1344
1514
 
1345
 
    def setUp(self):
1346
 
        super(TestLogFormatter, self).setUp()
1347
 
        self.rev = revision.Revision('a-id')
1348
 
        self.lf = log.LogFormatter(None)
1349
 
 
1350
1515
    def test_short_committer(self):
1351
 
        def assertCommitter(expected, committer):
1352
 
            self.rev.committer = committer
1353
 
            self.assertEqual(expected, self.lf.short_committer(self.rev))
1354
 
 
1355
 
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1356
 
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1357
 
        assertCommitter('John Smith', 'John Smith')
1358
 
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
1359
 
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1360
 
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
 
1516
        rev = revision.Revision('a-id')
 
1517
        rev.committer = 'John Doe <jdoe@example.com>'
 
1518
        lf = log.LogFormatter(None)
 
1519
        self.assertEqual('John Doe', lf.short_committer(rev))
 
1520
        rev.committer = 'John Smith <jsmith@example.com>'
 
1521
        self.assertEqual('John Smith', lf.short_committer(rev))
 
1522
        rev.committer = 'John Smith'
 
1523
        self.assertEqual('John Smith', lf.short_committer(rev))
 
1524
        rev.committer = 'jsmith@example.com'
 
1525
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
 
1526
        rev.committer = '<jsmith@example.com>'
 
1527
        self.assertEqual('jsmith@example.com', lf.short_committer(rev))
 
1528
        rev.committer = 'John Smith jsmith@example.com'
 
1529
        self.assertEqual('John Smith', lf.short_committer(rev))
1361
1530
 
1362
1531
    def test_short_author(self):
1363
 
        def assertAuthor(expected, author):
1364
 
            self.rev.properties['author'] = author
1365
 
            self.assertEqual(expected, self.lf.short_author(self.rev))
1366
 
 
1367
 
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1368
 
        assertAuthor('John Smith', 'John Smith')
1369
 
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
1370
 
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1371
 
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
1372
 
 
1373
 
    def test_short_author_from_committer(self):
1374
 
        self.rev.committer = 'John Doe <jdoe@example.com>'
1375
 
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
1376
 
 
1377
 
    def test_short_author_from_authors(self):
1378
 
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1379
 
                                          'Jane Rey <jrey@example.com>')
1380
 
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
 
1532
        rev = revision.Revision('a-id')
 
1533
        rev.committer = 'John Doe <jdoe@example.com>'
 
1534
        lf = log.LogFormatter(None)
 
1535
        self.assertEqual('John Doe', lf.short_author(rev))
 
1536
        rev.properties['author'] = 'John Smith <jsmith@example.com>'
 
1537
        self.assertEqual('John Smith', lf.short_author(rev))
 
1538
        rev.properties['author'] = 'John Smith'
 
1539
        self.assertEqual('John Smith', lf.short_author(rev))
 
1540
        rev.properties['author'] = 'jsmith@example.com'
 
1541
        self.assertEqual('jsmith@example.com', 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'] = 'John Smith jsmith@example.com'
 
1545
        self.assertEqual('John Smith', lf.short_author(rev))
 
1546
        del rev.properties['author']
 
1547
        rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
 
1548
                'Jane Rey <jrey@example.com>')
 
1549
        self.assertEqual('John Smith', lf.short_author(rev))
1381
1550
 
1382
1551
 
1383
1552
class TestReverseByDepth(tests.TestCase):
1529
1698
        log.show_branch_change(tree.branch, s, 3, '3b')
1530
1699
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1531
1700
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1532
 
 
1533
 
 
1534
 
class TestRevisionNotInBranch(TestCaseForLogFormatter):
1535
 
 
1536
 
    def setup_a_tree(self):
1537
 
        tree = self.make_branch_and_tree('tree')
1538
 
        tree.lock_write()
1539
 
        self.addCleanup(tree.unlock)
1540
 
        kwargs = {
1541
 
            'committer': 'Joe Foo <joe@foo.com>',
1542
 
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1543
 
            'timezone': 0, # UTC
1544
 
        }
1545
 
        tree.commit('commit 1a', rev_id='1a', **kwargs)
1546
 
        tree.commit('commit 2a', rev_id='2a', **kwargs)
1547
 
        tree.commit('commit 3a', rev_id='3a', **kwargs)
1548
 
        return tree
1549
 
 
1550
 
    def setup_ab_tree(self):
1551
 
        tree = self.setup_a_tree()
1552
 
        tree.set_last_revision('1a')
1553
 
        tree.branch.set_last_revision_info(1, '1a')
1554
 
        kwargs = {
1555
 
            'committer': 'Joe Foo <joe@foo.com>',
1556
 
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1557
 
            'timezone': 0, # UTC
1558
 
        }
1559
 
        tree.commit('commit 2b', rev_id='2b', **kwargs)
1560
 
        tree.commit('commit 3b', rev_id='3b', **kwargs)
1561
 
        return tree
1562
 
 
1563
 
    def test_one_revision(self):
1564
 
        tree = self.setup_ab_tree()
1565
 
        lf = LogCatcher()
1566
 
        rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1567
 
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1568
 
                     end_revision=rev)
1569
 
        self.assertEqual(1, len(lf.revisions))
1570
 
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1571
 
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1572
 
 
1573
 
    def test_many_revisions(self):
1574
 
        tree = self.setup_ab_tree()
1575
 
        lf = LogCatcher()
1576
 
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1577
 
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1578
 
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1579
 
                     end_revision=end_rev)
1580
 
        self.assertEqual(3, len(lf.revisions))
1581
 
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1582
 
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1583
 
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
1584
 
        self.assertEqual('2a', lf.revisions[1].rev.revision_id)
1585
 
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
1586
 
 
1587
 
    def test_long_format(self):
1588
 
        tree = self.setup_ab_tree()
1589
 
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1590
 
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1591
 
        self.assertFormatterResult("""\
1592
 
------------------------------------------------------------
1593
 
revision-id: 3a
1594
 
committer: Joe Foo <joe@foo.com>
1595
 
branch nick: tree
1596
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1597
 
message:
1598
 
  commit 3a
1599
 
------------------------------------------------------------
1600
 
revision-id: 2a
1601
 
committer: Joe Foo <joe@foo.com>
1602
 
branch nick: tree
1603
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1604
 
message:
1605
 
  commit 2a
1606
 
------------------------------------------------------------
1607
 
revno: 1
1608
 
committer: Joe Foo <joe@foo.com>
1609
 
branch nick: tree
1610
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1611
 
message:
1612
 
  commit 1a
1613
 
""",
1614
 
            tree.branch, log.LongLogFormatter, show_log_kwargs={
1615
 
                'start_revision': start_rev, 'end_revision': end_rev
1616
 
            })
1617
 
 
1618
 
    def test_short_format(self):
1619
 
        tree = self.setup_ab_tree()
1620
 
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1621
 
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1622
 
        self.assertFormatterResult("""\
1623
 
      Joe Foo\t2005-11-22
1624
 
      revision-id:3a
1625
 
      commit 3a
1626
 
 
1627
 
      Joe Foo\t2005-11-22
1628
 
      revision-id:2a
1629
 
      commit 2a
1630
 
 
1631
 
    1 Joe Foo\t2005-11-22
1632
 
      commit 1a
1633
 
 
1634
 
""",
1635
 
            tree.branch, log.ShortLogFormatter, show_log_kwargs={
1636
 
                'start_revision': start_rev, 'end_revision': end_rev
1637
 
            })
1638
 
 
1639
 
    def test_line_format(self):
1640
 
        tree = self.setup_ab_tree()
1641
 
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1642
 
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1643
 
        self.assertFormatterResult("""\
1644
 
Joe Foo 2005-11-22 commit 3a
1645
 
Joe Foo 2005-11-22 commit 2a
1646
 
1: Joe Foo 2005-11-22 commit 1a
1647
 
""",
1648
 
            tree.branch, log.LineLogFormatter, show_log_kwargs={
1649
 
                'start_revision': start_rev, 'end_revision': end_rev
1650
 
            })
1651
 
 
1652
 
 
1653
 
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1654
 
 
1655
 
    def setUp(self):
1656
 
        TestCaseForLogFormatter.setUp(self)
1657
 
        log.properties_handler_registry.register(
1658
 
            'bugs_properties_handler',
1659
 
            log._bugs_properties_handler)
1660
 
 
1661
 
    def make_commits_with_bugs(self):
1662
 
        """Helper method for LogFormatter tests"""
1663
 
        tree = self.make_branch_and_tree(u'.')
1664
 
        self.build_tree(['a', 'b'])
1665
 
        tree.add('a')
1666
 
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1667
 
                       revprops={'bugs': 'test://bug/id fixed'})
1668
 
        tree.add('b')
1669
 
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1670
 
                       authors=['Joe Bar <joe@bar.com>'],
1671
 
                       revprops={'bugs': 'test://bug/id fixed\n'
1672
 
                                 'test://bug/2 fixed'})
1673
 
        return tree
1674
 
 
1675
 
 
1676
 
    def test_long_bugs(self):
1677
 
        tree = self.make_commits_with_bugs()
1678
 
        self.assertFormatterResult("""\
1679
 
------------------------------------------------------------
1680
 
revno: 2
1681
 
fixes bug(s): test://bug/id test://bug/2
1682
 
author: Joe Bar <joe@bar.com>
1683
 
committer: Joe Foo <joe@foo.com>
1684
 
branch nick: work
1685
 
timestamp: Tue 2005-11-22 00:00:01 +0000
1686
 
message:
1687
 
  multiline
1688
 
  log
1689
 
  message
1690
 
------------------------------------------------------------
1691
 
revno: 1
1692
 
fixes bug(s): test://bug/id
1693
 
committer: Joe Foo <joe@foo.com>
1694
 
branch nick: work
1695
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1696
 
message:
1697
 
  simple log message
1698
 
""",
1699
 
            tree.branch, log.LongLogFormatter)
1700
 
 
1701
 
    def test_short_bugs(self):
1702
 
        tree = self.make_commits_with_bugs()
1703
 
        self.assertFormatterResult("""\
1704
 
    2 Joe Bar\t2005-11-22
1705
 
      fixes bug(s): test://bug/id test://bug/2
1706
 
      multiline
1707
 
      log
1708
 
      message
1709
 
 
1710
 
    1 Joe Foo\t2005-11-22
1711
 
      fixes bug(s): test://bug/id
1712
 
      simple log message
1713
 
 
1714
 
""",
1715
 
            tree.branch, log.ShortLogFormatter)
1716
 
 
1717
 
    def test_wrong_bugs_property(self):
1718
 
        tree = self.make_branch_and_tree(u'.')
1719
 
        self.build_tree(['foo'])
1720
 
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1721
 
                       revprops={'bugs': 'test://bug/id invalid_value'})
1722
 
        self.assertFormatterResult("""\
1723
 
    1 Joe Foo\t2005-11-22
1724
 
      simple log message
1725
 
 
1726
 
""",
1727
 
            tree.branch, log.ShortLogFormatter)
1728
 
 
1729
 
    def test_bugs_handler_present(self):
1730
 
        self.properties_handler_registry.get('bugs_properties_handler')
1731
 
 
1732
 
 
1733
 
class TestLogForAuthors(TestCaseForLogFormatter):
1734
 
 
1735
 
    def setUp(self):
1736
 
        TestCaseForLogFormatter.setUp(self)
1737
 
        self.wt = self.make_standard_commit('nicky',
1738
 
            authors=['John Doe <jdoe@example.com>',
1739
 
                     'Jane Rey <jrey@example.com>'])
1740
 
 
1741
 
    def assertFormatterResult(self, formatter, who, result):
1742
 
        formatter_kwargs = dict()
1743
 
        if who is not None:
1744
 
            author_list_handler = log.author_list_registry.get(who)
1745
 
            formatter_kwargs['author_list_handler'] = author_list_handler
1746
 
        TestCaseForLogFormatter.assertFormatterResult(self, result,
1747
 
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
1748
 
 
1749
 
    def test_line_default(self):
1750
 
        self.assertFormatterResult(log.LineLogFormatter, None, """\
1751
 
1: John Doe 2005-11-22 add a
1752
 
""")
1753
 
 
1754
 
    def test_line_committer(self):
1755
 
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
1756
 
1: Lorem Ipsum 2005-11-22 add a
1757
 
""")
1758
 
 
1759
 
    def test_line_first(self):
1760
 
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
1761
 
1: John Doe 2005-11-22 add a
1762
 
""")
1763
 
 
1764
 
    def test_line_all(self):
1765
 
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
1766
 
1: John Doe, Jane Rey 2005-11-22 add a
1767
 
""")
1768
 
 
1769
 
 
1770
 
    def test_short_default(self):
1771
 
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
1772
 
    1 John Doe\t2005-11-22
1773
 
      add a
1774
 
 
1775
 
""")
1776
 
 
1777
 
    def test_short_committer(self):
1778
 
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
1779
 
    1 Lorem Ipsum\t2005-11-22
1780
 
      add a
1781
 
 
1782
 
""")
1783
 
 
1784
 
    def test_short_first(self):
1785
 
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
1786
 
    1 John Doe\t2005-11-22
1787
 
      add a
1788
 
 
1789
 
""")
1790
 
 
1791
 
    def test_short_all(self):
1792
 
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
1793
 
    1 John Doe, Jane Rey\t2005-11-22
1794
 
      add a
1795
 
 
1796
 
""")
1797
 
 
1798
 
    def test_long_default(self):
1799
 
        self.assertFormatterResult(log.LongLogFormatter, None, """\
1800
 
------------------------------------------------------------
1801
 
revno: 1
1802
 
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1803
 
committer: Lorem Ipsum <test@example.com>
1804
 
branch nick: nicky
1805
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1806
 
message:
1807
 
  add a
1808
 
""")
1809
 
 
1810
 
    def test_long_committer(self):
1811
 
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
1812
 
------------------------------------------------------------
1813
 
revno: 1
1814
 
committer: Lorem Ipsum <test@example.com>
1815
 
branch nick: nicky
1816
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1817
 
message:
1818
 
  add a
1819
 
""")
1820
 
 
1821
 
    def test_long_first(self):
1822
 
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
1823
 
------------------------------------------------------------
1824
 
revno: 1
1825
 
author: John Doe <jdoe@example.com>
1826
 
committer: Lorem Ipsum <test@example.com>
1827
 
branch nick: nicky
1828
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1829
 
message:
1830
 
  add a
1831
 
""")
1832
 
 
1833
 
    def test_long_all(self):
1834
 
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
1835
 
------------------------------------------------------------
1836
 
revno: 1
1837
 
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1838
 
committer: Lorem Ipsum <test@example.com>
1839
 
branch nick: nicky
1840
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1841
 
message:
1842
 
  add a
1843
 
""")
1844
 
 
1845
 
    def test_gnu_changelog_default(self):
1846
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
1847
 
2005-11-22  John Doe  <jdoe@example.com>
1848
 
 
1849
 
\tadd a
1850
 
 
1851
 
""")
1852
 
 
1853
 
    def test_gnu_changelog_committer(self):
1854
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
1855
 
2005-11-22  Lorem Ipsum  <test@example.com>
1856
 
 
1857
 
\tadd a
1858
 
 
1859
 
""")
1860
 
 
1861
 
    def test_gnu_changelog_first(self):
1862
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
1863
 
2005-11-22  John Doe  <jdoe@example.com>
1864
 
 
1865
 
\tadd a
1866
 
 
1867
 
""")
1868
 
 
1869
 
    def test_gnu_changelog_all(self):
1870
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
1871
 
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
1872
 
 
1873
 
\tadd a
1874
 
 
1875
 
""")
1876
 
 
1877
 
 
1878
 
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1879
 
 
1880
 
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1881
 
        # See test_merge_sorted_exclude_ancestry below for the difference with
1882
 
        # bt.per_branch.test_iter_merge_sorted_revision.
1883
 
        # TestIterMergeSortedRevisionsBushyGraph. 
1884
 
        # make_branch_with_alternate_ancestries
1885
 
        # and test_merge_sorted_exclude_ancestry
1886
 
        # See the FIXME in assertLogRevnos too.
1887
 
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1888
 
        # 1
1889
 
        # |\
1890
 
        # 2 \
1891
 
        # |  |
1892
 
        # |  1.1.1
1893
 
        # |  | \
1894
 
        # |  |  1.2.1
1895
 
        # |  | /
1896
 
        # |  1.1.2
1897
 
        # | /
1898
 
        # 3
1899
 
        builder.start_series()
1900
 
        builder.build_snapshot('1', None, [
1901
 
            ('add', ('', 'TREE_ROOT', 'directory', '')),])
1902
 
        builder.build_snapshot('1.1.1', ['1'], [])
1903
 
        builder.build_snapshot('2', ['1'], [])
1904
 
        builder.build_snapshot('1.2.1', ['1.1.1'], [])
1905
 
        builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
1906
 
        builder.build_snapshot('3', ['2', '1.1.2'], [])
1907
 
        builder.finish_series()
1908
 
        br = builder.get_branch()
1909
 
        br.lock_read()
1910
 
        self.addCleanup(br.unlock)
1911
 
        return br
1912
 
 
1913
 
    def assertLogRevnos(self, expected_revnos, b, start, end,
1914
 
                        exclude_common_ancestry, generate_merge_revisions=True):
1915
 
        # FIXME: the layering in log makes it hard to test intermediate levels,
1916
 
        # I wish adding filters with their parameters were easier...
1917
 
        # -- vila 20100413
1918
 
        iter_revs = log._calc_view_revisions(
1919
 
            b, start, end, direction='reverse',
1920
 
            generate_merge_revisions=generate_merge_revisions,
1921
 
            exclude_common_ancestry=exclude_common_ancestry)
1922
 
        self.assertEqual(expected_revnos,
1923
 
                         [revid for revid, revno, depth in iter_revs])
1924
 
 
1925
 
    def test_merge_sorted_exclude_ancestry(self):
1926
 
        b = self.make_branch_with_alternate_ancestries()
1927
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1928
 
                             b, '1', '3', exclude_common_ancestry=False)
1929
 
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1930
 
        # it should be mentioned even if merge_sort order will make it appear
1931
 
        # after 1.1.1
1932
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1933
 
                             b, '1.1.1', '3', exclude_common_ancestry=True)
1934
 
 
1935
 
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1936
 
        b = self.make_branch_with_alternate_ancestries()
1937
 
        self.assertLogRevnos(['3', '2'],
1938
 
                             b, '1', '3', exclude_common_ancestry=True,
1939
 
                             generate_merge_revisions=False)
1940
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
1941
 
                             b, '1', '3', exclude_common_ancestry=True,
1942
 
                             generate_merge_revisions=True)
1943