[PATCH] annotate: calculate line count correctly

Augie Fackler raf at durin42.com
Sun Oct 2 17:59:07 EDT 2016


> On Oct 1, 2016, at 9:20 AM, Jun Wu <quark at fb.com> wrote:
> 
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1475327938 -3600
> #      Sat Oct 01 14:18:58 2016 +0100
> # Node ID dfd539e1e012e2fa78c0635e0e4bc993f7bbd89e
> # Parent  3741a8f86e88702595c29f8ed824a28da0cfa961
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r dfd539e1e012
> # EXP-Topic extensions.debug
> annotate: calculate line count correctly

queued this, thanks

> 
> Before this patch, the "lines" function inside "annotate" returns 1 for
> empty text (''). This patch makes it 0. Because the function should match
> mdiff.splitnewlines (used by mdiff.allblocks), or s.splitlines (used at the
> end of the "annotate" method). Both len(mdiff.splitnewlines('')) and
> len(''.splitlines(True)) are 0.
> 
> This issue was discovered while testing fastannotate [1].
> 
> I could not find a test case to reveal this issue. However in theory this
> could reduce memory usage a little bit, and avoids surprises when people
> are touching this area in the future.
> 
> [1]: https://bitbucket.org/facebook/hg-experimental/commits/525b3b98e93a
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -931,5 +931,5 @@ class basefilectx(object):
>             if text.endswith("\n"):
>                 return text.count("\n")
> -            return text.count("\n") + 1
> +            return text.count("\n") + int(bool(text))
> 
>         if linenumber:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20161002/4398282e/attachment.sig>


More information about the Mercurial-devel mailing list