comparison mercurial/context.py @ 32483:f8fb8a441b4a

annotate: move pair function to top level We'll want to make this more complicated and have unit tests for it in upcoming patches.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 24 May 2017 17:38:28 -0700
parents 3e2e179ef031
children c50f29b37aab
comparison
equal deleted inserted replaced
32482:579df5aaa425 32483:f8fb8a441b4a
967 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text) 967 return ([(rev, i) for i in xrange(1, lines(text) + 1)], text)
968 else: 968 else:
969 def decorate(text, rev): 969 def decorate(text, rev):
970 return ([(rev, False)] * lines(text), text) 970 return ([(rev, False)] * lines(text), text)
971 971
972 def pair(parent, child):
973 blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts)
974 for (a1, a2, b1, b2), t in blocks:
975 # Changed blocks ('!') or blocks made only of blank lines ('~')
976 # belong to the child.
977 if t == '=':
978 child[0][b1:b2] = parent[0][a1:a2]
979 return child
980
981 getlog = util.lrucachefunc(lambda x: self._repo.file(x)) 972 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
982 973
983 def parents(f): 974 def parents(f):
984 # Cut _descendantrev here to mitigate the penalty of lazy linkrev 975 # Cut _descendantrev here to mitigate the penalty of lazy linkrev
985 # adjustment. Otherwise, p._adjustlinkrev() would walk changelog 976 # adjustment. Otherwise, p._adjustlinkrev() would walk changelog
1052 visit.append(p) 1043 visit.append(p)
1053 if ready: 1044 if ready:
1054 visit.pop() 1045 visit.pop()
1055 curr = decorate(f.data(), f) 1046 curr = decorate(f.data(), f)
1056 for p in pl: 1047 for p in pl:
1057 curr = pair(hist[p], curr) 1048 curr = _annotatepair(hist[p], curr, diffopts)
1058 if needed[p] == 1: 1049 if needed[p] == 1:
1059 del hist[p] 1050 del hist[p]
1060 del needed[p] 1051 del needed[p]
1061 else: 1052 else:
1062 needed[p] -= 1 1053 needed[p] -= 1
1079 visit[(parent.linkrev(), parent.filenode())] = parent 1070 visit[(parent.linkrev(), parent.filenode())] = parent
1080 if not visit: 1071 if not visit:
1081 break 1072 break
1082 c = visit.pop(max(visit)) 1073 c = visit.pop(max(visit))
1083 yield c 1074 yield c
1075
1076 def _annotatepair(parent, child, diffopts):
1077 blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts)
1078 for (a1, a2, b1, b2), t in blocks:
1079 # Changed blocks ('!') or blocks made only of blank lines ('~')
1080 # belong to the child.
1081 if t == '=':
1082 child[0][b1:b2] = parent[0][a1:a2]
1083 return child
1084 1084
1085 class filectx(basefilectx): 1085 class filectx(basefilectx):
1086 """A filecontext object makes access to data related to a particular 1086 """A filecontext object makes access to data related to a particular
1087 filerevision convenient.""" 1087 filerevision convenient."""
1088 def __init__(self, repo, path, changeid=None, fileid=None, 1088 def __init__(self, repo, path, changeid=None, fileid=None,