D2787: hgweb: port most @webcommand to use modern response type

2018-03-12 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG9fc3d814646e: hgweb: port most @webcommand to use modern 
response type (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2787?vs=6848=6923

REVISION DETAIL
  https://phab.mercurial-scm.org/D2787

AFFECTED FILES
  hgext/highlight/__init__.py
  mercurial/hgweb/hgweb_mod.py
  mercurial/hgweb/webcommands.py

CHANGE DETAILS

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -106,17 +106,13 @@
 
 path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', ''))
 if not path:
-content = manifest(web, req, tmpl)
-req.respond(HTTP_OK, web.ctype)
-return content
+return manifest(web, req, tmpl)
 
 try:
 fctx = webutil.filectx(web.repo, req)
 except error.LookupError as inst:
 try:
-content = manifest(web, req, tmpl)
-req.respond(HTTP_OK, web.ctype)
-return content
+return manifest(web, req, tmpl)
 except ErrorResponse:
 raise inst
 
@@ -133,8 +129,12 @@
 if mt.startswith('text/'):
 mt += '; charset="%s"' % encoding.encoding
 
-req.respond(HTTP_OK, mt, path, body=text)
-return []
+web.res.headers['Content-Type'] = mt
+filename = (path.rpartition('/')[-1]
+.replace('\\', '').replace('"', '\\"'))
+web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
+web.res.setbodybytes(text)
+return web.res
 
 def _filerevision(web, req, tmpl, fctx):
 f = fctx.path()
@@ -153,15 +153,18 @@
"linenumber": "% 6d" % (lineno + 1),
"parity": next(parity)}
 
-return tmpl("filerevision",
-file=f,
-path=webutil.up(f),
-text=lines(),
-symrev=webutil.symrevorshortnode(req, fctx),
-rename=webutil.renamelink(fctx),
-permissions=fctx.manifest().flags(f),
-ishead=int(ishead),
-**pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
+web.res.setbodygen(tmpl(
+'filerevision',
+file=f,
+path=webutil.up(f),
+text=lines(),
+symrev=webutil.symrevorshortnode(req, fctx),
+rename=webutil.renamelink(fctx),
+permissions=fctx.manifest().flags(f),
+ishead=int(ishead),
+**pycompat.strkwargs(webutil.commonentry(web.repo, fctx
+
+return web.res
 
 @webcommand('file')
 def file(web, req, tmpl):
@@ -335,11 +338,20 @@
 tip = web.repo['tip']
 parity = paritygen(web.stripecount)
 
-return tmpl('search', query=query, node=tip.hex(), symrev='tip',
-entries=changelist, archives=web.archivelist("tip"),
-morevars=morevars, lessvars=lessvars,
-modedesc=searchfunc[1],
-showforcekw=showforcekw, showunforcekw=showunforcekw)
+web.res.setbodygen(tmpl(
+'search',
+query=query,
+node=tip.hex(),
+symrev='tip',
+entries=changelist,
+archives=web.archivelist('tip'),
+morevars=morevars,
+lessvars=lessvars,
+modedesc=searchfunc[1],
+showforcekw=showforcekw,
+showunforcekw=showunforcekw))
+
+return web.res
 
 @webcommand('changelog')
 def changelog(web, req, tmpl, shortlog=False):
@@ -423,12 +435,23 @@
 else:
 nextentry = []
 
-return tmpl('shortlog' if shortlog else 'changelog', changenav=changenav,
-node=ctx.hex(), rev=pos, symrev=symrev, changesets=count,
-entries=entries,
-latestentry=latestentry, nextentry=nextentry,
-archives=web.archivelist("tip"), revcount=revcount,
-morevars=morevars, lessvars=lessvars, query=query)
+web.res.setbodygen(tmpl(
+'shortlog' if shortlog else 'changelog',
+changenav=changenav,
+node=ctx.hex(),
+rev=pos,
+symrev=symrev,
+changesets=count,
+entries=entries,
+latestentry=latestentry,
+nextentry=nextentry,
+archives=web.archivelist('tip'),
+revcount=revcount,
+morevars=morevars,
+lessvars=lessvars,
+query=query))
+
+return web.res
 
 @webcommand('shortlog')
 def shortlog(web, req, tmpl):
@@ -461,8 +484,9 @@
 templates related to diffs may all be used to produce the output.
 """
 ctx = webutil.changectx(web.repo, req)
-
-return tmpl('changeset', **webutil.changesetentry(web, req, tmpl, ctx))
+web.res.setbodygen(tmpl('changeset',
+**webutil.changesetentry(web, req, tmpl, ctx)))
+return web.res
 
 rev = webcommand('rev')(changeset)
 
@@ -563,15 +587,18 @@

D2787: hgweb: port most @webcommand to use modern response type

2018-03-10 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This only focused on porting the return value.
  
  raw file requests are wonky because they go through a separate code
  path at the dispatch layer. Now that everyone is using the same
  API, we could clean this up.
  
  It's worth noting that wsgirequest.respond() allows sending the
  Content-Disposition header, but the only user of that feature was
  removed as part of this change (with the setting of the header
  now being performed inline).
  
  A few @webcommand are not as straightforward as the others and
  they have not been ported yet.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2787

AFFECTED FILES
  hgext/highlight/__init__.py
  mercurial/hgweb/hgweb_mod.py
  mercurial/hgweb/webcommands.py

CHANGE DETAILS

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -106,17 +106,13 @@
 
 path = webutil.cleanpath(web.repo, req.req.qsparams.get('file', ''))
 if not path:
-content = manifest(web, req, tmpl)
-req.respond(HTTP_OK, web.ctype)
-return content
+return manifest(web, req, tmpl)
 
 try:
 fctx = webutil.filectx(web.repo, req)
 except error.LookupError as inst:
 try:
-content = manifest(web, req, tmpl)
-req.respond(HTTP_OK, web.ctype)
-return content
+return manifest(web, req, tmpl)
 except ErrorResponse:
 raise inst
 
@@ -133,8 +129,12 @@
 if mt.startswith('text/'):
 mt += '; charset="%s"' % encoding.encoding
 
-req.respond(HTTP_OK, mt, path, body=text)
-return []
+web.res.headers['Content-Type'] = mt
+filename = (path.rpartition('/')[-1]
+.replace('\\', '').replace('"', '\\"'))
+web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
+web.res.setbodybytes(text)
+return web.res
 
 def _filerevision(web, req, tmpl, fctx):
 f = fctx.path()
@@ -153,15 +153,18 @@
"linenumber": "% 6d" % (lineno + 1),
"parity": next(parity)}
 
-return tmpl("filerevision",
-file=f,
-path=webutil.up(f),
-text=lines(),
-symrev=webutil.symrevorshortnode(req, fctx),
-rename=webutil.renamelink(fctx),
-permissions=fctx.manifest().flags(f),
-ishead=int(ishead),
-**pycompat.strkwargs(webutil.commonentry(web.repo, fctx)))
+web.res.setbodygen(tmpl(
+'filerevision',
+file=f,
+path=webutil.up(f),
+text=lines(),
+symrev=webutil.symrevorshortnode(req, fctx),
+rename=webutil.renamelink(fctx),
+permissions=fctx.manifest().flags(f),
+ishead=int(ishead),
+**pycompat.strkwargs(webutil.commonentry(web.repo, fctx
+
+return web.res
 
 @webcommand('file')
 def file(web, req, tmpl):
@@ -335,11 +338,20 @@
 tip = web.repo['tip']
 parity = paritygen(web.stripecount)
 
-return tmpl('search', query=query, node=tip.hex(), symrev='tip',
-entries=changelist, archives=web.archivelist("tip"),
-morevars=morevars, lessvars=lessvars,
-modedesc=searchfunc[1],
-showforcekw=showforcekw, showunforcekw=showunforcekw)
+web.res.setbodygen(tmpl(
+'search',
+query=query,
+node=tip.hex(),
+symrev='tip',
+entries=changelist,
+archives=web.archivelist('tip'),
+morevars=morevars,
+lessvars=lessvars,
+modedesc=searchfunc[1],
+showforcekw=showforcekw,
+showunforcekw=showunforcekw))
+
+return web.res
 
 @webcommand('changelog')
 def changelog(web, req, tmpl, shortlog=False):
@@ -423,12 +435,23 @@
 else:
 nextentry = []
 
-return tmpl('shortlog' if shortlog else 'changelog', changenav=changenav,
-node=ctx.hex(), rev=pos, symrev=symrev, changesets=count,
-entries=entries,
-latestentry=latestentry, nextentry=nextentry,
-archives=web.archivelist("tip"), revcount=revcount,
-morevars=morevars, lessvars=lessvars, query=query)
+web.res.setbodygen(tmpl(
+'shortlog' if shortlog else 'changelog',
+changenav=changenav,
+node=ctx.hex(),
+rev=pos,
+symrev=symrev,
+changesets=count,
+entries=entries,
+latestentry=latestentry,
+nextentry=nextentry,
+archives=web.archivelist('tip'),
+revcount=revcount,
+morevars=morevars,
+lessvars=lessvars,
+query=query))
+
+return web.res
 
 @webcommand('shortlog')
 def shortlog(web, req, tmpl):
@@ -461,8 +484,9 @@
 templates related to