Submitter | Yuya Nishihara |
---|---|
Date | May 12, 2018, 3:35 a.m. |
Message ID | <093cd239abcc1a6a79e8.1526096108@mimosa> |
Download | mbox | patch |
Permalink | /patch/31531/ |
State | Accepted |
Headers | show |
Comments
On Fri, May 11, 2018 at 8:35 PM, Yuya Nishihara <yuya@tcha.org> wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1522766299 -32400 > # Tue Apr 03 23:38:19 2018 +0900 > # Node ID 093cd239abcc1a6a79e80f03f3536df427753ebe > # Parent b9e6b71dc27246d1f4d6437edfdc9788188aa306 > hgweb: move prettyprintlines() closure out of diffs() > > This will be wrapped with mappedgenerator. > Queued this series. Thanks for the continued cleanups in hgweb and in the templating system! > > diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py > --- a/mercurial/hgweb/webutil.py > +++ b/mercurial/hgweb/webutil.py > @@ -519,27 +519,26 @@ def listfilediffs(files, node, max): > return templateutil.mappedgenerator(_listfilediffsgen, > args=(files, node, max)) > > +def _prettyprintdifflines(tmpl, lines, blockno, lineidprefix): > + for lineno, l in enumerate(lines, 1): > + difflineno = "%d.%d" % (blockno, lineno) > + if l.startswith('+'): > + ltype = "difflineplus" > + elif l.startswith('-'): > + ltype = "difflineminus" > + elif l.startswith('@'): > + ltype = "difflineat" > + else: > + ltype = "diffline" > + yield tmpl.generate(ltype, { > + 'line': l, > + 'lineno': lineno, > + 'lineid': lineidprefix + "l%s" % difflineno, > + 'linenumber': "% 8s" % difflineno, > + }) > + > def diffs(web, ctx, basectx, files, style, linerange=None, > lineidprefix=''): > - > - def prettyprintlines(lines, blockno): > - for lineno, l in enumerate(lines, 1): > - difflineno = "%d.%d" % (blockno, lineno) > - if l.startswith('+'): > - ltype = "difflineplus" > - elif l.startswith('-'): > - ltype = "difflineminus" > - elif l.startswith('@'): > - ltype = "difflineat" > - else: > - ltype = "diffline" > - yield web.tmpl.generate(ltype, { > - 'line': l, > - 'lineno': lineno, > - 'lineid': lineidprefix + "l%s" % difflineno, > - 'linenumber': "% 8s" % difflineno, > - }) > - > repo = web.repo > if files: > m = match.exact(repo.root, repo.getcwd(), files) > @@ -566,7 +565,8 @@ def diffs(web, ctx, basectx, files, styl > yield web.tmpl.generate('diffblock', { > 'parity': next(parity), > 'blockno': blockno, > - 'lines': prettyprintlines(lines, blockno), > + 'lines': _prettyprintdifflines(web.tmpl, lines, blockno, > + lineidprefix), > }) > > def compare(tmpl, context, leftlines, rightlines): > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel >
Patch
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -519,27 +519,26 @@ def listfilediffs(files, node, max): return templateutil.mappedgenerator(_listfilediffsgen, args=(files, node, max)) +def _prettyprintdifflines(tmpl, lines, blockno, lineidprefix): + for lineno, l in enumerate(lines, 1): + difflineno = "%d.%d" % (blockno, lineno) + if l.startswith('+'): + ltype = "difflineplus" + elif l.startswith('-'): + ltype = "difflineminus" + elif l.startswith('@'): + ltype = "difflineat" + else: + ltype = "diffline" + yield tmpl.generate(ltype, { + 'line': l, + 'lineno': lineno, + 'lineid': lineidprefix + "l%s" % difflineno, + 'linenumber': "% 8s" % difflineno, + }) + def diffs(web, ctx, basectx, files, style, linerange=None, lineidprefix=''): - - def prettyprintlines(lines, blockno): - for lineno, l in enumerate(lines, 1): - difflineno = "%d.%d" % (blockno, lineno) - if l.startswith('+'): - ltype = "difflineplus" - elif l.startswith('-'): - ltype = "difflineminus" - elif l.startswith('@'): - ltype = "difflineat" - else: - ltype = "diffline" - yield web.tmpl.generate(ltype, { - 'line': l, - 'lineno': lineno, - 'lineid': lineidprefix + "l%s" % difflineno, - 'linenumber': "% 8s" % difflineno, - }) - repo = web.repo if files: m = match.exact(repo.root, repo.getcwd(), files) @@ -566,7 +565,8 @@ def diffs(web, ctx, basectx, files, styl yield web.tmpl.generate('diffblock', { 'parity': next(parity), 'blockno': blockno, - 'lines': prettyprintlines(lines, blockno), + 'lines': _prettyprintdifflines(web.tmpl, lines, blockno, + lineidprefix), }) def compare(tmpl, context, leftlines, rightlines):