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.
--- a/mercurial/commands.py Tue Mar 13 22:18:06 2018 +0900
+++ b/mercurial/commands.py Sun Mar 18 12:28:19 2018 +0900
@@ -396,7 +396,7 @@
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 @@
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 @@
fmt = "* %s"
else:
fmt = ": %s"
- fm.write('line', fmt, l)
-
- if not lines[-1][1].endswith('\n'):
+ fm.write('line', fmt, n.text)
+
+ if not lines[-1].text.endswith('\n'):
fm.plain('\n')
fm.end()
--- a/mercurial/context.py Tue Mar 13 22:18:06 2018 +0900
+++ b/mercurial/context.py Sun Mar 18 12:28:19 2018 +0900
@@ -968,11 +968,12 @@
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
-
- - 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
+ """Returns a list of annotateline objects for each line in the file
+
+ - 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))
--- a/mercurial/dagop.py Tue Mar 13 22:18:06 2018 +0900
+++ b/mercurial/dagop.py Sun Mar 18 12:28:19 2018 +0900
@@ -368,6 +368,7 @@
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 @@
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.
--- a/mercurial/hgweb/webcommands.py Tue Mar 13 22:18:06 2018 +0900
+++ b/mercurial/hgweb/webcommands.py Sun Mar 18 12:28:19 2018 +0900
@@ -945,13 +945,14 @@
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 @@
"blockhead": blockhead,
"blockparity": blockparity,
"targetline": aline.lineno,
- "line": l,
+ "line": aline.text,
"lineno": lineno + 1,
"lineid": "l%d" % (lineno + 1),
"linenumber": "% 6d" % (lineno + 1),