[PATCH 4 of 4] annotate: drop linenumber flag from fctx.annotate() (API)

Yuya Nishihara yuya at tcha.org
Tue Mar 13 09:55:12 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1520947086 -32400
#      Tue Mar 13 22:18:06 2018 +0900
# Node ID 854d59569873317764fb7ff68b7f0051585caed6
# Parent  1ce0d903cfa6e8db0112f86cc346751651db1f80
annotate: drop linenumber flag from fctx.annotate() (API)

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

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
@@ -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
@@ -186,7 +186,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):


More information about the Mercurial-devel mailing list