Mercurial > hg-stable
changeset 38030:8cc23a46df37
hgweb: convert {diff} to a mappinggenerator with named template
No more bare generator. Fortunately, this one is associated with a single
template, so it can be a mappinggenerator.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 03 Apr 2018 23:50:00 +0900 |
parents | 7a9e9fbaa559 |
children | 406f945c5814 |
files | mercurial/hgweb/webutil.py |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py Tue Apr 03 23:43:41 2018 +0900 +++ b/mercurial/hgweb/webutil.py Tue Apr 03 23:50:00 2018 +0900 @@ -537,9 +537,8 @@ 'linenumber': "% 8s" % difflineno, }) -def diffs(web, ctx, basectx, files, style, linerange=None, - lineidprefix=''): - repo = web.repo +def _diffsgen(context, repo, ctx, basectx, files, style, stripecount, + linerange, lineidprefix): if files: m = match.exact(repo.root, repo.getcwd(), files) else: @@ -548,7 +547,7 @@ diffopts = patch.diffopts(repo.ui, untrusted=True) node1 = basectx.node() node2 = ctx.node() - parity = paritygen(web.stripecount) + parity = paritygen(stripecount) diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts) for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1): @@ -565,11 +564,16 @@ l = templateutil.mappedgenerator(_prettyprintdifflines, args=(lines, blockno, lineidprefix)) - yield web.tmpl.generate('diffblock', { + yield { 'parity': next(parity), 'blockno': blockno, 'lines': l, - }) + } + +def diffs(web, ctx, basectx, files, style, linerange=None, lineidprefix=''): + args = (web.repo, ctx, basectx, files, style, web.stripecount, + linerange, lineidprefix) + return templateutil.mappinggenerator(_diffsgen, args=args, name='diffblock') def compare(tmpl, context, leftlines, rightlines): '''Generator function that provides side-by-side comparison data.'''