comparison 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
comparison
equal deleted inserted replaced
34432:52e9310626a8 34433:2e32c6a31cc7
22 nullrev, 22 nullrev,
23 short, 23 short,
24 wdirid, 24 wdirid,
25 wdirnodes, 25 wdirnodes,
26 wdirrev, 26 wdirrev,
27 )
28 from .thirdparty import (
29 attr,
27 ) 30 )
28 from . import ( 31 from . import (
29 encoding, 32 encoding,
30 error, 33 error,
31 fileset, 34 fileset,
981 return text.count("\n") 984 return text.count("\n")
982 return text.count("\n") + int(bool(text)) 985 return text.count("\n") + int(bool(text))
983 986
984 if linenumber: 987 if linenumber:
985 def decorate(text, rev): 988 def decorate(text, rev):
986 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text) 989 return ([annotateline(fctx=rev, lineno=i)
990 for i in xrange(1, lines(text) + 1)], text)
987 else: 991 else:
988 def decorate(text, rev): 992 def decorate(text, rev):
989 return ([(rev, False)] * lines(text), text) 993 return ([annotateline(fctx=rev)] * lines(text), text)
990 994
991 getlog = util.lrucachefunc(lambda x: self._repo.file(x)) 995 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
992 996
993 def parents(f): 997 def parents(f):
994 # Cut _descendantrev here to mitigate the penalty of lazy linkrev 998 # Cut _descendantrev here to mitigate the penalty of lazy linkrev
1101 1105
1102 This is often equivalent to how the data would be expressed on disk. 1106 This is often equivalent to how the data would be expressed on disk.
1103 """ 1107 """
1104 return self._repo.wwritedata(self.path(), self.data()) 1108 return self._repo.wwritedata(self.path(), self.data())
1105 1109
1110 @attr.s(slots=True, frozen=True)
1111 class annotateline(object):
1112 fctx = attr.ib()
1113 lineno = attr.ib(default=False)
1114
1106 def _annotatepair(parents, childfctx, child, skipchild, diffopts): 1115 def _annotatepair(parents, childfctx, child, skipchild, diffopts):
1107 r''' 1116 r'''
1108 Given parent and child fctxes and annotate data for parents, for all lines 1117 Given parent and child fctxes and annotate data for parents, for all lines
1109 in either parent that match the child, annotate the child with the parent's 1118 in either parent that match the child, annotate the child with the parent's
1110 data. 1119 data.
1146 remaining = [(parent, []) for parent, _blocks in pblocks] 1155 remaining = [(parent, []) for parent, _blocks in pblocks]
1147 for idx, (parent, blocks) in enumerate(pblocks): 1156 for idx, (parent, blocks) in enumerate(pblocks):
1148 for (a1, a2, b1, b2), _t in blocks: 1157 for (a1, a2, b1, b2), _t in blocks:
1149 if a2 - a1 >= b2 - b1: 1158 if a2 - a1 >= b2 - b1:
1150 for bk in xrange(b1, b2): 1159 for bk in xrange(b1, b2):
1151 if child[0][bk][0] == childfctx: 1160 if child[0][bk].fctx == childfctx:
1152 ak = min(a1 + (bk - b1), a2 - 1) 1161 ak = min(a1 + (bk - b1), a2 - 1)
1153 child[0][bk] = parent[0][ak] 1162 child[0][bk] = parent[0][ak]
1154 else: 1163 else:
1155 remaining[idx][1].append((a1, a2, b1, b2)) 1164 remaining[idx][1].append((a1, a2, b1, b2))
1156 1165
1157 # Then, look at anything left, which might involve repeating the last 1166 # Then, look at anything left, which might involve repeating the last
1158 # line. 1167 # line.
1159 for parent, blocks in remaining: 1168 for parent, blocks in remaining:
1160 for a1, a2, b1, b2 in blocks: 1169 for a1, a2, b1, b2 in blocks:
1161 for bk in xrange(b1, b2): 1170 for bk in xrange(b1, b2):
1162 if child[0][bk][0] == childfctx: 1171 if child[0][bk].fctx == childfctx:
1163 ak = min(a1 + (bk - b1), a2 - 1) 1172 ak = min(a1 + (bk - b1), a2 - 1)
1164 child[0][bk] = parent[0][ak] 1173 child[0][bk] = parent[0][ak]
1165 return child 1174 return child
1166 1175
1167 class filectx(basefilectx): 1176 class filectx(basefilectx):