Mercurial > public > mercurial-scm > hg-stable
diff mercurial/context.py @ 34433:2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
We're going to extend this a bit -- at first by simply adding whether this was
a skipped child. We're well on our way to outgrowing tuples, though -- adding
more and more fields to tuples becomes annoying very quickly.
Differential Revision: https://phab.mercurial-scm.org/D898
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 02 Oct 2017 02:34:47 -0700 |
parents | 52e9310626a8 |
children | 2f5a135b2b04 |
line wrap: on
line diff
--- a/mercurial/context.py Mon Oct 02 02:34:47 2017 -0700 +++ b/mercurial/context.py Mon Oct 02 02:34:47 2017 -0700 @@ -25,6 +25,9 @@ wdirnodes, wdirrev, ) +from .thirdparty import ( + attr, +) from . import ( encoding, error, @@ -983,10 +986,11 @@ if linenumber: def decorate(text, rev): - return ([(rev, i) for i in xrange(1, lines(text) + 1)], text) + return ([annotateline(fctx=rev, lineno=i) + for i in xrange(1, lines(text) + 1)], text) else: def decorate(text, rev): - return ([(rev, False)] * lines(text), text) + return ([annotateline(fctx=rev)] * lines(text), text) getlog = util.lrucachefunc(lambda x: self._repo.file(x)) @@ -1103,6 +1107,11 @@ """ return self._repo.wwritedata(self.path(), self.data()) +@attr.s(slots=True, frozen=True) +class annotateline(object): + fctx = attr.ib() + lineno = attr.ib(default=False) + def _annotatepair(parents, childfctx, child, skipchild, diffopts): r''' Given parent and child fctxes and annotate data for parents, for all lines @@ -1148,7 +1157,7 @@ for (a1, a2, b1, b2), _t in blocks: if a2 - a1 >= b2 - b1: for bk in xrange(b1, b2): - if child[0][bk][0] == childfctx: + if child[0][bk].fctx == childfctx: ak = min(a1 + (bk - b1), a2 - 1) child[0][bk] = parent[0][ak] else: @@ -1159,7 +1168,7 @@ for parent, blocks in remaining: for a1, a2, b1, b2 in blocks: for bk in xrange(b1, b2): - if child[0][bk][0] == childfctx: + if child[0][bk].fctx == childfctx: ak = min(a1 + (bk - b1), a2 - 1) child[0][bk] = parent[0][ak] return child