[PATCH 1 of 2] context: eliminate handling of linenumber being None in annotate

Denis Laxalde denis.laxalde at logilab.fr
Wed Jul 13 05:08:15 EDT 2016


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1468241059 -7200
#      Mon Jul 11 14:44:19 2016 +0200
# Node ID 969b3f54ffa50a3fc3348bb645700e647893a0e8
# Parent  4b16a5bd99484cac96ade9af76e6deee1fc57b54
context: eliminate handling of linenumber being None in annotate

I could not find any use of this parameter value. And it arguably makes
understanding of the function more difficult. Setting the parameter default
value to False.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -918,27 +918,20 @@ class basefilectx(object):
             return p[1]
         return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
 
-    def annotate(self, follow=False, linenumber=None, diffopts=None):
-        '''returns a list of tuples of (ctx, line) for each line
+    def annotate(self, follow=False, linenumber=False, 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.
-        This returns tuples of ((ctx, linenumber), line) for each line,
-        if "linenumber" parameter is NOT "None".
-        In such tuples, linenumber means one at the first appearance
-        in the managed file.
-        To reduce annotation cost,
-        this returns fixed value(False is used) as linenumber,
-        if "linenumber" parameter is "False".'''
+        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 lines(text):
             if text.endswith("\n"):
                 return text.count("\n")
             return text.count("\n") + 1
 
-        if linenumber is None:
-            def decorate(text, rev):
-                return ([rev] * lines(text), text)
-        elif linenumber:
+        if linenumber:
             def decorate(text, rev):
                 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text)
         else:


More information about the Mercurial-devel mailing list