[PATCH 02 of 23 Series-D] hgweb: renamed `limit` argument to `lastest`
Mads Kiilerich
mads at kiilerich.com
Sat Jan 12 07:31:52 CST 2013
Pierre-Yves David wrote, On 01/11/2013 01:23 AM:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1357598846 -3600
> # Node ID f474b1184d82e9ad72b624541bbfe02bc9d2efe3
> # Parent 12a9a51ca6f925bac254c693ef53627d39c622db
> hgweb: renamed `limit` argument to `lastest`
>
> The `limit` argument of several generator have only two possible values in
> practice: 0 and 1. We rename this parameter to `lastest` and simplify it's
> handling.
The parameter is used for generating a single element iterable
"latestentry" with the last element from the "entries" iterable. So +1
for calling it "latest" or "latestonly".
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -192,13 +192,16 @@ def changelog(web, req, tmpl, shortlog=F
> try:
> ctx = web.repo[hi]
> except error.RepoError:
> return _search(web, req, tmpl) # XXX redirect to 404 page?
>
> - def changelist(limit=0, **map):
> + def changelist(lastest=False, **map):
> l = [] # build a list in forward order for efficiency
> - for i in xrange(start, end):
> + revs = xrange(start, end)
> + if lastest:
> + revs = (end - 1,)
> + for i in revs:
> ctx = web.repo[i]
> n = ctx.node()
> showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
> files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
>
> @@ -215,13 +218,10 @@ def changelog(web, req, tmpl, shortlog=F
> "tags": webutil.nodetagsdict(web.repo, n),
> "bookmarks": webutil.nodebookmarksdict(web.repo, n),
> "inbranch": webutil.nodeinbranch(web.repo, ctx),
> "branches": webutil.nodebranchdict(web.repo, ctx)
> })
> - if limit > 0:
> - l = l[-limit:]
> -
> for e in reversed(l):
> yield e
>
> revcount = shortlog and web.maxshortchanges or web.maxchanges
> if 'revcount' in req.form:
> @@ -243,12 +243,12 @@ def changelog(web, req, tmpl, shortlog=F
>
> changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
>
> return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
> node=ctx.hex(), rev=pos, changesets=count,
> - entries=lambda **x: changelist(limit=0,**x),
> - latestentry=lambda **x: changelist(limit=1,**x),
> + entries=lambda **x: changelist(**x),
I would like to comment that you lost a parameter here ... but realized
that you just started using the default value.
The combination of parameters with default value and ** is not pretty,
and removing the parameter makes the code less readable. FWIW, I would
prefer to make it more explicit and drop the default values ... and also
let the lambda pass the x on directly without first expanding it as
parameters and then fold it back to a dict.
> + latestentry=lambda **x: changelist(lastest=True,**x),
I think it is OK to fix minor whitespace damage when touching a line for
other reasons.
> archives=web.archivelist("tip"), revcount=revcount,
> morevars=morevars, lessvars=lessvars)
>
/Mads
More information about the Mercurial-devel
mailing list