[PATCH 2 of 2] annotate: handle empty files earlier
Augie Fackler
raf at durin42.com
Wed Jul 13 15:56:38 UTC 2016
On Wed, Jul 13, 2016 at 11:08:16AM +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1468244734 -7200
> # Mon Jul 11 15:45:34 2016 +0200
> # Node ID 97b9d021baad5537eab37232bdafe3a3e96404a2
> # Parent 969b3f54ffa50a3fc3348bb645700e647893a0e8
> annotate: handle empty files earlier
Queued these, thanks.
>
> Rather than looping on funcmap and then checking for non-zero `l`
> continue if the result of fctx.annotate is empty.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -469,26 +469,27 @@ def annotate(ui, repo, *pats, **opts):
>
> 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()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list