Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 29528:9c3786713926
annotate: handle empty files earlier
Rather than looping on funcmap and then checking for non-zero `l`
continue if the result of fctx.annotate is empty.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Mon, 11 Jul 2016 15:45:34 +0200 |
parents | 33a6b750b5b9 |
children | 53e2c979e4cd |
comparison
equal
deleted
inserted
replaced
29527:576ff900fcc7 | 29528:9c3786713926 |
---|---|
467 fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) | 467 fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
468 continue | 468 continue |
469 | 469 |
470 lines = fctx.annotate(follow=follow, linenumber=linenumber, | 470 lines = fctx.annotate(follow=follow, linenumber=linenumber, |
471 diffopts=diffopts) | 471 diffopts=diffopts) |
472 if not lines: | |
473 continue | |
472 formats = [] | 474 formats = [] |
473 pieces = [] | 475 pieces = [] |
474 | 476 |
475 for f, sep in funcmap: | 477 for f, sep in funcmap: |
476 l = [f(n) for n, dummy in lines] | 478 l = [f(n) for n, dummy in lines] |
477 if l: | 479 if fm: |
478 if fm: | 480 formats.append(['%s' for x in l]) |
479 formats.append(['%s' for x in l]) | 481 else: |
480 else: | 482 sizes = [encoding.colwidth(x) for x in l] |
481 sizes = [encoding.colwidth(x) for x in l] | 483 ml = max(sizes) |
482 ml = max(sizes) | 484 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
483 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) | 485 pieces.append(l) |
484 pieces.append(l) | |
485 | 486 |
486 for f, p, l in zip(zip(*formats), zip(*pieces), lines): | 487 for f, p, l in zip(zip(*formats), zip(*pieces), lines): |
487 fm.startitem() | 488 fm.startitem() |
488 fm.write(fields, "".join(f), *p) | 489 fm.write(fields, "".join(f), *p) |
489 fm.write('line', ": %s", l[1]) | 490 fm.write('line', ": %s", l[1]) |
490 | 491 |
491 if lines and not lines[-1][1].endswith('\n'): | 492 if not lines[-1][1].endswith('\n'): |
492 fm.plain('\n') | 493 fm.plain('\n') |
493 | 494 |
494 fm.end() | 495 fm.end() |
495 | 496 |
496 @command('archive', | 497 @command('archive', |