comparison mercurial/hgweb/webutil.py @ 36547:7937850a523d

hgweb: make templater mostly compatible with log templates Prepares for gradually switching templatekw.showsuccsandmarkers() to new API. This was a PoC showing how to reuse templatekw functions in hgweb. We could remove rev, node, author, etc. from the commonentry() table, but we'll have to carefully remove all corresponding symbols from webcommands.*(). Otherwise, we would face the issue5612. Still templatekw.keywords aren't exported. Otherwise some tests would fail because the atom template expects {files} to be empty in filelog, but templatekw.showfiles() provides the {files} implementation.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 22 Dec 2017 21:59:38 +0900
parents 1fb9e01328e4
children 59ee648870a7
comparison
equal deleted inserted replaced
36546:69477bac8926 36547:7937850a523d
350 raise ErrorResponse(HTTP_BAD_REQUEST, pycompat.bytestr(exc)) 350 raise ErrorResponse(HTTP_BAD_REQUEST, pycompat.bytestr(exc))
351 351
352 def formatlinerange(fromline, toline): 352 def formatlinerange(fromline, toline):
353 return '%d:%d' % (fromline + 1, toline) 353 return '%d:%d' % (fromline + 1, toline)
354 354
355 def succsandmarkers(repo, ctx): 355 def succsandmarkers(repo, ctx, **args):
356 for item in templatekw.showsuccsandmarkers(repo, ctx): 356 for item in templatekw.showsuccsandmarkers(repo, ctx, **args):
357 item['successors'] = _siblings(repo[successor] 357 item['successors'] = _siblings(repo[successor]
358 for successor in item['successors']) 358 for successor in item['successors'])
359 yield item 359 yield item
360 360
361 def commonentry(repo, ctx): 361 def commonentry(repo, ctx):
362 node = ctx.node() 362 node = ctx.node()
363 return { 363 return {
364 # TODO: perhaps ctx.changectx() should be assigned if ctx is a
365 # filectx, but I'm not pretty sure if that would always work because
366 # fctx.parents() != fctx.changectx.parents() for example.
367 'ctx': ctx,
368 'revcache': {},
364 'rev': ctx.rev(), 369 'rev': ctx.rev(),
365 'node': hex(node), 370 'node': hex(node),
366 'author': ctx.user(), 371 'author': ctx.user(),
367 'desc': ctx.description(), 372 'desc': ctx.description(),
368 'date': ctx.date(), 373 'date': ctx.date(),
369 'extra': ctx.extra(), 374 'extra': ctx.extra(),
370 'phase': ctx.phasestr(), 375 'phase': ctx.phasestr(),
371 'obsolete': ctx.obsolete(), 376 'obsolete': ctx.obsolete(),
372 'succsandmarkers': lambda **x: succsandmarkers(repo, ctx), 377 'succsandmarkers': succsandmarkers,
373 'instabilities': [{"instability": i} for i in ctx.instabilities()], 378 'instabilities': [{"instability": i} for i in ctx.instabilities()],
374 'branch': nodebranchnodefault(ctx), 379 'branch': nodebranchnodefault(ctx),
375 'inbranch': nodeinbranch(repo, ctx), 380 'inbranch': nodeinbranch(repo, ctx),
376 'branches': nodebranchdict(repo, ctx), 381 'branches': nodebranchdict(repo, ctx),
377 'tags': nodetagsdict(repo, node), 382 'tags': nodetagsdict(repo, node),