mercurial/context.py
changeset 29527 576ff900fcc7
parent 29223 c04ad3d3c651
child 29827 a22b3de3b65a
child 29861 2f6d5c60f6fc
equal deleted inserted replaced
29526:9d02bed8477b 29527:576ff900fcc7
   916         p = self.parents()
   916         p = self.parents()
   917         if len(p) == 2:
   917         if len(p) == 2:
   918             return p[1]
   918             return p[1]
   919         return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
   919         return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
   920 
   920 
   921     def annotate(self, follow=False, linenumber=None, diffopts=None):
   921     def annotate(self, follow=False, linenumber=False, diffopts=None):
   922         '''returns a list of tuples of (ctx, line) for each line
   922         '''returns a list of tuples of ((ctx, number), line) for each line
   923         in the file, where ctx is the filectx of the node where
   923         in the file, where ctx is the filectx of the node where
   924         that line was last changed.
   924         that line was last changed; if linenumber parameter is true, number is
   925         This returns tuples of ((ctx, linenumber), line) for each line,
   925         the line number at the first appearance in the managed file, otherwise,
   926         if "linenumber" parameter is NOT "None".
   926         number has a fixed value of False.
   927         In such tuples, linenumber means one at the first appearance
   927         '''
   928         in the managed file.
       
   929         To reduce annotation cost,
       
   930         this returns fixed value(False is used) as linenumber,
       
   931         if "linenumber" parameter is "False".'''
       
   932 
   928 
   933         def lines(text):
   929         def lines(text):
   934             if text.endswith("\n"):
   930             if text.endswith("\n"):
   935                 return text.count("\n")
   931                 return text.count("\n")
   936             return text.count("\n") + 1
   932             return text.count("\n") + 1
   937 
   933 
   938         if linenumber is None:
   934         if linenumber:
   939             def decorate(text, rev):
       
   940                 return ([rev] * lines(text), text)
       
   941         elif linenumber:
       
   942             def decorate(text, rev):
   935             def decorate(text, rev):
   943                 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text)
   936                 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text)
   944         else:
   937         else:
   945             def decorate(text, rev):
   938             def decorate(text, rev):
   946                 return ([(rev, False)] * lines(text), text)
   939                 return ([(rev, False)] * lines(text), text)