[PATCH 02 of 23 Series-D] hgweb: renamed `limit` argument to `lastest`

Angel Ezquerra angel.ezquerra at gmail.com
Fri Jan 11 17:52:45 CST 2013


On Jan 11, 2013 10:37 PM, "Pierre-Yves David" <
pierre-yves.david at ens-lyon.org> wrote:
>
> # 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.
>
> 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),
> +                latestentry=lambda **x: changelist(lastest=True,**x),
>                  archives=web.archivelist("tip"), revcount=revcount,
>                  morevars=morevars, lessvars=lessvars)
>
>  def shortlog(web, req, tmpl):
>      return changelog(web, req, tmpl, shortlog = True)
> @@ -399,48 +399,47 @@ def manifest(web, req, tmpl):
>
>  def tags(web, req, tmpl):
>      i = list(reversed(web.repo.tagslist()))
>      parity = paritygen(web.stripecount)
>
> -    def entries(notip=False, limit=0, **map):
> -        count = 0
> -        for k, n in i:
> -            if notip and k == "tip":
> -                continue
> -            if limit > 0 and count >= limit:
> -                continue
> -            count = count + 1
> +    def entries(notip=False, lastest=False, **map):
> +        t = i
> +        if notip:
> +            t = [(k, n) for k, n in i if k != "tip"]
> +        if lastest:
> +            t = t[:1]
> +        for k, n in t:
>              yield {"parity": parity.next(),
>                     "tag": k,
>                     "date": web.repo[n].date(),
>                     "node": hex(n)}
>
>      return tmpl("tags",
>                  node=hex(web.repo.changelog.tip()),
> -                entries=lambda **x: entries(False, 0, **x),
> -                entriesnotip=lambda **x: entries(True, 0, **x),
> -                latestentry=lambda **x: entries(True, 1, **x))
> +                entries=lambda **x: entries(False, **x),
> +                entriesnotip=lambda **x: entries(True, **x),
> +                latestentry=lambda **x: entries(True, True, **x))
>
>  def bookmarks(web, req, tmpl):
>      i = web.repo._bookmarks.items()
>      parity = paritygen(web.stripecount)
>
> -    def entries(limit=0, **map):
> -        count = 0
> -        for k, n in sorted(i):
> -            if limit > 0 and count >= limit:
> -                continue
> -            count = count + 1
> +    def entries(lastest=False, **map):
> +        if lastest:
> +            t = min(i)
> +        else:
> +            t = sorted(i)
> +        for k, n in t:
>              yield {"parity": parity.next(),
>                     "bookmark": k,
>                     "date": web.repo[n].date(),
>                     "node": hex(n)}
>
>      return tmpl("bookmarks",
>                  node=hex(web.repo.changelog.tip()),
> -                entries=lambda **x: entries(0, **x),
> -                latestentry=lambda **x: entries(1, **x))
> +                entries=lambda **x: entries(**x),
> +                latestentry=lambda **x: entries(lastest=True, **x))
>
>  def branches(web, req, tmpl):
>      tips = []
>      heads = web.repo.heads()
>      parity = paritygen(web.stripecount)
> @@ -739,15 +738,18 @@ def filelog(web, req, tmpl):
>      count = fctx.filerev() + 1
>      start = max(0, fctx.filerev() - revcount + 1) # first rev on this
page
>      end = min(count, start + revcount) # last rev on this page
>      parity = paritygen(web.stripecount, offset=start - end)
>
> -    def entries(limit=0, **map):
> +    def entries(lastest=False, **map):
>          l = []
>
>          repo = web.repo
> -        for i in xrange(start, end):
> +        revs = xrange(start, end)
> +        if lastest:
> +            revs = (end - 1,)
> +        for i in revs:
>              iterfctx = fctx.filectx(i)
>
>              l.append({"parity": parity.next(),
>                        "filerev": i,
>                        "file": f,
> @@ -762,22 +764,18 @@ def filelog(web, req, tmpl):
>                        "bookmarks": webutil.nodebookmarksdict(
>                            repo, iterfctx.node()),
>                        "branch": webutil.nodebranchnodefault(iterfctx),
>                        "inbranch": webutil.nodeinbranch(repo, iterfctx),
>                        "branches": webutil.nodebranchdict(repo,
iterfctx)})
> -
> -        if limit > 0:
> -            l = l[-limit:]
> -
>          for e in reversed(l):
>              yield e
>
>      nodefunc = lambda x: fctx.filectx(fileid=x)
>      nav = webutil.revnavgen(end - 1, revcount, count, nodefunc)
>      return tmpl("filelog", file=f, node=fctx.hex(), nav=nav,
> -                entries=lambda **x: entries(limit=0, **x),
> -                latestentry=lambda **x: entries(limit=1, **x),
> +                entries=lambda **x: entries(**x),
> +                latestentry=lambda **x: entries(lastest=True, **x),
>                  revcount=revcount, morevars=morevars, lessvars=lessvars)
>
>  def archive(web, req, tmpl):
>      type_ = req.form.get('type', [None])[0]
>      allowed = web.configlist("web", "allow_archive")
>

Pierre-Yves,

What does "lastest" mean? Do you mean "latest"?

Angel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130112/ad45dbc3/attachment.html>


More information about the Mercurial-devel mailing list