# HG changeset patch # User Jun Wu # Date 1475327938 -3600 # Node ID 3e3f2201bbdfada996cf9c7d29c7bf86587c09f3 # Parent ff7697b436aba70b752a6277eaf4e9ef298e3640 annotate: calculate line count correctly 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 -r ff7697b436ab -r 3e3f2201bbdf mercurial/context.py --- a/mercurial/context.py Sun Oct 02 05:29:17 2016 +0530 +++ b/mercurial/context.py Sat Oct 01 14:18:58 2016 +0100 @@ -930,7 +930,7 @@ def lines(text): if text.endswith("\n"): return text.count("\n") - return text.count("\n") + 1 + return text.count("\n") + int(bool(text)) if linenumber: def decorate(text, rev):