[PATCH 1 of 2 V2] hgweb: move entry-preparing code from webcommands to webutils.commonentry()

Yuya Nishihara yuya at tcha.org
Sun Nov 22 10:52:54 CST 2015


On Sun, 22 Nov 2015 15:13:50 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1447396536 -28800
> #      Fri Nov 13 14:35:36 2015 +0800
> # Node ID b4c5ca5544c5b51cbe9f616d3821d07ff29f1073
> # Parent  df9b73d2d444ae82fe8d3fe6cf682a93b2c4a7ef
> hgweb: move entry-preparing code from webcommands to webutils.commonentry()
> 
> The new function is used to prefill basic information about a ctx, such as
> revision number and hash, author, commit message, etc. Before, every webcommand
> used to get this basic information on its own using some boilerplate code, and
> some things in some places just weren't available (e.g. branch/tag/bookmark
> info for the current hgweb revision in filelog).
> 
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -141,24 +141,16 @@ def _filerevision(web, req, tmpl, fctx):
>                     "linenumber": "% 6d" % (lineno + 1),
>                     "parity": parity.next()}
>  
> -    return tmpl("filerevision",
> -                file=f,
> -                path=webutil.up(f),
> -                text=lines(),
> -                rev=fctx.rev(),
> -                symrev=webutil.symrevorshortnode(req, fctx),
> -                node=fctx.hex(),
> -                author=fctx.user(),
> -                date=fctx.date(),
> -                desc=fctx.description(),
> -                extra=fctx.extra(),
> -                branch=webutil.nodebranchnodefault(fctx),
> -                parent=webutil.parents(fctx),
> -                child=webutil.children(fctx),
> -                rename=webutil.renamelink(fctx),
> -                tags=webutil.nodetagsdict(web.repo, fctx.node()),
> -                bookmarks=webutil.nodebookmarksdict(web.repo, fctx.node()),
> -                permissions=fctx.manifest().flags(f))
> +    entry = webutil.commonentry(web.repo, fctx)
> +    entry.update(
> +        file=f,
> +        path=webutil.up(f),
> +        text=lines(),
> +        symrev=webutil.symrevorshortnode(req, fctx),
> +        rename=webutil.renamelink(fctx),
> +        permissions=fctx.manifest().flags(f),
> +    )
> +    return tmpl("filerevision", **entry)

Can I replace it as follows if there's no conflicting items?

-    entry = webutil.commonentry(web.repo, fctx)
-    entry.update(
-        file=f,
-        path=webutil.up(f),
-        text=lines(),
-        symrev=webutil.symrevorshortnode(req, fctx),
-        rename=webutil.renamelink(fctx),
-        permissions=fctx.manifest().flags(f),
-    )
-    return tmpl("filerevision", **entry)
+    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),
+                **webutil.commonentry(web.repo, fctx))


More information about the Mercurial-devel mailing list