dagop: move lines() out of annotate()
authorYuya Nishihara <yuya@tcha.org>
Wed, 28 Feb 2018 15:20:41 -0500
changeset 36925 8fba319750c2
parent 36924 5d3abd6a5b25
child 36926 6ff6e1d6b5b8
dagop: move lines() out of annotate()
mercurial/dagop.py
--- a/mercurial/dagop.py	Wed Feb 28 15:19:47 2018 -0500
+++ b/mercurial/dagop.py	Wed Feb 28 15:20:41 2018 -0500
@@ -369,6 +369,11 @@
     # Whether this annotation was the result of a skip-annotate.
     skip = attr.ib(default=False)
 
+def _countlines(text):
+    if text.endswith("\n"):
+        return text.count("\n")
+    return text.count("\n") + int(bool(text))
+
 def _annotatepair(parents, childfctx, child, skipchild, diffopts):
     r'''
     Given parent and child fctxes and annotate data for parents, for all lines
@@ -436,18 +441,13 @@
     `parents(fctx)` is a function returning a list of parent filectxs.
     """
 
-    def lines(text):
-        if text.endswith("\n"):
-            return text.count("\n")
-        return text.count("\n") + int(bool(text))
-
     if linenumber:
         def decorate(text, rev):
             return ([annotateline(fctx=rev, lineno=i)
-                     for i in xrange(1, lines(text) + 1)], text)
+                     for i in xrange(1, _countlines(text) + 1)], text)
     else:
         def decorate(text, rev):
-            return ([annotateline(fctx=rev)] * lines(text), text)
+            return ([annotateline(fctx=rev)] * _countlines(text), text)
 
     # This algorithm would prefer to be recursive, but Python is a
     # bit recursion-hostile. Instead we do an iterative