changeset 30040:3e3f2201bbdf

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
author Jun Wu <quark@fb.com>
date Sat, 01 Oct 2016 14:18:58 +0100
parents ff7697b436ab
children 1779dde4c9ef
files mercurial/context.py
diffstat 1 files changed, 1 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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):