Patchwork [2,of,3,V2] annotate: drop linenumber flag from fctx.annotate() (API)

login
register
mail settings
Submitter Yuya Nishihara
Date March 18, 2018, 3:45 a.m.
Message ID <edba0c7df0a076dc3838.1521344733@mimosa>
Download mbox | patch
Permalink /patch/29590/
State Accepted
Headers show

Comments

Yuya Nishihara - March 18, 2018, 3:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520947086 -32400
#      Tue Mar 13 22:18:06 2018 +0900
# Node ID edba0c7df0a076dc383824f39c3ec16a0849b189
# Parent  2d8154d8b27e0452aee52f45d48370c7ca9f837b
annotate: drop linenumber flag from fctx.annotate() (API)

Now linenumber=True is fast enough to be enabled by default.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -387,8 +387,8 @@  def annotate(ui, repo, *pats, **opts):
             continue
 
         fm = rootfm.nested('lines')
-        lines = fctx.annotate(follow=follow, linenumber=linenumber,
-                              skiprevs=skiprevs, diffopts=diffopts)
+        lines = fctx.annotate(follow=follow, skiprevs=skiprevs,
+                              diffopts=diffopts)
         if not lines:
             fm.end()
             continue
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -967,14 +967,13 @@  class basefilectx(object):
             return p[1]
         return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
 
-    def annotate(self, follow=False, linenumber=False, skiprevs=None,
-                 diffopts=None):
-        '''returns a list of tuples of ((ctx, number), line) for each line
-        in the file, where ctx is the filectx of the node where
-        that line was last changed; if linenumber parameter is true, number is
-        the line number at the first appearance in the managed file, otherwise,
-        number has a fixed value of False.
-        '''
+    def annotate(self, follow=False, skiprevs=None, diffopts=None):
+        """Returns a list of tuples of (attr, line) for each line in the file
+
+        - attr.fctx is the filectx of the node where that line was last changed
+        - attr.lineno is the line number at the first appearance in the managed
+          file
+        """
         getlog = util.lrucachefunc(lambda x: self._repo.file(x))
 
         def parents(f):
@@ -1010,8 +1009,8 @@  class basefilectx(object):
                 ac = cl.ancestors([base.rev()], inclusive=True)
             base._ancestrycontext = ac
 
-        return dagop.annotate(base, parents, linenumber=linenumber,
-                              skiprevs=skiprevs, diffopts=diffopts)
+        return dagop.annotate(base, parents, skiprevs=skiprevs,
+                              diffopts=diffopts)
 
     def ancestors(self, followfirst=False):
         visit = {}
diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -365,7 +365,7 @@  def blockdescendants(fctx, fromline, tol
 @attr.s(slots=True, frozen=True)
 class annotateline(object):
     fctx = attr.ib()
-    lineno = attr.ib(default=False)
+    lineno = attr.ib()
     # Whether this annotation was the result of a skip-annotate.
     skip = attr.ib(default=False)
 
@@ -383,6 +383,11 @@  def _countlines(text):
         return text.count("\n")
     return text.count("\n") + int(bool(text))
 
+def _decoratelines(text, fctx):
+    n = _countlines(text)
+    linenos = pycompat.rangelist(1, n + 1)
+    return _annotatedfile([fctx] * n, linenos, [False] * n, text)
+
 def _annotatepair(parents, childfctx, child, skipchild, diffopts):
     r'''
     Given parent and child fctxes and annotate data for parents, for all lines
@@ -450,22 +455,12 @@  def _annotatepair(parents, childfctx, ch
                         child.skips[bk] = True
     return child
 
-def annotate(base, parents, linenumber=False, skiprevs=None, diffopts=None):
+def annotate(base, parents, skiprevs=None, diffopts=None):
     """Core algorithm for filectx.annotate()
 
     `parents(fctx)` is a function returning a list of parent filectxs.
     """
 
-    if linenumber:
-        def decorate(text, fctx):
-            n = _countlines(text)
-            linenos = pycompat.rangelist(1, n + 1)
-            return _annotatedfile([fctx] * n, linenos, [False] * n, text)
-    else:
-        def decorate(text, fctx):
-            n = _countlines(text)
-            return _annotatedfile([fctx] * n, [False] * n, [False] * n, text)
-
     # This algorithm would prefer to be recursive, but Python is a
     # bit recursion-hostile. Instead we do an iterative
     # depth-first search.
@@ -502,7 +497,7 @@  def annotate(base, parents, linenumber=F
                 visit.append(p)
         if ready:
             visit.pop()
-            curr = decorate(f.data(), f)
+            curr = _decoratelines(f.data(), f)
             skipchild = False
             if skiprevs is not None:
                 skipchild = f._changeid in skiprevs
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -187,7 +187,7 @@  def difffeatureopts(req, ui, section):
 
 def annotate(req, fctx, ui):
     diffopts = difffeatureopts(req, ui, 'annotate')
-    return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts)
+    return fctx.annotate(follow=True, diffopts=diffopts)
 
 def parents(ctx, hide=None):
     if isinstance(ctx, context.basefilectx):