comparison mercurial/context.py @ 4846:e45c5120ca27

Allow filectx.annotate to return the line number of first appearance.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 08 Jul 2007 19:46:04 +0200
parents 8808ea7da86b
children 3b081f2a77b2
comparison
equal deleted inserted replaced
4845:e4480f2b61e9 4846:e45c5120ca27
238 # hard for renames 238 # hard for renames
239 c = self._filelog.children(self._filenode) 239 c = self._filelog.children(self._filenode)
240 return [filectx(self._repo, self._path, fileid=x, 240 return [filectx(self._repo, self._path, fileid=x,
241 filelog=self._filelog) for x in c] 241 filelog=self._filelog) for x in c]
242 242
243 def annotate(self, follow=False): 243 def annotate(self, follow=False, linenumber=None):
244 '''returns a list of tuples of (ctx, line) for each line 244 '''returns a list of tuples of (ctx, line) for each line
245 in the file, where ctx is the filectx of the node where 245 in the file, where ctx is the filectx of the node where
246 that line was last changed''' 246 that line was last changed.
247 247 This returns tuples of ((ctx, linenumber), line) for each line,
248 def decorate(text, rev): 248 if "linenumber" parameter is NOT "None".
249 In such tuples, linenumber means one at the first appearance
250 in the managed file.
251 To reduce annotation cost,
252 this returns fixed value(False is used) as linenumber,
253 if "linenumber" parameter is "False".'''
254
255 def decorate_compat(text, rev):
249 return ([rev] * len(text.splitlines()), text) 256 return ([rev] * len(text.splitlines()), text)
257
258 def without_linenumber(text, rev):
259 return ([(rev, False)] * len(text.splitlines()), text)
260
261 def with_linenumber(text, rev):
262 size = len(text.splitlines())
263 return ([(rev, i) for i in xrange(1, size + 1)], text)
264
265 decorate = (((linenumber is None) and decorate_compat) or
266 (linenumber and with_linenumber) or
267 without_linenumber)
250 268
251 def pair(parent, child): 269 def pair(parent, child):
252 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): 270 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]):
253 child[0][b1:b2] = parent[0][a1:a2] 271 child[0][b1:b2] = parent[0][a1:a2]
254 return child 272 return child