Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/webcommands.py @ 23745:513d47905114
hgweb: extract changelist entry generation into own function
I want to supplement changelist entries (used by shortlog and changelog
endpoints) with custom metadata from an extension. i.e. I have extra
per-changeset metadata that I wish to make available to templates so it
can be rendered on hgweb.
To facilitate this, I've extracted the logic for creating a changeset
data structure into its own function, where it can be wrapped by
extensions.
Ideally, hgweb would use the same templater as the command line and have
full access to templatekw.keywords. But that's a lot of work. This patch
gets us some of the benefit without all the work.
Many other hgweb commands could benefit from similar refactorings. I'm
going to wait to see how this patch is received before I go crazy on
extracting inline functions.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 06 Jan 2015 20:14:52 -0800 |
parents | 9e1f4c65f5f5 |
children | db85e454fccc |
comparison
equal
deleted
inserted
replaced
23744:d1933c2e3c8c | 23745:513d47905114 |
---|---|
280 def changelist(): | 280 def changelist(): |
281 revs = [] | 281 revs = [] |
282 if pos != -1: | 282 if pos != -1: |
283 revs = web.repo.changelog.revs(pos, 0) | 283 revs = web.repo.changelog.revs(pos, 0) |
284 curcount = 0 | 284 curcount = 0 |
285 for i in revs: | 285 for rev in revs: |
286 ctx = web.repo[i] | |
287 n = ctx.node() | |
288 showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) | |
289 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) | |
290 | |
291 curcount += 1 | 286 curcount += 1 |
292 if curcount > revcount + 1: | 287 if curcount > revcount + 1: |
293 break | 288 break |
294 yield {"parity": parity.next(), | 289 |
295 "author": ctx.user(), | 290 entry = webutil.changelistentry(web, web.repo[rev], tmpl) |
296 "parent": webutil.parents(ctx, i - 1), | 291 entry['parity'] = parity.next() |
297 "child": webutil.children(ctx, i + 1), | 292 yield entry |
298 "changelogtag": showtags, | |
299 "desc": ctx.description(), | |
300 "extra": ctx.extra(), | |
301 "date": ctx.date(), | |
302 "files": files, | |
303 "rev": i, | |
304 "node": hex(n), | |
305 "tags": webutil.nodetagsdict(web.repo, n), | |
306 "bookmarks": webutil.nodebookmarksdict(web.repo, n), | |
307 "inbranch": webutil.nodeinbranch(web.repo, ctx), | |
308 "branches": webutil.nodebranchdict(web.repo, ctx) | |
309 } | |
310 | 293 |
311 revcount = shortlog and web.maxshortchanges or web.maxchanges | 294 revcount = shortlog and web.maxshortchanges or web.maxchanges |
312 if 'revcount' in req.form: | 295 if 'revcount' in req.form: |
313 try: | 296 try: |
314 revcount = int(req.form.get('revcount', [revcount])[0]) | 297 revcount = int(req.form.get('revcount', [revcount])[0]) |