changeset 36892:563fd95a6efb

hgweb: pass modern request type into various webutil functions (API) Our march towards killing wsgirequest continues. .. api:: Various functions in hgweb.webutil now take a modern request object instead of ``wsgirequest``. Differential Revision: https://phab.mercurial-scm.org/D2802
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 19:57:08 -0800
parents c68e79dcf21c
children 4daa22071d5d
files hgext/highlight/__init__.py mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py
diffstat 3 files changed, 47 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/highlight/__init__.py	Sat Mar 10 19:46:54 2018 -0800
+++ b/hgext/highlight/__init__.py	Sat Mar 10 19:57:08 2018 -0800
@@ -75,7 +75,7 @@
 def annotate_highlight(orig, web, req, tmpl):
     mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
     if 'html' in mt:
-        fctx = webutil.filectx(web.repo, req)
+        fctx = webutil.filectx(web.repo, web.req)
         pygmentize(web, 'annotateline', fctx, web.tmpl)
 
     return orig(web, req, web.tmpl)
--- a/mercurial/hgweb/webcommands.py	Sat Mar 10 19:46:54 2018 -0800
+++ b/mercurial/hgweb/webcommands.py	Sat Mar 10 19:57:08 2018 -0800
@@ -108,7 +108,7 @@
         return manifest(web, req, None)
 
     try:
-        fctx = webutil.filectx(web.repo, req)
+        fctx = webutil.filectx(web.repo, web.req)
     except error.LookupError as inst:
         try:
             return manifest(web, req, None)
@@ -157,7 +157,7 @@
         file=f,
         path=webutil.up(f),
         text=lines(),
-        symrev=webutil.symrevorshortnode(req, fctx),
+        symrev=webutil.symrevorshortnode(web.req, fctx),
         rename=webutil.renamelink(fctx),
         permissions=fctx.manifest().flags(f),
         ishead=int(ishead),
@@ -190,7 +190,7 @@
     if not path:
         return manifest(web, req, None)
     try:
-        return _filerevision(web, req, webutil.filectx(web.repo, req))
+        return _filerevision(web, req, webutil.filectx(web.repo, web.req))
     except error.LookupError as inst:
         try:
             return manifest(web, req, None)
@@ -381,8 +381,8 @@
 
     query = ''
     if 'node' in web.req.qsparams:
-        ctx = webutil.changectx(web.repo, req)
-        symrev = webutil.symrevorshortnode(req, ctx)
+        ctx = webutil.changectx(web.repo, web.req)
+        symrev = webutil.symrevorshortnode(web.req, ctx)
     elif 'rev' in web.req.qsparams:
         return _search(web)
     else:
@@ -481,11 +481,11 @@
     ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many
     templates related to diffs may all be used to produce the output.
     """
-    ctx = webutil.changectx(web.repo, req)
+    ctx = webutil.changectx(web.repo, web.req)
 
     return web.sendtemplate(
         'changeset',
-        **webutil.changesetentry(web, req, ctx))
+        **webutil.changesetentry(web, ctx))
 
 rev = webcommand('rev')(changeset)
 
@@ -515,8 +515,8 @@
     The ``manifest`` template will be rendered for this handler.
     """
     if 'node' in web.req.qsparams:
-        ctx = webutil.changectx(web.repo, req)
-        symrev = webutil.symrevorshortnode(req, ctx)
+        ctx = webutil.changectx(web.repo, web.req)
+        symrev = webutil.symrevorshortnode(web.req, ctx)
     else:
         ctx = web.repo['tip']
         symrev = 'tip'
@@ -792,9 +792,9 @@
     """
     fctx, ctx = None, None
     try:
-        fctx = webutil.filectx(web.repo, req)
+        fctx = webutil.filectx(web.repo, web.req)
     except LookupError:
-        ctx = webutil.changectx(web.repo, req)
+        ctx = webutil.changectx(web.repo, web.req)
         path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
         if path not in ctx.files():
             raise
@@ -819,7 +819,7 @@
     return web.sendtemplate(
         'filediff',
         file=path,
-        symrev=webutil.symrevorshortnode(req, ctx),
+        symrev=webutil.symrevorshortnode(web.req, ctx),
         rename=rename,
         diff=diffs,
         **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))
@@ -843,7 +843,7 @@
 
     The ``filecomparison`` template is rendered.
     """
-    ctx = webutil.changectx(web.repo, req)
+    ctx = webutil.changectx(web.repo, web.req)
     if 'file' not in web.req.qsparams:
         raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
     path = webutil.cleanpath(web.repo, web.req.qsparams['file'])
@@ -892,7 +892,7 @@
     return web.sendtemplate(
         'filecomparison',
         file=path,
-        symrev=webutil.symrevorshortnode(req, ctx),
+        symrev=webutil.symrevorshortnode(web.req, ctx),
         rename=rename,
         leftrev=leftrev,
         leftnode=hex(leftnode),
@@ -918,7 +918,7 @@
 
     The ``fileannotate`` template is rendered.
     """
-    fctx = webutil.filectx(web.repo, req)
+    fctx = webutil.filectx(web.repo, web.req)
     f = fctx.path()
     parity = paritygen(web.stripecount)
     ishead = fctx.filerev() in fctx.filelog().headrevs()
@@ -948,7 +948,7 @@
                   or 'application/octet-stream')
             lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
         else:
-            lines = webutil.annotate(req, fctx, web.repo.ui)
+            lines = webutil.annotate(web.req, fctx, web.repo.ui)
 
         previousrev = None
         blockparitygen = paritygen(1)
@@ -978,7 +978,7 @@
                    "linenumber": "% 6d" % (lineno + 1),
                    "revdate": f.date()}
 
-    diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate')
+    diffopts = webutil.difffeatureopts(web.req, web.repo.ui, 'annotate')
     diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults}
 
     return web.sendtemplate(
@@ -986,7 +986,7 @@
         file=f,
         annotate=annotate,
         path=webutil.up(f),
-        symrev=webutil.symrevorshortnode(req, fctx),
+        symrev=webutil.symrevorshortnode(web.req, fctx),
         rename=webutil.renamelink(fctx),
         permissions=fctx.manifest().flags(f),
         ishead=int(ishead),
@@ -1008,7 +1008,7 @@
     """
 
     try:
-        fctx = webutil.filectx(web.repo, req)
+        fctx = webutil.filectx(web.repo, web.req)
         f = fctx.path()
         fl = fctx.filelog()
     except error.LookupError:
@@ -1017,7 +1017,7 @@
         numrevs = len(fl)
         if not numrevs: # file doesn't exist at all
             raise
-        rev = webutil.changectx(web.repo, req).rev()
+        rev = webutil.changectx(web.repo, web.req).rev()
         first = fl.linkrev(0)
         if rev < first: # current rev is from before file existed
             raise
@@ -1035,7 +1035,7 @@
         except ValueError:
             pass
 
-    lrange = webutil.linerange(req)
+    lrange = webutil.linerange(web.req)
 
     lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
     lessvars['revcount'] = max(revcount // 2, 1)
@@ -1120,7 +1120,7 @@
         'filelog',
         file=f,
         nav=nav,
-        symrev=webutil.symrevorshortnode(req, fctx),
+        symrev=webutil.symrevorshortnode(web.req, fctx),
         entries=entries,
         descend=descend,
         patch=patch,
@@ -1172,7 +1172,7 @@
         arch_version = short(cnode)
     name = "%s-%s" % (reponame, arch_version)
 
-    ctx = webutil.changectx(web.repo, req)
+    ctx = webutil.changectx(web.repo, web.req)
     pats = []
     match = scmutil.match(ctx, [])
     file = web.req.qsparams.get('file')
@@ -1245,8 +1245,8 @@
     """
 
     if 'node' in web.req.qsparams:
-        ctx = webutil.changectx(web.repo, req)
-        symrev = webutil.symrevorshortnode(req, ctx)
+        ctx = webutil.changectx(web.repo, web.req)
+        symrev = webutil.symrevorshortnode(web.req, ctx)
     else:
         ctx = web.repo['tip']
         symrev = 'tip'
--- a/mercurial/hgweb/webutil.py	Sat Mar 10 19:46:54 2018 -0800
+++ b/mercurial/hgweb/webutil.py	Sat Mar 10 19:57:08 2018 -0800
@@ -177,7 +177,7 @@
                                      section=section, whitespace=True)
 
     for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
-        v = req.req.qsparams.get(k)
+        v = req.qsparams.get(k)
         if v is not None:
             v = util.parsebool(v)
             setattr(diffopts, k, v if v is not None else True)
@@ -295,19 +295,19 @@
 
 def changectx(repo, req):
     changeid = "tip"
-    if 'node' in req.req.qsparams:
-        changeid = req.req.qsparams['node']
+    if 'node' in req.qsparams:
+        changeid = req.qsparams['node']
         ipos = changeid.find(':')
         if ipos != -1:
             changeid = changeid[(ipos + 1):]
-    elif 'manifest' in req.req.qsparams:
-        changeid = req.req.qsparams['manifest']
+    elif 'manifest' in req.qsparams:
+        changeid = req.qsparams['manifest']
 
     return changeidctx(repo, changeid)
 
 def basechangectx(repo, req):
-    if 'node' in req.req.qsparams:
-        changeid = req.req.qsparams['node']
+    if 'node' in req.qsparams:
+        changeid = req.qsparams['node']
         ipos = changeid.find(':')
         if ipos != -1:
             changeid = changeid[:ipos]
@@ -316,13 +316,13 @@
     return None
 
 def filectx(repo, req):
-    if 'file' not in req.req.qsparams:
+    if 'file' not in req.qsparams:
         raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
-    path = cleanpath(repo, req.req.qsparams['file'])
-    if 'node' in req.req.qsparams:
-        changeid = req.req.qsparams['node']
-    elif 'filenode' in req.req.qsparams:
-        changeid = req.req.qsparams['filenode']
+    path = cleanpath(repo, req.qsparams['file'])
+    if 'node' in req.qsparams:
+        changeid = req.qsparams['node']
+    elif 'filenode' in req.qsparams:
+        changeid = req.qsparams['filenode']
     else:
         raise ErrorResponse(HTTP_NOT_FOUND, 'node or filenode not given')
     try:
@@ -333,7 +333,7 @@
     return fctx
 
 def linerange(req):
-    linerange = req.req.qsparams.getall('linerange')
+    linerange = req.qsparams.getall('linerange')
     if not linerange:
         return None
     if len(linerange) > 1:
@@ -412,12 +412,12 @@
     return entry
 
 def symrevorshortnode(req, ctx):
-    if 'node' in req.req.qsparams:
-        return templatefilters.revescape(req.req.qsparams['node'])
+    if 'node' in req.qsparams:
+        return templatefilters.revescape(req.qsparams['node'])
     else:
         return short(ctx.node())
 
-def changesetentry(web, req, ctx):
+def changesetentry(web, ctx):
     '''Obtain a dictionary to be used to render the "changeset" template.'''
 
     showtags = showtag(web.repo, web.tmpl, 'changesettag', ctx.node())
@@ -433,13 +433,13 @@
                               node=ctx.hex(), file=f, blockno=blockno + 1,
                               parity=next(parity)))
 
-    basectx = basechangectx(web.repo, req)
+    basectx = basechangectx(web.repo, web.req)
     if basectx is None:
         basectx = ctx.p1()
 
     style = web.config('web', 'style')
-    if 'style' in req.req.qsparams:
-        style = req.req.qsparams['style']
+    if 'style' in web.req.qsparams:
+        style = web.req.qsparams['style']
 
     diff = diffs(web, ctx, basectx, None, style)
 
@@ -449,7 +449,7 @@
 
     return dict(
         diff=diff,
-        symrev=symrevorshortnode(req, ctx),
+        symrev=symrevorshortnode(web.req, ctx),
         basenode=basectx.hex(),
         changesettag=showtags,
         changesetbookmark=showbookmarks,