~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

(jelmer) Support upgrading between the 2a and development-colo formats.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Whitebox tests for annotate functionality."""
18
18
 
21
21
 
22
22
from bzrlib import (
23
23
    annotate,
24
 
    conflicts,
25
 
    errors,
 
24
    symbol_versioning,
26
25
    tests,
27
 
    trace,
28
26
    )
29
27
 
30
28
 
116
114
#  |\
117
115
#  A B  # line should be annotated as new for A and B
118
116
#  |\|
119
 
#  C D  # line should 'converge' and say D
 
117
#  C D  # line should 'converge' and say A
120
118
#  |/
121
119
#  E    # D should supersede A and stay as D (not become E because C references
122
120
#         A)
150
148
 
151
149
duplicate_D = annotation("""\
152
150
rev-base first
153
 
rev-D alt-second
 
151
rev-A alt-second
154
152
rev-base third
155
153
rev-D fourth-D
156
154
""")
157
155
 
158
156
duplicate_E = annotation("""\
159
157
rev-base first
160
 
rev-D alt-second
 
158
rev-A alt-second
161
159
rev-base third
162
160
rev-E fourth-E
163
161
""")
176
174
         |
177
175
        rev-3
178
176
        """
179
 
 
180
 
        tree1 = self.make_branch_and_tree('tree1')
181
 
        self.build_tree_contents([('tree1/a', 'first\n')])
182
 
        tree1.add(['a'], ['a-id'])
183
 
        tree1.commit('a', rev_id='rev-1',
184
 
                     committer="joe@foo.com",
185
 
                     timestamp=1166046000.00, timezone=0)
186
 
 
187
 
        tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
188
 
 
189
 
        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
190
 
        tree1.commit('b', rev_id='rev-2',
191
 
                     committer='joe@foo.com',
192
 
                     timestamp=1166046001.00, timezone=0)
193
 
 
194
 
        self.build_tree_contents([('tree2/a', 'first\nthird\n')])
195
 
        tree2.commit('c', rev_id='rev-1_1_1',
196
 
                     committer="barry@foo.com",
197
 
                     timestamp=1166046002.00, timezone=0)
198
 
 
199
 
        num_conflicts = tree1.merge_from_branch(tree2.branch)
200
 
        self.assertEqual(1, num_conflicts)
201
 
 
202
 
        self.build_tree_contents([('tree1/a',
203
 
                                 'first\nsecond\nthird\n')])
204
 
        tree1.set_conflicts(conflicts.ConflictList())
205
 
        tree1.commit('merge 2', rev_id='rev-3',
206
 
                     committer='sal@foo.com',
207
 
                     timestamp=1166046003.00, timezone=0)
208
 
        tree1.lock_read()
209
 
        self.addCleanup(tree1.unlock)
210
 
        return tree1, tree2
 
177
        builder = self.make_branch_builder('branch')
 
178
        builder.start_series()
 
179
        self.addCleanup(builder.finish_series)
 
180
        builder.build_snapshot('rev-1', None, [
 
181
            ('add', ('', 'root-id', 'directory', None)),
 
182
            ('add', ('a', 'a-id', 'file', 'first\n')),
 
183
            ], timestamp=1166046000.00, timezone=0, committer="joe@foo.com")
 
184
        builder.build_snapshot('rev-2', ['rev-1'], [
 
185
            ('modify', ('a-id', 'first\nsecond\n')),
 
186
            ], timestamp=1166046001.00, timezone=0, committer="joe@foo.com")
 
187
        builder.build_snapshot('rev-1_1_1', ['rev-1'], [
 
188
            ('modify', ('a-id', 'first\nthird\n')),
 
189
            ], timestamp=1166046002.00, timezone=0, committer="barry@foo.com")
 
190
        builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
 
191
            ('modify', ('a-id', 'first\nsecond\nthird\n')),
 
192
            ], timestamp=1166046003.00, timezone=0, committer="sal@foo.com")
 
193
        return builder
211
194
 
212
195
    def create_deeply_merged_trees(self):
213
196
        """Create some trees with a more complex merge history.
232
215
         |
233
216
        rev-6
234
217
        """
235
 
        tree1, tree2 = self.create_merged_trees()
236
 
        tree1.unlock()
237
 
 
238
 
        tree3 = tree2.bzrdir.clone('tree3').open_workingtree()
239
 
 
240
 
        tree2.commit('noop', rev_id='rev-1_1_2')
241
 
        self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
242
 
        tree1.commit('noop merge', rev_id='rev-4')
243
 
 
244
 
        self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
245
 
        tree3.commit('four', rev_id='rev-1_2_1',
246
 
                     committer='jerry@foo.com',
247
 
                     timestamp=1166046003.00, timezone=0)
248
 
 
249
 
        tree4 = tree3.bzrdir.clone('tree4').open_workingtree()
250
 
 
251
 
        tree3.commit('noop', rev_id='rev-1_2_2',
252
 
                     committer='jerry@foo.com',
253
 
                     timestamp=1166046004.00, timezone=0)
254
 
        self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
255
 
        tree1.commit('merge four', rev_id='rev-5')
256
 
 
257
 
        self.build_tree_contents([('tree4/a',
258
 
                                   'first\nthird\nfourth\nfifth\nsixth\n')])
259
 
        tree4.commit('five and six', rev_id='rev-1_3_1',
260
 
                     committer='george@foo.com',
261
 
                     timestamp=1166046005.00, timezone=0)
262
 
        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
263
 
        tree1.commit('merge five and six', rev_id='rev-6')
264
 
        tree1.lock_read()
265
 
        return tree1
 
218
        builder = self.create_merged_trees()
 
219
        builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
 
220
        builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
 
221
        builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
 
222
            ('modify', ('a-id', 'first\nthird\nfourth\n')),
 
223
            ], timestamp=1166046003.00, timezone=0, committer="jerry@foo.com")
 
224
        builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
 
225
            timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
 
226
        builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
 
227
            ('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
 
228
            ], timestamp=1166046004.00, timezone=0, committer="jerry@foo.com")
 
229
        builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
 
230
            ('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
 
231
            ], timestamp=1166046005.00, timezone=0, committer="george@foo.com")
 
232
        builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
 
233
            ('modify', ('a-id',
 
234
                        'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
 
235
            ])
 
236
        return builder
266
237
 
267
238
    def create_duplicate_lines_tree(self):
268
 
        tree1 = self.make_branch_and_tree('tree1')
 
239
        builder = self.make_branch_builder('branch')
 
240
        builder.start_series()
 
241
        self.addCleanup(builder.finish_series)
269
242
        base_text = ''.join(l for r, l in duplicate_base)
270
243
        a_text = ''.join(l for r, l in duplicate_A)
271
244
        b_text = ''.join(l for r, l in duplicate_B)
272
245
        c_text = ''.join(l for r, l in duplicate_C)
273
246
        d_text = ''.join(l for r, l in duplicate_D)
274
247
        e_text = ''.join(l for r, l in duplicate_E)
275
 
        self.build_tree_contents([('tree1/file', base_text)])
276
 
        tree1.add(['file'], ['file-id'])
277
 
        tree1.commit('base', rev_id='rev-base')
278
 
        tree2 = tree1.bzrdir.clone('tree2').open_workingtree()
279
 
 
280
 
        self.build_tree_contents([('tree1/file', a_text),
281
 
                                  ('tree2/file', b_text)])
282
 
        tree1.commit('A', rev_id='rev-A')
283
 
        tree2.commit('B', rev_id='rev-B')
284
 
 
285
 
        tree2.merge_from_branch(tree1.branch)
286
 
        conflicts.resolve(tree2, None) # Resolve the conflicts
287
 
        self.build_tree_contents([('tree2/file', d_text)])
288
 
        tree2.commit('D', rev_id='rev-D')
289
 
 
290
 
        self.build_tree_contents([('tree1/file', c_text)])
291
 
        tree1.commit('C', rev_id='rev-C')
292
 
 
293
 
        tree1.merge_from_branch(tree2.branch)
294
 
        conflicts.resolve(tree1, None) # Resolve the conflicts
295
 
        self.build_tree_contents([('tree1/file', e_text)])
296
 
        tree1.commit('E', rev_id='rev-E')
297
 
        return tree1
298
 
 
299
 
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
300
 
        """Assert that the revision is properly annotated."""
301
 
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
248
        builder.build_snapshot('rev-base', None, [
 
249
            ('add', ('', 'root-id', 'directory', None)),
 
250
            ('add', ('file', 'file-id', 'file', base_text)),
 
251
            ])
 
252
        builder.build_snapshot('rev-A', ['rev-base'], [
 
253
            ('modify', ('file-id', a_text))])
 
254
        builder.build_snapshot('rev-B', ['rev-base'], [
 
255
            ('modify', ('file-id', b_text))])
 
256
        builder.build_snapshot('rev-C', ['rev-A'], [
 
257
            ('modify', ('file-id', c_text))])
 
258
        builder.build_snapshot('rev-D', ['rev-B', 'rev-A'], [
 
259
            ('modify', ('file-id', d_text))])
 
260
        builder.build_snapshot('rev-E', ['rev-C', 'rev-D'], [
 
261
            ('modify', ('file-id', e_text))])
 
262
        return builder
 
263
 
 
264
    def assertAnnotateEqualDiff(self, actual, expected):
302
265
        if actual != expected:
303
266
            # Create an easier to understand diff when the lines don't actually
304
267
            # match
305
268
            self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
306
269
                                 ''.join('\t'.join(l) for l in actual))
307
270
 
 
271
    def assertBranchAnnotate(self, expected, branch, file_id, revision_id,
 
272
            verbose=False, full=False, show_ids=False):
 
273
        tree = branch.repository.revision_tree(revision_id)
 
274
        to_file = StringIO()
 
275
        annotate.annotate_file_tree(tree, file_id, to_file,
 
276
            verbose=verbose, full=full, show_ids=show_ids, branch=branch)
 
277
        self.assertAnnotateEqualDiff(to_file.getvalue(), expected)
 
278
 
 
279
    def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
 
280
        """Assert that the revision is properly annotated."""
 
281
        actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
 
282
        self.assertAnnotateEqualDiff(actual, expected)
 
283
 
308
284
    def test_annotate_duplicate_lines(self):
309
 
        # XXX: Should this be a repository_implementations test?
310
 
        tree1 = self.create_duplicate_lines_tree()
311
 
        repo = tree1.branch.repository
 
285
        # XXX: Should this be a per_repository test?
 
286
        builder = self.create_duplicate_lines_tree()
 
287
        repo = builder.get_branch().repository
312
288
        repo.lock_read()
313
289
        self.addCleanup(repo.unlock)
314
290
        self.assertRepoAnnotate(duplicate_base, repo, 'file-id', 'rev-base')
319
295
        self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
320
296
 
321
297
    def test_annotate_shows_dotted_revnos(self):
322
 
        tree1, tree2 = self.create_merged_trees()
323
 
 
324
 
        sio = StringIO()
325
 
        annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
326
 
                               to_file=sio)
327
 
        self.assertEqualDiff('1     joe@foo | first\n'
328
 
                             '2     joe@foo | second\n'
329
 
                             '1.1.1 barry@f | third\n',
330
 
                             sio.getvalue())
 
298
        builder = self.create_merged_trees()
 
299
 
 
300
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
301
                                  '2     joe@foo | second\n'
 
302
                                  '1.1.1 barry@f | third\n',
 
303
                                  builder.get_branch(), 'a-id', 'rev-3')
 
304
 
 
305
    def test_annotate_file(self):
 
306
        builder = self.create_merged_trees()
 
307
 
 
308
        to_file = StringIO()
 
309
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
310
            annotate.annotate_file, builder.get_branch(),
 
311
                'rev-3', 'a-id', to_file=to_file)
 
312
 
 
313
        self.assertAnnotateEqualDiff('1     joe@foo | first\n'
 
314
                                     '2     joe@foo | second\n'
 
315
                                     '1.1.1 barry@f | third\n',
 
316
                                     to_file.getvalue())
331
317
 
332
318
    def test_annotate_limits_dotted_revnos(self):
333
319
        """Annotate should limit dotted revnos to a depth of 12"""
334
 
        tree1 = self.create_deeply_merged_trees()
335
 
 
336
 
        sio = StringIO()
337
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
338
 
                               to_file=sio, verbose=False, full=False)
339
 
        self.assertEqualDiff('1     joe@foo | first\n'
340
 
                             '2     joe@foo | second\n'
341
 
                             '1.1.1 barry@f | third\n'
342
 
                             '1.2.1 jerry@f | fourth\n'
343
 
                             '1.3.1 george@ | fifth\n'
344
 
                             '              | sixth\n',
345
 
                             sio.getvalue())
346
 
 
347
 
        sio = StringIO()
348
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
349
 
                               to_file=sio, verbose=False, full=True)
350
 
        self.assertEqualDiff('1     joe@foo | first\n'
351
 
                             '2     joe@foo | second\n'
352
 
                             '1.1.1 barry@f | third\n'
353
 
                             '1.2.1 jerry@f | fourth\n'
354
 
                             '1.3.1 george@ | fifth\n'
355
 
                             '1.3.1 george@ | sixth\n',
356
 
                             sio.getvalue())
 
320
        builder = self.create_deeply_merged_trees()
 
321
 
 
322
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
323
                                  '2     joe@foo | second\n'
 
324
                                  '1.1.1 barry@f | third\n'
 
325
                                  '1.2.1 jerry@f | fourth\n'
 
326
                                  '1.3.1 george@ | fifth\n'
 
327
                                  '              | sixth\n',
 
328
                                  builder.get_branch(), 'a-id', 'rev-6',
 
329
                                  verbose=False, full=False)
 
330
 
 
331
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
332
                                  '2     joe@foo | second\n'
 
333
                                  '1.1.1 barry@f | third\n'
 
334
                                  '1.2.1 jerry@f | fourth\n'
 
335
                                  '1.3.1 george@ | fifth\n'
 
336
                                  '1.3.1 george@ | sixth\n',
 
337
                                  builder.get_branch(), 'a-id', 'rev-6',
 
338
                                  verbose=False, full=True)
357
339
 
358
340
        # verbose=True shows everything, the full revno, user id, and date
359
 
        sio = StringIO()
360
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
361
 
                               to_file=sio, verbose=True, full=False)
362
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
363
 
                             '2     joe@foo.com    20061213 | second\n'
364
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
365
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
366
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
367
 
                             '                              | sixth\n',
368
 
                             sio.getvalue())
 
341
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
342
                                  '2     joe@foo.com    20061213 | second\n'
 
343
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
344
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
345
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
346
                                  '                              | sixth\n',
 
347
                                  builder.get_branch(), 'a-id', 'rev-6',
 
348
                                  verbose=True, full=False)
369
349
 
370
 
        sio = StringIO()
371
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
372
 
                               to_file=sio, verbose=True, full=True)
373
 
        self.assertEqualDiff('1     joe@foo.com    20061213 | first\n'
374
 
                             '2     joe@foo.com    20061213 | second\n'
375
 
                             '1.1.1 barry@foo.com  20061213 | third\n'
376
 
                             '1.2.1 jerry@foo.com  20061213 | fourth\n'
377
 
                             '1.3.1 george@foo.com 20061213 | fifth\n'
378
 
                             '1.3.1 george@foo.com 20061213 | sixth\n',
379
 
                             sio.getvalue())
 
350
        self.assertBranchAnnotate('1     joe@foo.com    20061213 | first\n'
 
351
                                  '2     joe@foo.com    20061213 | second\n'
 
352
                                  '1.1.1 barry@foo.com  20061213 | third\n'
 
353
                                  '1.2.1 jerry@foo.com  20061213 | fourth\n'
 
354
                                  '1.3.1 george@foo.com 20061213 | fifth\n'
 
355
                                  '1.3.1 george@foo.com 20061213 | sixth\n',
 
356
                                  builder.get_branch(), 'a-id', 'rev-6',
 
357
                                  verbose=True, full=True)
380
358
 
381
359
    def test_annotate_uses_branch_context(self):
382
360
        """Dotted revnos should use the Branch context.
384
362
        When annotating a non-mainline revision, the annotation should still
385
363
        use dotted revnos from the mainline.
386
364
        """
387
 
        tree1 = self.create_deeply_merged_trees()
 
365
        builder = self.create_deeply_merged_trees()
388
366
 
389
 
        sio = StringIO()
390
 
        annotate.annotate_file(tree1.branch, 'rev-1_3_1', 'a-id',
391
 
                               to_file=sio, verbose=False, full=False)
392
 
        self.assertEqualDiff('1     joe@foo | first\n'
393
 
                             '1.1.1 barry@f | third\n'
394
 
                             '1.2.1 jerry@f | fourth\n'
395
 
                             '1.3.1 george@ | fifth\n'
396
 
                             '              | sixth\n',
397
 
                             sio.getvalue())
 
367
        self.assertBranchAnnotate('1     joe@foo | first\n'
 
368
                                  '1.1.1 barry@f | third\n'
 
369
                                  '1.2.1 jerry@f | fourth\n'
 
370
                                  '1.3.1 george@ | fifth\n'
 
371
                                  '              | sixth\n',
 
372
                                  builder.get_branch(), 'a-id', 'rev-1_3_1',
 
373
                                  verbose=False, full=False)
398
374
 
399
375
    def test_annotate_show_ids(self):
400
 
        tree1 = self.create_deeply_merged_trees()
401
 
 
402
 
        sio = StringIO()
403
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
404
 
                               to_file=sio, show_ids=True, full=False)
 
376
        builder = self.create_deeply_merged_trees()
405
377
 
406
378
        # It looks better with real revision ids :)
407
 
        self.assertEqualDiff('    rev-1 | first\n'
408
 
                             '    rev-2 | second\n'
409
 
                             'rev-1_1_1 | third\n'
410
 
                             'rev-1_2_1 | fourth\n'
411
 
                             'rev-1_3_1 | fifth\n'
412
 
                             '          | sixth\n',
413
 
                             sio.getvalue())
414
 
 
415
 
        sio = StringIO()
416
 
        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
417
 
                               to_file=sio, show_ids=True, full=True)
418
 
 
419
 
        self.assertEqualDiff('    rev-1 | first\n'
420
 
                             '    rev-2 | second\n'
421
 
                             'rev-1_1_1 | third\n'
422
 
                             'rev-1_2_1 | fourth\n'
423
 
                             'rev-1_3_1 | fifth\n'
424
 
                             'rev-1_3_1 | sixth\n',
425
 
                             sio.getvalue())
 
379
        self.assertBranchAnnotate('    rev-1 | first\n'
 
380
                                  '    rev-2 | second\n'
 
381
                                  'rev-1_1_1 | third\n'
 
382
                                  'rev-1_2_1 | fourth\n'
 
383
                                  'rev-1_3_1 | fifth\n'
 
384
                                  '          | sixth\n',
 
385
                                  builder.get_branch(), 'a-id', 'rev-6',
 
386
                                  show_ids=True, full=False)
 
387
 
 
388
        self.assertBranchAnnotate('    rev-1 | first\n'
 
389
                                  '    rev-2 | second\n'
 
390
                                  'rev-1_1_1 | third\n'
 
391
                                  'rev-1_2_1 | fourth\n'
 
392
                                  'rev-1_3_1 | fifth\n'
 
393
                                  'rev-1_3_1 | sixth\n',
 
394
                                  builder.get_branch(), 'a-id', 'rev-6',
 
395
                                  show_ids=True, full=True)
426
396
 
427
397
    def test_annotate_unicode_author(self):
428
398
        tree1 = self.make_branch_and_tree('tree1')
441
411
 
442
412
        tree1.lock_read()
443
413
        self.addCleanup(tree1.unlock)
 
414
 
 
415
        revtree_1 = tree1.branch.repository.revision_tree('rev-1')
 
416
        revtree_2 = tree1.branch.repository.revision_tree('rev-2')
 
417
 
444
418
        # this passes if no exception is raised
445
419
        to_file = StringIO()
446
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
 
420
        annotate.annotate_file_tree(revtree_1, 'a-id',
 
421
            to_file=to_file, branch=tree1.branch)
447
422
 
448
423
        sio = StringIO()
449
424
        to_file = codecs.getwriter('ascii')(sio)
450
425
        to_file.encoding = 'ascii' # codecs does not set it
451
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
426
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
427
            to_file=to_file, branch=tree1.branch)
452
428
        self.assertEqualDiff('2   p?rez   | bye\n', sio.getvalue())
453
429
 
454
430
        # test now with to_file.encoding = None
455
431
        to_file = tests.StringIOWrapper()
456
432
        to_file.encoding = None
457
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
433
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
434
            to_file=to_file, branch=tree1.branch)
458
435
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
459
436
 
460
437
        # and when it does not exist
461
438
        to_file = StringIO()
462
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
 
439
        annotate.annotate_file_tree(revtree_2, 'b-id',
 
440
            to_file=to_file, branch=tree1.branch)
463
441
        self.assertContainsRe('2   p.rez   | bye\n', to_file.getvalue())
464
442
 
465
443
    def test_annotate_author_or_committer(self):
475
453
        tree1.add(['b'], ['b-id'])
476
454
        tree1.commit('b', rev_id='rev-2',
477
455
                     committer='Committer <committer@example.com>',
478
 
                     author='Author <author@example.com>',
 
456
                     authors=['Author <author@example.com>'],
479
457
                     timestamp=1166046000.00, timezone=0)
480
458
 
481
459
        tree1.lock_read()
482
460
        self.addCleanup(tree1.unlock)
483
 
        to_file = StringIO()
484
 
        annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
485
 
        self.assertEqual('1   committ | hello\n', to_file.getvalue())
486
 
 
487
 
        to_file = StringIO()
488
 
        annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
489
 
        self.assertEqual('2   author@ | bye\n', to_file.getvalue())
 
461
 
 
462
        self.assertBranchAnnotate('1   committ | hello\n', tree1.branch,
 
463
            'a-id', 'rev-1')
 
464
 
 
465
        to_file = StringIO()
 
466
        self.assertBranchAnnotate('2   author@ | bye\n', tree1.branch,
 
467
            'b-id', 'rev-2')
490
468
 
491
469
 
492
470
class TestReannotate(tests.TestCase):
502
480
    def test_reannotate(self):
503
481
        self.annotateEqual(parent_1, [parent_1], new_1, 'blahblah')
504
482
        self.annotateEqual(expected_2_1, [parent_2], new_1, 'blahblah')
505
 
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2, 
 
483
        self.annotateEqual(expected_1_2_2, [parent_1, parent_2], new_2,
506
484
                           'blahblah')
507
485
 
508
486
    def test_reannotate_no_parents(self):