261
263
('modify', ('file-id', e_text))])
264
def assertAnnotateEqualDiff(self, actual, expected):
266
def assertRepoAnnotate(self, expected, repo, file_id, revision_id):
267
"""Assert that the revision is properly annotated."""
268
actual = list(repo.revision_tree(revision_id).annotate_iter(file_id))
265
269
if actual != expected:
266
270
# Create an easier to understand diff when the lines don't actually
268
272
self.assertEqualDiff(''.join('\t'.join(l) for l in expected),
269
273
''.join('\t'.join(l) for l in actual))
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)
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)
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)
284
275
def test_annotate_duplicate_lines(self):
285
276
# XXX: Should this be a per_repository test?
286
277
builder = self.create_duplicate_lines_tree()
297
288
def test_annotate_shows_dotted_revnos(self):
298
289
builder = self.create_merged_trees()
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')
292
annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
294
self.assertEqualDiff('1 joe@foo | first\n'
295
'2 joe@foo | second\n'
296
'1.1.1 barry@f | third\n',
305
299
def test_annotate_limits_dotted_revnos(self):
306
300
"""Annotate should limit dotted revnos to a depth of 12"""
307
301
builder = self.create_deeply_merged_trees()
309
self.assertBranchAnnotate('1 joe@foo | first\n'
310
'2 joe@foo | second\n'
311
'1.1.1 barry@f | third\n'
312
'1.2.1 jerry@f | fourth\n'
313
'1.3.1 george@ | fifth\n'
315
builder.get_branch(), 'a-id', 'rev-6',
316
verbose=False, full=False)
304
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
305
to_file=sio, verbose=False, full=False)
306
self.assertEqualDiff('1 joe@foo | first\n'
307
'2 joe@foo | second\n'
308
'1.1.1 barry@f | third\n'
309
'1.2.1 jerry@f | fourth\n'
310
'1.3.1 george@ | fifth\n'
318
self.assertBranchAnnotate('1 joe@foo | first\n'
319
'2 joe@foo | second\n'
320
'1.1.1 barry@f | third\n'
321
'1.2.1 jerry@f | fourth\n'
322
'1.3.1 george@ | fifth\n'
323
'1.3.1 george@ | sixth\n',
324
builder.get_branch(), 'a-id', 'rev-6',
325
verbose=False, full=True)
315
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
316
to_file=sio, verbose=False, full=True)
317
self.assertEqualDiff('1 joe@foo | first\n'
318
'2 joe@foo | second\n'
319
'1.1.1 barry@f | third\n'
320
'1.2.1 jerry@f | fourth\n'
321
'1.3.1 george@ | fifth\n'
322
'1.3.1 george@ | sixth\n',
327
325
# verbose=True shows everything, the full revno, user id, and date
328
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
329
'2 joe@foo.com 20061213 | second\n'
330
'1.1.1 barry@foo.com 20061213 | third\n'
331
'1.2.1 jerry@foo.com 20061213 | fourth\n'
332
'1.3.1 george@foo.com 20061213 | fifth\n'
334
builder.get_branch(), 'a-id', 'rev-6',
335
verbose=True, full=False)
327
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
328
to_file=sio, verbose=True, full=False)
329
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
330
'2 joe@foo.com 20061213 | second\n'
331
'1.1.1 barry@foo.com 20061213 | third\n'
332
'1.2.1 jerry@foo.com 20061213 | fourth\n'
333
'1.3.1 george@foo.com 20061213 | fifth\n'
337
self.assertBranchAnnotate('1 joe@foo.com 20061213 | first\n'
338
'2 joe@foo.com 20061213 | second\n'
339
'1.1.1 barry@foo.com 20061213 | third\n'
340
'1.2.1 jerry@foo.com 20061213 | fourth\n'
341
'1.3.1 george@foo.com 20061213 | fifth\n'
342
'1.3.1 george@foo.com 20061213 | sixth\n',
343
builder.get_branch(), 'a-id', 'rev-6',
344
verbose=True, full=True)
338
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
339
to_file=sio, verbose=True, full=True)
340
self.assertEqualDiff('1 joe@foo.com 20061213 | first\n'
341
'2 joe@foo.com 20061213 | second\n'
342
'1.1.1 barry@foo.com 20061213 | third\n'
343
'1.2.1 jerry@foo.com 20061213 | fourth\n'
344
'1.3.1 george@foo.com 20061213 | fifth\n'
345
'1.3.1 george@foo.com 20061213 | sixth\n',
346
348
def test_annotate_uses_branch_context(self):
347
349
"""Dotted revnos should use the Branch context.
352
354
builder = self.create_deeply_merged_trees()
354
self.assertBranchAnnotate('1 joe@foo | first\n'
355
'1.1.1 barry@f | third\n'
356
'1.2.1 jerry@f | fourth\n'
357
'1.3.1 george@ | fifth\n'
359
builder.get_branch(), 'a-id', 'rev-1_3_1',
360
verbose=False, full=False)
357
annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
358
to_file=sio, verbose=False, full=False)
359
self.assertEqualDiff('1 joe@foo | first\n'
360
'1.1.1 barry@f | third\n'
361
'1.2.1 jerry@f | fourth\n'
362
'1.3.1 george@ | fifth\n'
362
366
def test_annotate_show_ids(self):
363
367
builder = self.create_deeply_merged_trees()
370
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
371
to_file=sio, show_ids=True, full=False)
365
373
# It looks better with real revision ids :)
366
self.assertBranchAnnotate(' rev-1 | first\n'
368
'rev-1_1_1 | third\n'
369
'rev-1_2_1 | fourth\n'
370
'rev-1_3_1 | fifth\n'
372
builder.get_branch(), 'a-id', 'rev-6',
373
show_ids=True, full=False)
375
self.assertBranchAnnotate(' rev-1 | first\n'
377
'rev-1_1_1 | third\n'
378
'rev-1_2_1 | fourth\n'
379
'rev-1_3_1 | fifth\n'
380
'rev-1_3_1 | sixth\n',
381
builder.get_branch(), 'a-id', 'rev-6',
382
show_ids=True, full=True)
374
self.assertEqualDiff(' rev-1 | first\n'
376
'rev-1_1_1 | third\n'
377
'rev-1_2_1 | fourth\n'
378
'rev-1_3_1 | fifth\n'
383
annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
384
to_file=sio, show_ids=True, full=True)
386
self.assertEqualDiff(' rev-1 | first\n'
388
'rev-1_1_1 | third\n'
389
'rev-1_2_1 | fourth\n'
390
'rev-1_3_1 | fifth\n'
391
'rev-1_3_1 | sixth\n',
384
394
def test_annotate_unicode_author(self):
385
395
tree1 = self.make_branch_and_tree('tree1')
399
409
tree1.lock_read()
400
410
self.addCleanup(tree1.unlock)
402
revtree_1 = tree1.branch.repository.revision_tree('rev-1')
403
revtree_2 = tree1.branch.repository.revision_tree('rev-2')
405
411
# this passes if no exception is raised
406
412
to_file = StringIO()
407
annotate.annotate_file_tree(revtree_1, 'a-id',
408
to_file=to_file, branch=tree1.branch)
413
annotate.annotate_file(tree1.branch, 'rev-1', 'a-id', to_file=to_file)
411
416
to_file = codecs.getwriter('ascii')(sio)
412
417
to_file.encoding = 'ascii' # codecs does not set it
413
annotate.annotate_file_tree(revtree_2, 'b-id',
414
to_file=to_file, branch=tree1.branch)
418
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
415
419
self.assertEqualDiff('2 p?rez | bye\n', sio.getvalue())
417
421
# test now with to_file.encoding = None
418
422
to_file = tests.StringIOWrapper()
419
423
to_file.encoding = None
420
annotate.annotate_file_tree(revtree_2, 'b-id',
421
to_file=to_file, branch=tree1.branch)
424
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
422
425
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
424
427
# and when it does not exist
425
428
to_file = StringIO()
426
annotate.annotate_file_tree(revtree_2, 'b-id',
427
to_file=to_file, branch=tree1.branch)
429
annotate.annotate_file(tree1.branch, 'rev-2', 'b-id', to_file=to_file)
428
430
self.assertContainsRe('2 p.rez | bye\n', to_file.getvalue())
430
432
def test_annotate_author_or_committer(self):