changeset 37068:b235bde38a83

annotate: drop linenumber flag from fctx.annotate() (API) Now linenumber=True is fast enough to be enabled by default.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 13 Mar 2018 22:18:06 +0900
parents 434e520adb8c
children b33b91ca2ec2
files mercurial/commands.py mercurial/context.py mercurial/dagop.py mercurial/hgweb/webutil.py
diffstat 4 files changed, 20 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Mar 12 20:45:10 2018 +0900
+++ b/mercurial/commands.py	Tue Mar 13 22:18:06 2018 +0900
@@ -387,8 +387,8 @@
             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
--- a/mercurial/context.py	Mon Mar 12 20:45:10 2018 +0900
+++ b/mercurial/context.py	Tue Mar 13 22:18:06 2018 +0900
@@ -967,14 +967,13 @@
             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 @@
                 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 = {}
--- a/mercurial/dagop.py	Mon Mar 12 20:45:10 2018 +0900
+++ b/mercurial/dagop.py	Tue Mar 13 22:18:06 2018 +0900
@@ -365,7 +365,7 @@
 @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 @@
         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 @@
                         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 @@
                 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
--- a/mercurial/hgweb/webutil.py	Mon Mar 12 20:45:10 2018 +0900
+++ b/mercurial/hgweb/webutil.py	Tue Mar 13 22:18:06 2018 +0900
@@ -187,7 +187,7 @@
 
 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):