# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 2018-03-10 19:46:52
# Node ID 1a1972b1a1ff76b84da9458ba36fa84a8e6f377b
# Parent  ec0af9c59270605d29a5ee3d78eace96856ecc12

hgweb: use our new request object for "style" parameter

The "style" parameter is kind of wonky because it is explicitly
set and has lookups in random locations.

Let's port it to qsparams first because it isn't straightforward.

There is subtle change in behavior. But I don't think it is worth
calling out in a BC.

Our multidict's __getitem__ returns the last set value for a key,
not the first. So if the query string set a variable multiple times,
before we would get the first value and now we would get the last
value. It makes no sense to specify these things multiple times.
And I think last write wins is more sensible than first write wins.

Differential Revision: https://phab.mercurial-scm.org/D2779

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -53,9 +53,8 @@ archivespecs = util.sortdict((
 ))
 
 def getstyle(req, configfn, templatepath):
-    fromreq = req.form.get('style', [None])[0]
     styles = (
-        fromreq,
+        req.qsparams.get('style', None),
         configfn('web', 'style'),
         'paper',
     )
@@ -160,7 +159,7 @@ class requestcontext(object):
         # figure out which style to use
 
         vars = {}
-        styles, (style, mapfile) = getstyle(wsgireq, self.config,
+        styles, (style, mapfile) = getstyle(wsgireq.req, self.config,
                                             self.templatepath)
         if style == styles[0]:
             vars['style'] = style
@@ -337,7 +336,7 @@ class hgweb(object):
             cmd = args.pop(0)
             style = cmd.rfind('-')
             if style != -1:
-                wsgireq.form['style'] = [cmd[:style]]
+                req.qsparams['style'] = cmd[:style]
                 cmd = cmd[style + 1:]
 
             # avoid accepting e.g. style parameter as command
@@ -355,7 +354,7 @@ class hgweb(object):
 
             ua = req.headers.get('User-Agent', '')
             if cmd == 'rev' and 'mercurial' in ua:
-                wsgireq.form['style'] = ['raw']
+                req.qsparams['style'] = 'raw'
 
             if cmd == 'archive':
                 fn = wsgireq.form['node'][0]
@@ -389,7 +388,7 @@ class hgweb(object):
             if cmd not in webcommands.__all__:
                 msg = 'no such method: %s' % cmd
                 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
-            elif cmd == 'file' and 'raw' in wsgireq.form.get('style', []):
+            elif cmd == 'file' and req.qsparams.get('style') == 'raw':
                 rctx.ctype = ctype
                 content = webcommands.rawfile(rctx, wsgireq, tmpl)
             else:
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -510,7 +510,7 @@ class hgwebdir(object):
             url += '/'
 
         vars = {}
-        styles, (style, mapfile) = hgweb_mod.getstyle(wsgireq, config,
+        styles, (style, mapfile) = hgweb_mod.getstyle(wsgireq.req, config,
                                                       self.templatepath)
         if style == styles[0]:
             vars['style'] = style
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -762,8 +762,8 @@ def filediff(web, req, tmpl):
     basectx = ctx.p1()
 
     style = web.config('web', 'style')
-    if 'style' in req.form:
-        style = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        style = req.req.qsparams['style']
 
     diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style)
     if fctx is not None:
@@ -1011,8 +1011,8 @@ def filelog(web, req, tmpl):
     entries = []
 
     diffstyle = web.config('web', 'style')
-    if 'style' in req.form:
-        diffstyle = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        diffstyle = req.req.qsparams['style']
 
     def diff(fctx, linerange=None):
         ctx = fctx.changectx()
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -438,8 +438,8 @@ def changesetentry(web, req, tmpl, ctx):
         basectx = ctx.p1()
 
     style = web.config('web', 'style')
-    if 'style' in req.form:
-        style = req.form['style'][0]
+    if 'style' in req.req.qsparams:
+        style = req.req.qsparams['style']
 
     diff = diffs(web, tmpl, ctx, basectx, None, style)