diff 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
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Tue Jan 06 15:29:02 2015 -0800
+++ b/mercurial/hgweb/webcommands.py	Tue Jan 06 20:14:52 2015 -0800
@@ -282,31 +282,14 @@
         if pos != -1:
             revs = web.repo.changelog.revs(pos, 0)
         curcount = 0
-        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)
-
+        for rev in revs:
             curcount += 1
             if curcount > revcount + 1:
                 break
-            yield {"parity": parity.next(),
-                   "author": ctx.user(),
-                   "parent": webutil.parents(ctx, i - 1),
-                   "child": webutil.children(ctx, i + 1),
-                   "changelogtag": showtags,
-                   "desc": ctx.description(),
-                   "extra": ctx.extra(),
-                   "date": ctx.date(),
-                   "files": files,
-                   "rev": i,
-                   "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)
-            }
+
+            entry = webutil.changelistentry(web, web.repo[rev], tmpl)
+            entry['parity'] = parity.next()
+            yield entry
 
     revcount = shortlog and web.maxshortchanges or web.maxchanges
     if 'revcount' in req.form: