~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-04 07:10:07 UTC
  • mto: (4086.1.2 hpss-integration)
  • mto: This revision was merged to the branch mainline in revision 4087.
  • Revision ID: andrew.bennetts@canonical.com-20090304071007-8iqoi1m44ypmzg2a
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.

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