D2803: hgweb: stop passing req and tmpl into @webcommand functions (API)
This revision was automatically updated to reflect the committed changes. Closed by commit rHG4daa22071d5d: hgweb: stop passing req and tmpl into @webcommand functions (API) (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2803?vs=6864=6939 REVISION DETAIL https://phab.mercurial-scm.org/D2803 AFFECTED FILES hgext/highlight/__init__.py hgext/keyword.py hgext/largefiles/overrides.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py tests/hgweberror.py CHANGE DETAILS diff --git a/tests/hgweberror.py b/tests/hgweberror.py --- a/tests/hgweberror.py +++ b/tests/hgweberror.py @@ -6,7 +6,7 @@ webcommands, ) -def raiseerror(web, req, tmpl): +def raiseerror(web): '''Dummy web command that raises an uncaught Exception.''' # Simulate an error after partial response. diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -65,7 +65,7 @@ Usage: @webcommand('mycommand') -def mycommand(web, req, tmpl): +def mycommand(web): pass """ @@ -78,7 +78,7 @@ return func @webcommand('log') -def log(web, req, tmpl): +def log(web): """ /log[/{revision}[/{path}]] -- @@ -95,23 +95,23 @@ """ if web.req.qsparams.get('file'): -return filelog(web, req, None) +return filelog(web) else: -return changelog(web, req, None) +return changelog(web) @webcommand('rawfile') -def rawfile(web, req, tmpl): +def rawfile(web): guessmime = web.configbool('web', 'guessmime') path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) if not path: -return manifest(web, req, None) +return manifest(web) try: fctx = webutil.filectx(web.repo, web.req) except error.LookupError as inst: try: -return manifest(web, req, None) +return manifest(web) except ErrorResponse: raise inst @@ -135,7 +135,7 @@ web.res.setbodybytes(text) return web.res.sendresponse() -def _filerevision(web, req, fctx): +def _filerevision(web, fctx): f = fctx.path() text = fctx.data() parity = paritygen(web.stripecount) @@ -164,7 +164,7 @@ **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))) @webcommand('file') -def file(web, req, tmpl): +def file(web): """ /file/{revision}[/{path}] - @@ -184,16 +184,16 @@ be rendered. """ if web.req.qsparams.get('style') == 'raw': -return rawfile(web, req, None) +return rawfile(web) path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) if not path: -return manifest(web, req, None) +return manifest(web) try: -return _filerevision(web, req, webutil.filectx(web.repo, web.req)) +return _filerevision(web, webutil.filectx(web.repo, web.req)) except error.LookupError as inst: try: -return manifest(web, req, None) +return manifest(web) except ErrorResponse: raise inst @@ -354,7 +354,7 @@ showunforcekw=showunforcekw) @webcommand('changelog') -def changelog(web, req, tmpl, shortlog=False): +def changelog(web, shortlog=False): """ /changelog[/{revision}] --- @@ -452,7 +452,7 @@ query=query) @webcommand('shortlog') -def shortlog(web, req, tmpl): +def shortlog(web): """ /shortlog - @@ -463,10 +463,10 @@ difference is the ``shortlog`` template will be rendered instead of the ``changelog`` template. """ -return changelog(web, req, None, shortlog=True) +return changelog(web, shortlog=True) @webcommand('changeset') -def changeset(web, req, tmpl): +def changeset(web): """ /changeset[/{revision}] --- @@ -498,7 +498,7 @@ return path @webcommand('manifest') -def manifest(web, req, tmpl): +def manifest(web): """ /manifest[/{revision}[/{path}]] --- @@ -598,7 +598,7 @@ **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) @webcommand('tags') -def tags(web, req, tmpl): +def tags(web): """ /tags - @@ -632,7 +632,7 @@ latestentry=lambda **x: entries(True, True, **x)) @webcommand('bookmarks') -def bookmarks(web, req, tmpl): +def bookmarks(web): """ /bookmarks -- @@ -671,7 +671,7 @@ latestentry=lambda **x: entries(latestonly=True, **x)) @webcommand('branches') -def branches(web, req, tmpl): +def branches(web): """ /branches - @@ -694,7 +694,7 @@ latestentry=latestentry) @webcommand('summary') -def summary(web, req, tmpl): +def summary(web): """ /summary
D2803: hgweb: stop passing req and tmpl into @webcommand functions (API)
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY We have effectively removed all consumers of the old wsgirequest type. The templater can be accessed on the requestcontext passed into the @webcommand function. For the most part, these arguments are unused. They only exist to provide backwards compatibility. And in the case of wsgirequest, use of that object could actively interfere with the new request object. So let's stop passing these objects to @webcommand functions. With this commit, wsgirequest is practically dead from the hgweb WSGI application. There are still some uses in hgwebdir though... .. api:: @webcommand functions now only receive a single argument. The request and templater instances can be accessed via the ``req`` and ``templater`` attributes of the first argument. Note that the request object is different from previous Mercurial releases and consumers of the previous ``req`` 2nd argument will need updating to use the new API. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2803 AFFECTED FILES hgext/highlight/__init__.py hgext/keyword.py hgext/largefiles/overrides.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py tests/hgweberror.py CHANGE DETAILS diff --git a/tests/hgweberror.py b/tests/hgweberror.py --- a/tests/hgweberror.py +++ b/tests/hgweberror.py @@ -6,7 +6,7 @@ webcommands, ) -def raiseerror(web, req, tmpl): +def raiseerror(web): '''Dummy web command that raises an uncaught Exception.''' # Simulate an error after partial response. diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -65,7 +65,7 @@ Usage: @webcommand('mycommand') -def mycommand(web, req, tmpl): +def mycommand(web): pass """ @@ -78,7 +78,7 @@ return func @webcommand('log') -def log(web, req, tmpl): +def log(web): """ /log[/{revision}[/{path}]] -- @@ -95,23 +95,23 @@ """ if web.req.qsparams.get('file'): -return filelog(web, req, None) +return filelog(web) else: -return changelog(web, req, None) +return changelog(web) @webcommand('rawfile') -def rawfile(web, req, tmpl): +def rawfile(web): guessmime = web.configbool('web', 'guessmime') path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) if not path: -return manifest(web, req, None) +return manifest(web) try: fctx = webutil.filectx(web.repo, web.req) except error.LookupError as inst: try: -return manifest(web, req, None) +return manifest(web) except ErrorResponse: raise inst @@ -135,7 +135,7 @@ web.res.setbodybytes(text) return web.res.sendresponse() -def _filerevision(web, req, fctx): +def _filerevision(web, fctx): f = fctx.path() text = fctx.data() parity = paritygen(web.stripecount) @@ -164,7 +164,7 @@ **pycompat.strkwargs(webutil.commonentry(web.repo, fctx))) @webcommand('file') -def file(web, req, tmpl): +def file(web): """ /file/{revision}[/{path}] - @@ -184,16 +184,16 @@ be rendered. """ if web.req.qsparams.get('style') == 'raw': -return rawfile(web, req, None) +return rawfile(web) path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) if not path: -return manifest(web, req, None) +return manifest(web) try: -return _filerevision(web, req, webutil.filectx(web.repo, web.req)) +return _filerevision(web, webutil.filectx(web.repo, web.req)) except error.LookupError as inst: try: -return manifest(web, req, None) +return manifest(web) except ErrorResponse: raise inst @@ -354,7 +354,7 @@ showunforcekw=showunforcekw) @webcommand('changelog') -def changelog(web, req, tmpl, shortlog=False): +def changelog(web, shortlog=False): """ /changelog[/{revision}] --- @@ -452,7 +452,7 @@ query=query) @webcommand('shortlog') -def shortlog(web, req, tmpl): +def shortlog(web): """ /shortlog - @@ -463,10 +463,10 @@ difference is the ``shortlog`` template will be rendered instead of the ``changelog`` template. """ -return changelog(web, req, None, shortlog=True) +return changelog(web, shortlog=True) @webcommand('changeset') -def changeset(web, req, tmpl): +def changeset(web): """ /changeset[/{revision}] --- @@ -498,7 +498,7 @@ return path @webcommand('manifest') -def manifest(web, req, tmpl): +def manifest(web): """