[PATCH V3] hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Augie Fackler
raf at durin42.com
Tue Dec 8 09:31:15 CST 2015
On Tue, Dec 08, 2015 at 03:18:46PM +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 ddf69053c201adc1b9b3ad93d5dbd2c72635c2df
> # Parent 42aa0e570eaa364a622bc4443b0bcb79b1100a58
> hgweb: move entry-preparing code from webcommands to webutils.commonentry()
Queued this, thanks!
>
> The new function is used to fill 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.
>
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -145,20 +145,10 @@ def _filerevision(web, req, tmpl, fctx):
> 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))
> + permissions=fctx.manifest().flags(f),
> + **webutil.commonentry(web.repo, fctx))
>
> @webcommand('file')
> def file(web, req, tmpl):
> @@ -289,20 +279,9 @@ def _search(web, req, tmpl):
>
> yield tmpl('searchentry',
> parity=parity.next(),
> - author=ctx.user(),
> - parent=lambda **x: webutil.parents(ctx),
> - child=lambda **x: webutil.children(ctx),
> changelogtag=showtags,
> - desc=ctx.description(),
> - extra=ctx.extra(),
> - date=ctx.date(),
> files=files,
> - rev=ctx.rev(),
> - node=hex(n),
> - tags=webutil.nodetagsdict(web.repo, n),
> - bookmarks=webutil.nodebookmarksdict(web.repo, n),
> - inbranch=webutil.nodeinbranch(web.repo, ctx),
> - branches=webutil.nodebranchdict(web.repo, ctx))
> + **webutil.commonentry(web.repo, ctx))
>
> if count >= revcount:
> break
> @@ -572,20 +551,14 @@ def manifest(web, req, tmpl):
> "basename": d}
>
> return tmpl("manifest",
> - rev=ctx.rev(),
> symrev=symrev,
> - node=hex(node),
> path=abspath,
> up=webutil.up(abspath),
> upparity=parity.next(),
> fentries=filelist,
> dentries=dirlist,
> archives=web.archivelist(hex(node)),
> - tags=webutil.nodetagsdict(web.repo, node),
> - bookmarks=webutil.nodebookmarksdict(web.repo, node),
> - branch=webutil.nodebranchnodefault(ctx),
> - inbranch=webutil.nodeinbranch(web.repo, ctx),
> - branches=webutil.nodebranchdict(web.repo, ctx))
> + **webutil.commonentry(web.repo, ctx))
>
> @webcommand('tags')
> def tags(web, req, tmpl):
> @@ -719,22 +692,11 @@ def summary(web, req, tmpl):
> revs = web.repo.changelog.revs(start, end - 1)
> for i in revs:
> ctx = web.repo[i]
> - n = ctx.node()
> - hn = hex(n)
>
> l.append(tmpl(
> - 'shortlogentry',
> + 'shortlogentry',
> parity=parity.next(),
> - author=ctx.user(),
> - desc=ctx.description(),
> - extra=ctx.extra(),
> - date=ctx.date(),
> - rev=i,
> - node=hn,
> - tags=webutil.nodetagsdict(web.repo, n),
> - bookmarks=webutil.nodebookmarksdict(web.repo, n),
> - inbranch=webutil.nodeinbranch(web.repo, ctx),
> - branches=webutil.nodebranchdict(web.repo, ctx)))
> + **webutil.commonentry(web.repo, ctx)))
>
> l.reverse()
> yield l
> @@ -779,12 +741,8 @@ def filediff(web, req, tmpl):
> raise
>
> if fctx is not None:
> - n = fctx.node()
> path = fctx.path()
> ctx = fctx.changectx()
> - else:
> - n = ctx.node()
> - # path already defined in except clause
>
> parity = paritygen(web.stripecount)
> style = web.config('web', 'style', 'paper')
> @@ -800,20 +758,10 @@ def filediff(web, req, tmpl):
> ctx = ctx
> return tmpl("filediff",
> file=path,
> - node=hex(n),
> - rev=ctx.rev(),
> symrev=webutil.symrevorshortnode(req, ctx),
> - date=ctx.date(),
> - desc=ctx.description(),
> - extra=ctx.extra(),
> - author=ctx.user(),
> rename=rename,
> - branch=webutil.nodebranchnodefault(ctx),
> - parent=webutil.parents(ctx),
> - child=webutil.children(ctx),
> - tags=webutil.nodetagsdict(web.repo, n),
> - bookmarks=webutil.nodebookmarksdict(web.repo, n),
> - diff=diffs)
> + diff=diffs,
> + **webutil.commonentry(web.repo, ctx))
>
> diff = webcommand('diff')(filediff)
>
> @@ -881,24 +829,14 @@ def comparison(web, req, tmpl):
> ctx = ctx
> return tmpl('filecomparison',
> file=path,
> - node=hex(ctx.node()),
> - rev=ctx.rev(),
> symrev=webutil.symrevorshortnode(req, ctx),
> - date=ctx.date(),
> - desc=ctx.description(),
> - extra=ctx.extra(),
> - author=ctx.user(),
> rename=rename,
> - branch=webutil.nodebranchnodefault(ctx),
> - parent=webutil.parents(ctx),
> - child=webutil.children(ctx),
> - tags=webutil.nodetagsdict(web.repo, ctx.node()),
> - bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()),
> leftrev=leftrev,
> leftnode=hex(leftnode),
> rightrev=rightrev,
> rightnode=hex(rightnode),
> - comparison=comparison)
> + comparison=comparison,
> + **webutil.commonentry(web.repo, ctx))
>
> @webcommand('annotate')
> def annotate(web, req, tmpl):
> @@ -950,20 +888,10 @@ def annotate(web, req, tmpl):
> file=f,
> annotate=annotate,
> path=webutil.up(f),
> - rev=fctx.rev(),
> symrev=webutil.symrevorshortnode(req, fctx),
> - node=fctx.hex(),
> - author=fctx.user(),
> - date=fctx.date(),
> - desc=fctx.description(),
> - extra=fctx.extra(),
> rename=webutil.renamelink(fctx),
> - branch=webutil.nodebranchnodefault(fctx),
> - parent=webutil.parents(fctx),
> - child=webutil.children(fctx),
> - tags=webutil.nodetagsdict(web.repo, fctx.node()),
> - bookmarks=webutil.nodebookmarksdict(web.repo, fctx.node()),
> - permissions=fctx.manifest().flags(f))
> + permissions=fctx.manifest().flags(f),
> + **webutil.commonentry(web.repo, fctx))
>
> @webcommand('filelog')
> def filelog(web, req, tmpl):
> @@ -1025,23 +953,12 @@ def filelog(web, req, tmpl):
> for i in revs:
> iterfctx = fctx.filectx(i)
>
> - l.append({"parity": parity.next(),
> - "filerev": i,
> - "file": f,
> - "node": iterfctx.hex(),
> - "author": iterfctx.user(),
> - "date": iterfctx.date(),
> - "rename": webutil.renamelink(iterfctx),
> - "parent": lambda **x: webutil.parents(iterfctx),
> - "child": lambda **x: webutil.children(iterfctx),
> - "desc": iterfctx.description(),
> - "extra": iterfctx.extra(),
> - "tags": webutil.nodetagsdict(repo, iterfctx.node()),
> - "bookmarks": webutil.nodebookmarksdict(
> - repo, iterfctx.node()),
> - "branch": webutil.nodebranchnodefault(iterfctx),
> - "inbranch": webutil.nodeinbranch(repo, iterfctx),
> - "branches": webutil.nodebranchdict(repo, iterfctx)})
> + l.append(dict(
> + parity=parity.next(),
> + filerev=i,
> + file=f,
> + rename=webutil.renamelink(iterfctx),
> + **webutil.commonentry(repo, iterfctx)))
> for e in reversed(l):
> yield e
>
> @@ -1050,15 +967,16 @@ def filelog(web, req, tmpl):
>
> revnav = webutil.filerevnav(web.repo, fctx.path())
> nav = revnav.gen(end - 1, revcount, count)
> - return tmpl("filelog", file=f, node=fctx.hex(), nav=nav,
> - rev=fctx.rev(),
> + return tmpl("filelog",
> + file=f,
> + nav=nav,
> symrev=webutil.symrevorshortnode(req, fctx),
> - branch=webutil.nodebranchnodefault(fctx),
> - tags=webutil.nodetagsdict(web.repo, fctx.node()),
> - bookmarks=webutil.nodebookmarksdict(web.repo, fctx.node()),
> entries=entries,
> latestentry=latestentry,
> - revcount=revcount, morevars=morevars, lessvars=lessvars)
> + revcount=revcount,
> + morevars=morevars,
> + lessvars=lessvars,
> + **webutil.commonentry(web.repo, fctx))
>
> @webcommand('archive')
> def archive(web, req, tmpl):
> diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
> --- a/mercurial/hgweb/webutil.py
> +++ b/mercurial/hgweb/webutil.py
> @@ -308,6 +308,25 @@ def filectx(repo, req):
>
> return fctx
>
> +def commonentry(repo, ctx):
> + node = ctx.node()
> + return {
> + 'rev': ctx.rev(),
> + 'node': hex(node),
> + 'author': ctx.user(),
> + 'desc': ctx.description(),
> + 'date': ctx.date(),
> + 'extra': ctx.extra(),
> + 'phase': ctx.phasestr(),
> + 'branch': nodebranchnodefault(ctx),
> + 'inbranch': nodeinbranch(repo, ctx),
> + 'branches': nodebranchdict(repo, ctx),
> + 'tags': nodetagsdict(repo, node),
> + 'bookmarks': nodebookmarksdict(repo, node),
> + 'parent': lambda **x: parents(ctx),
> + 'child': lambda **x: children(ctx),
> + }
> +
> def changelistentry(web, ctx, tmpl):
> '''Obtain a dictionary to be used for entries in a changelist.
>
> @@ -320,22 +339,14 @@ def changelistentry(web, ctx, tmpl):
> showtags = showtag(repo, tmpl, 'changelogtag', n)
> files = listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
>
> - return {
> - "author": ctx.user(),
> - "parent": lambda **x: parents(ctx, rev - 1),
> - "child": lambda **x: children(ctx, rev + 1),
> - "changelogtag": showtags,
> - "desc": ctx.description(),
> - "extra": ctx.extra(),
> - "date": ctx.date(),
> - "files": files,
> - "rev": rev,
> - "node": hex(n),
> - "tags": nodetagsdict(repo, n),
> - "bookmarks": nodebookmarksdict(repo, n),
> - "inbranch": nodeinbranch(repo, ctx),
> - "branches": nodebranchdict(repo, ctx)
> - }
> + entry = commonentry(repo, ctx)
> + entry.update(
> + parent=lambda **x: parents(ctx, rev - 1),
> + child=lambda **x: children(ctx, rev + 1),
> + changelogtag=showtags,
> + files=files,
> + )
> + return entry
>
> def symrevorshortnode(req, ctx):
> if 'node' in req.form:
> @@ -376,29 +387,16 @@ def changesetentry(web, req, tmpl, ctx):
>
> return dict(
> diff=diff,
> - rev=ctx.rev(),
> - node=ctx.hex(),
> symrev=symrevorshortnode(req, ctx),
> - parent=parents(ctx),
> - child=children(ctx),
> basenode=basectx.hex(),
> changesettag=showtags,
> changesetbookmark=showbookmarks,
> changesetbranch=showbranch,
> - author=ctx.user(),
> - desc=ctx.description(),
> - extra=ctx.extra(),
> - date=ctx.date(),
> - phase=ctx.phasestr(),
> files=files,
> diffsummary=lambda **x: diffsummary(diffstatsgen),
> diffstat=diffstats,
> archives=web.archivelist(ctx.hex()),
> - tags=nodetagsdict(web.repo, ctx.node()),
> - bookmarks=nodebookmarksdict(web.repo, ctx.node()),
> - branch=showbranch,
> - inbranch=nodeinbranch(web.repo, ctx),
> - branches=nodebranchdict(web.repo, ctx))
> + **commonentry(web.repo, ctx))
>
> def listfilediffs(tmpl, files, node, max):
> for f in files[:max]:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list