Patchwork [3,of,3] dagop: move lines() out of annotate()

login
register
mail settings
Submitter Yuya Nishihara
Date March 11, 2018, 3 p.m.
Message ID <ba4ae5454659806d03b7.1520780441@mimosa>
Download mbox | patch
Permalink /patch/29308/
State Accepted
Headers show

Comments

Yuya Nishihara - March 11, 2018, 3 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519849241 18000
#      Wed Feb 28 15:20:41 2018 -0500
# Node ID ba4ae5454659806d03b7e4ebceb7238bfe46443e
# Parent  f634f309bed610e84b4ff151044f320461509e78
dagop: move lines() out of annotate()
Augie Fackler - March 12, 2018, 10:06 p.m.
On Mon, Mar 12, 2018 at 12:00:41AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519849241 18000
> #      Wed Feb 28 15:20:41 2018 -0500
> # Node ID ba4ae5454659806d03b7e4ebceb7238bfe46443e
> # Parent  f634f309bed610e84b4ff151044f320461509e78
> dagop: move lines() out of annotate()

queued, thanks

Patch

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -369,6 +369,11 @@  class annotateline(object):
     # 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 @@  def annotate(base, parents, linenumber=F
     `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