comparison mercurial/hgweb/webcommands.py @ 24177:f53b7174facf

hgweb: extract changeset template mapping generation to own function Similar in spirit to 513d47905114, I want to write an extension to make available extra template keywords so hgweb templates can include extra data. To do this today requires monkeypatching the templater, which I think is the wrong place to perform this modification. This patch extracts the creation of the templater arguments to a standalone function - one that can be monkeypatched by extensions. I would very much like for extensions to be able to inject extra templater parameters into *any* template. However, I'm not sure the best way to facilitate this, as hgweb commands invoke the templater before returning and we want the extensions to have access to rich data structures like the context instances. We need cooperation inside hgweb command functions. The use case screams for something like internal-only "hooks." This is exactly what my (rejected) "events" patch series provided. Perhaps that feature should be reconsidered...
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 02 Mar 2015 15:07:18 -0800
parents fafd9a1284cf
children 6ddc86eedc3b
comparison
equal deleted inserted replaced
24176:67952dc7a88f 24177:f53b7174facf
429 The ``changeset`` template is rendered. Contents of the ``changesettag``, 429 The ``changeset`` template is rendered. Contents of the ``changesettag``,
430 ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many 430 ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many
431 templates related to diffs may all be used to produce the output. 431 templates related to diffs may all be used to produce the output.
432 """ 432 """
433 ctx = webutil.changectx(web.repo, req) 433 ctx = webutil.changectx(web.repo, req)
434 basectx = webutil.basechangectx(web.repo, req) 434
435 if basectx is None: 435 return tmpl('changeset', **webutil.changesetentry(web, req, tmpl, ctx))
436 basectx = ctx.p1()
437 showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node())
438 showbookmarks = webutil.showbookmark(web.repo, tmpl, 'changesetbookmark',
439 ctx.node())
440 showbranch = webutil.nodebranchnodefault(ctx)
441
442 files = []
443 parity = paritygen(web.stripecount)
444 for blockno, f in enumerate(ctx.files()):
445 template = f in ctx and 'filenodelink' or 'filenolink'
446 files.append(tmpl(template,
447 node=ctx.hex(), file=f, blockno=blockno + 1,
448 parity=parity.next()))
449
450 style = web.config('web', 'style', 'paper')
451 if 'style' in req.form:
452 style = req.form['style'][0]
453
454 parity = paritygen(web.stripecount)
455 diffs = webutil.diffs(web.repo, tmpl, ctx, basectx, None, parity, style)
456
457 parity = paritygen(web.stripecount)
458 diffstatgen = webutil.diffstatgen(ctx, basectx)
459 diffstat = webutil.diffstat(tmpl, ctx, diffstatgen, parity)
460
461 return tmpl('changeset',
462 diff=diffs,
463 rev=ctx.rev(),
464 node=ctx.hex(),
465 parent=tuple(webutil.parents(ctx)),
466 child=webutil.children(ctx),
467 basenode=basectx.hex(),
468 changesettag=showtags,
469 changesetbookmark=showbookmarks,
470 changesetbranch=showbranch,
471 author=ctx.user(),
472 desc=ctx.description(),
473 extra=ctx.extra(),
474 date=ctx.date(),
475 files=files,
476 diffsummary=lambda **x: webutil.diffsummary(diffstatgen),
477 diffstat=diffstat,
478 archives=web.archivelist(ctx.hex()),
479 tags=webutil.nodetagsdict(web.repo, ctx.node()),
480 bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()),
481 branch=webutil.nodebranchnodefault(ctx),
482 inbranch=webutil.nodeinbranch(web.repo, ctx),
483 branches=webutil.nodebranchdict(web.repo, ctx))
484 436
485 rev = webcommand('rev')(changeset) 437 rev = webcommand('rev')(changeset)
486 438
487 def decodepath(path): 439 def decodepath(path):
488 """Hook for mapping a path in the repository to a path in the 440 """Hook for mapping a path in the repository to a path in the