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