Mercurial > hg
changeset 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 | 576ff900fcc7 |
children | 02de1dbd4f6e |
files | mercurial/commands.py |
diffstat | 1 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Mon Jul 11 14:44:19 2016 +0200 +++ b/mercurial/commands.py Mon Jul 11 15:45:34 2016 +0200 @@ -469,26 +469,27 @@ lines = fctx.annotate(follow=follow, linenumber=linenumber, diffopts=diffopts) + if not lines: + continue formats = [] pieces = [] for f, sep in funcmap: l = [f(n) for n, dummy in lines] - if l: - if fm: - formats.append(['%s' for x in l]) - else: - sizes = [encoding.colwidth(x) for x in l] - ml = max(sizes) - formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) - pieces.append(l) + if fm: + formats.append(['%s' for x in l]) + else: + sizes = [encoding.colwidth(x) for x in l] + ml = max(sizes) + formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) + pieces.append(l) for f, p, l in zip(zip(*formats), zip(*pieces), lines): fm.startitem() fm.write(fields, "".join(f), *p) fm.write('line', ": %s", l[1]) - if lines and not lines[-1][1].endswith('\n'): + if not lines[-1][1].endswith('\n'): fm.plain('\n') fm.end()