Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dagop.py @ 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 |
line wrap: on
line diff
--- 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