Commit fb73e362 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

annotate: pack line content into annotateline object (API)

Just for code readability. We can do that since the annotateline type is
no longer used while computing the history.
parent b235bde38a83
......@@ -396,7 +396,7 @@ def annotate(ui, repo, *pats, **opts):
pieces = []
for f, sep in funcmap:
l = [f(n) for n, dummy in lines]
l = [f(n) for n in lines]
if fm.isplain():
sizes = [encoding.colwidth(x) for x in l]
ml = max(sizes)
......@@ -405,7 +405,7 @@ def annotate(ui, repo, *pats, **opts):
formats.append(['%s' for x in l])
pieces.append(l)
for f, p, (n, l) in zip(zip(*formats), zip(*pieces), lines):
for f, p, n in zip(zip(*formats), zip(*pieces), lines):
fm.startitem()
fm.context(fctx=n.fctx)
fm.write(fields, "".join(f), *p)
......@@ -413,9 +413,9 @@ def annotate(ui, repo, *pats, **opts):
fmt = "* %s"
else:
fmt = ": %s"
fm.write('line', fmt, l)
fm.write('line', fmt, n.text)
if not lines[-1][1].endswith('\n'):
if not lines[-1].text.endswith('\n'):
fm.plain('\n')
fm.end()
......
......@@ -968,11 +968,12 @@ class basefilectx(object):
return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
def annotate(self, follow=False, skiprevs=None, diffopts=None):
"""Returns a list of tuples of (attr, line) for each line in the file
"""Returns a list of annotateline objects for each line in the file
- attr.fctx is the filectx of the node where that line was last changed
- attr.lineno is the line number at the first appearance in the managed
- line.fctx is the filectx of the node where that line was last changed
- line.lineno is the line number at the first appearance in the managed
file
- line.text is the data on that line (including newline character)
"""
getlog = util.lrucachefunc(lambda x: self._repo.file(x))
......
......@@ -368,6 +368,7 @@ class annotateline(object):
lineno = attr.ib()
# Whether this annotation was the result of a skip-annotate.
skip = attr.ib(default=False)
text = attr.ib(default=None)
@attr.s(slots=True, frozen=True)
class _annotatedfile(object):
......@@ -514,9 +515,8 @@ def annotate(base, parents, skiprevs=None, diffopts=None):
del pcache[f]
a = hist[base]
return [(annotateline(fctx, lineno, skip), line)
for fctx, lineno, skip, line
in zip(a.fctxs, a.linenos, a.skips, mdiff.splitnewlines(a.text))]
return [annotateline(*r) for r in zip(a.fctxs, a.linenos, a.skips,
mdiff.splitnewlines(a.text))]
def toposort(revs, parentsfunc, firstbranch=()):
"""Yield revisions from heads to roots one (topo) branch at a time.
......
......@@ -945,13 +945,14 @@ def annotate(web):
if fctx.isbinary():
mt = (mimetypes.guess_type(fctx.path())[0]
or 'application/octet-stream')
lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
lines = [dagop.annotateline(fctx=fctx.filectx(fctx.filerev()),
lineno=1, text='(binary:%s)' % mt)]
else:
lines = webutil.annotate(web.req, fctx, web.repo.ui)
previousrev = None
blockparitygen = paritygen(1)
for lineno, (aline, l) in enumerate(lines):
for lineno, aline in enumerate(lines):
f = aline.fctx
rev = f.rev()
if rev != previousrev:
......@@ -971,7 +972,7 @@ def annotate(web):
"blockhead": blockhead,
"blockparity": blockparity,
"targetline": aline.lineno,
"line": l,
"line": aline.text,
"lineno": lineno + 1,
"lineid": "l%d" % (lineno + 1),
"linenumber": "% 6d" % (lineno + 1),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment