~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-09 23:12:55 UTC
  • mfrom: (3920.2.37 dpush)
  • Revision ID: pqm@pqm.ubuntu.com-20090409231255-o8w1g2q3igiyf8b2
(Jelmer) Add the dpush command.

Show diffs side-by-side

added added

removed removed

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