##// END OF EJS Templates
annotate: drop linenumber flag from fctx.annotate() (API)...
Yuya Nishihara -
r37083:b235bde3 default
parent child Browse files
Show More
@@ -387,8 +387,8 b' def annotate(ui, repo, *pats, **opts):'
387 continue
387 continue
388
388
389 fm = rootfm.nested('lines')
389 fm = rootfm.nested('lines')
390 lines = fctx.annotate(follow=follow, linenumber=linenumber,
390 lines = fctx.annotate(follow=follow, skiprevs=skiprevs,
391 skiprevs=skiprevs, diffopts=diffopts)
391 diffopts=diffopts)
392 if not lines:
392 if not lines:
393 fm.end()
393 fm.end()
394 continue
394 continue
@@ -967,14 +967,13 b' class basefilectx(object):'
967 return p[1]
967 return p[1]
968 return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
968 return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
969
969
970 def annotate(self, follow=False, linenumber=False, skiprevs=None,
970 def annotate(self, follow=False, skiprevs=None, diffopts=None):
971 diffopts=None):
971 """Returns a list of tuples of (attr, line) for each line in the file
972 '''returns a list of tuples of ((ctx, number), line) for each line
972
973 in the file, where ctx is the filectx of the node where
973 - attr.fctx is the filectx of the node where that line was last changed
974 that line was last changed; if linenumber parameter is true, number is
974 - attr.lineno is the line number at the first appearance in the managed
975 the line number at the first appearance in the managed file, otherwise,
975 file
976 number has a fixed value of False.
976 """
977 '''
978 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
977 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
979
978
980 def parents(f):
979 def parents(f):
@@ -1010,8 +1009,8 b' class basefilectx(object):'
1010 ac = cl.ancestors([base.rev()], inclusive=True)
1009 ac = cl.ancestors([base.rev()], inclusive=True)
1011 base._ancestrycontext = ac
1010 base._ancestrycontext = ac
1012
1011
1013 return dagop.annotate(base, parents, linenumber=linenumber,
1012 return dagop.annotate(base, parents, skiprevs=skiprevs,
1014 skiprevs=skiprevs, diffopts=diffopts)
1013 diffopts=diffopts)
1015
1014
1016 def ancestors(self, followfirst=False):
1015 def ancestors(self, followfirst=False):
1017 visit = {}
1016 visit = {}
@@ -365,7 +365,7 b' def blockdescendants(fctx, fromline, tol'
365 @attr.s(slots=True, frozen=True)
365 @attr.s(slots=True, frozen=True)
366 class annotateline(object):
366 class annotateline(object):
367 fctx = attr.ib()
367 fctx = attr.ib()
368 lineno = attr.ib(default=False)
368 lineno = attr.ib()
369 # Whether this annotation was the result of a skip-annotate.
369 # Whether this annotation was the result of a skip-annotate.
370 skip = attr.ib(default=False)
370 skip = attr.ib(default=False)
371
371
@@ -383,6 +383,11 b' def _countlines(text):'
383 return text.count("\n")
383 return text.count("\n")
384 return text.count("\n") + int(bool(text))
384 return text.count("\n") + int(bool(text))
385
385
386 def _decoratelines(text, fctx):
387 n = _countlines(text)
388 linenos = pycompat.rangelist(1, n + 1)
389 return _annotatedfile([fctx] * n, linenos, [False] * n, text)
390
386 def _annotatepair(parents, childfctx, child, skipchild, diffopts):
391 def _annotatepair(parents, childfctx, child, skipchild, diffopts):
387 r'''
392 r'''
388 Given parent and child fctxes and annotate data for parents, for all lines
393 Given parent and child fctxes and annotate data for parents, for all lines
@@ -450,22 +455,12 b' def _annotatepair(parents, childfctx, ch'
450 child.skips[bk] = True
455 child.skips[bk] = True
451 return child
456 return child
452
457
453 def annotate(base, parents, linenumber=False, skiprevs=None, diffopts=None):
458 def annotate(base, parents, skiprevs=None, diffopts=None):
454 """Core algorithm for filectx.annotate()
459 """Core algorithm for filectx.annotate()
455
460
456 `parents(fctx)` is a function returning a list of parent filectxs.
461 `parents(fctx)` is a function returning a list of parent filectxs.
457 """
462 """
458
463
459 if linenumber:
460 def decorate(text, fctx):
461 n = _countlines(text)
462 linenos = pycompat.rangelist(1, n + 1)
463 return _annotatedfile([fctx] * n, linenos, [False] * n, text)
464 else:
465 def decorate(text, fctx):
466 n = _countlines(text)
467 return _annotatedfile([fctx] * n, [False] * n, [False] * n, text)
468
469 # This algorithm would prefer to be recursive, but Python is a
464 # This algorithm would prefer to be recursive, but Python is a
470 # bit recursion-hostile. Instead we do an iterative
465 # bit recursion-hostile. Instead we do an iterative
471 # depth-first search.
466 # depth-first search.
@@ -502,7 +497,7 b' def annotate(base, parents, linenumber=F'
502 visit.append(p)
497 visit.append(p)
503 if ready:
498 if ready:
504 visit.pop()
499 visit.pop()
505 curr = decorate(f.data(), f)
500 curr = _decoratelines(f.data(), f)
506 skipchild = False
501 skipchild = False
507 if skiprevs is not None:
502 if skiprevs is not None:
508 skipchild = f._changeid in skiprevs
503 skipchild = f._changeid in skiprevs
@@ -187,7 +187,7 b' def difffeatureopts(req, ui, section):'
187
187
188 def annotate(req, fctx, ui):
188 def annotate(req, fctx, ui):
189 diffopts = difffeatureopts(req, ui, 'annotate')
189 diffopts = difffeatureopts(req, ui, 'annotate')
190 return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts)
190 return fctx.annotate(follow=True, diffopts=diffopts)
191
191
192 def parents(ctx, hide=None):
192 def parents(ctx, hide=None):
193 if isinstance(ctx, context.basefilectx):
193 if isinstance(ctx, context.basefilectx):
General Comments 0
You need to be logged in to leave comments. Login now