Mercurial > hg
comparison mercurial/templatekw.py @ 32037:e5eab0fe69ee
templatekw: have showlist() take mapping dict with no **kwargs expansion (API)
See the previous commit for why.
splitlines() does not pass a mapping dict, which would probably mean the
legacy template didn't work from the beginning.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 05 Apr 2017 21:47:34 +0900 |
parents | 8bcc8c9b4e9f |
children | 3920b5970f95 |
comparison
equal
deleted
inserted
replaced
32036:8bcc8c9b4e9f | 32037:e5eab0fe69ee |
---|---|
76 template""" | 76 template""" |
77 if not util.safehasattr(thing, 'gen'): | 77 if not util.safehasattr(thing, 'gen'): |
78 return thing | 78 return thing |
79 return thing.gen | 79 return thing.gen |
80 | 80 |
81 def showlist(name, values, plural=None, element=None, separator=' ', **mapping): | 81 def showlist(name, values, mapping, plural=None, element=None, separator=' '): |
82 if not element: | 82 if not element: |
83 element = name | 83 element = name |
84 f = _showlist(name, values, mapping, plural, separator) | 84 f = _showlist(name, values, mapping, plural, separator) |
85 return hybridlist(values, name=element, gen=f) | 85 return hybridlist(values, name=element, gen=f) |
86 | 86 |
281 changeset was committed. Will be empty if the branch name was | 281 changeset was committed. Will be empty if the branch name was |
282 default. (DEPRECATED) | 282 default. (DEPRECATED) |
283 """ | 283 """ |
284 branch = args['ctx'].branch() | 284 branch = args['ctx'].branch() |
285 if branch != 'default': | 285 if branch != 'default': |
286 return showlist('branch', [branch], plural='branches', **args) | 286 return showlist('branch', [branch], args, plural='branches') |
287 return showlist('branch', [], plural='branches', **args) | 287 return showlist('branch', [], args, plural='branches') |
288 | 288 |
289 @templatekeyword('bookmarks') | 289 @templatekeyword('bookmarks') |
290 def showbookmarks(**args): | 290 def showbookmarks(**args): |
291 """List of strings. Any bookmarks associated with the | 291 """List of strings. Any bookmarks associated with the |
292 changeset. Also sets 'active', the name of the active bookmark. | 292 changeset. Also sets 'active', the name of the active bookmark. |
301 @templatekeyword('children') | 301 @templatekeyword('children') |
302 def showchildren(**args): | 302 def showchildren(**args): |
303 """List of strings. The children of the changeset.""" | 303 """List of strings. The children of the changeset.""" |
304 ctx = args['ctx'] | 304 ctx = args['ctx'] |
305 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()] | 305 childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()] |
306 return showlist('children', childrevs, element='child', **args) | 306 return showlist('children', childrevs, args, element='child') |
307 | 307 |
308 # Deprecated, but kept alive for help generation a purpose. | 308 # Deprecated, but kept alive for help generation a purpose. |
309 @templatekeyword('currentbookmark') | 309 @templatekeyword('currentbookmark') |
310 def showcurrentbookmark(**args): | 310 def showcurrentbookmark(**args): |
311 """String. The active bookmark, if it is | 311 """String. The active bookmark, if it is |
371 | 371 |
372 @templatekeyword('file_adds') | 372 @templatekeyword('file_adds') |
373 def showfileadds(**args): | 373 def showfileadds(**args): |
374 """List of strings. Files added by this changeset.""" | 374 """List of strings. Files added by this changeset.""" |
375 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | 375 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
376 return showlist('file_add', getfiles(repo, ctx, revcache)[1], | 376 return showlist('file_add', getfiles(repo, ctx, revcache)[1], args, |
377 element='file', **args) | 377 element='file') |
378 | 378 |
379 @templatekeyword('file_copies') | 379 @templatekeyword('file_copies') |
380 def showfilecopies(**args): | 380 def showfilecopies(**args): |
381 """List of strings. Files copied in this changeset with | 381 """List of strings. Files copied in this changeset with |
382 their sources. | 382 their sources. |
418 | 418 |
419 @templatekeyword('file_dels') | 419 @templatekeyword('file_dels') |
420 def showfiledels(**args): | 420 def showfiledels(**args): |
421 """List of strings. Files removed by this changeset.""" | 421 """List of strings. Files removed by this changeset.""" |
422 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | 422 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
423 return showlist('file_del', getfiles(repo, ctx, revcache)[2], | 423 return showlist('file_del', getfiles(repo, ctx, revcache)[2], args, |
424 element='file', **args) | 424 element='file') |
425 | 425 |
426 @templatekeyword('file_mods') | 426 @templatekeyword('file_mods') |
427 def showfilemods(**args): | 427 def showfilemods(**args): |
428 """List of strings. Files modified by this changeset.""" | 428 """List of strings. Files modified by this changeset.""" |
429 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] | 429 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
430 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], | 430 return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args, |
431 element='file', **args) | 431 element='file') |
432 | 432 |
433 @templatekeyword('files') | 433 @templatekeyword('files') |
434 def showfiles(**args): | 434 def showfiles(**args): |
435 """List of strings. All files modified, added, or removed by this | 435 """List of strings. All files modified, added, or removed by this |
436 changeset. | 436 changeset. |
437 """ | 437 """ |
438 return showlist('file', args['ctx'].files(), **args) | 438 return showlist('file', args['ctx'].files(), args) |
439 | 439 |
440 @templatekeyword('graphnode') | 440 @templatekeyword('graphnode') |
441 def showgraphnode(repo, ctx, **args): | 441 def showgraphnode(repo, ctx, **args): |
442 """String. The character representing the changeset node in | 442 """String. The character representing the changeset node in |
443 an ASCII revision graph""" | 443 an ASCII revision graph""" |
527 """helper method to generate a template keyword for a namespace""" | 527 """helper method to generate a template keyword for a namespace""" |
528 ctx = args['ctx'] | 528 ctx = args['ctx'] |
529 repo = ctx.repo() | 529 repo = ctx.repo() |
530 ns = repo.names[namespace] | 530 ns = repo.names[namespace] |
531 names = ns.names(repo, ctx.node()) | 531 names = ns.names(repo, ctx.node()) |
532 return showlist(ns.templatename, names, plural=namespace, **args) | 532 return showlist(ns.templatename, names, args, plural=namespace) |
533 | 533 |
534 @templatekeyword('namespaces') | 534 @templatekeyword('namespaces') |
535 def shownamespaces(**args): | 535 def shownamespaces(**args): |
536 """Dict of lists. Names attached to this changeset per | 536 """Dict of lists. Names attached to this changeset per |
537 namespace.""" | 537 namespace.""" |
538 ctx = args['ctx'] | 538 ctx = args['ctx'] |
539 repo = ctx.repo() | 539 repo = ctx.repo() |
540 namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()), | 540 namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()), |
541 **args)) | 541 args)) |
542 for k, ns in repo.names.iteritems()) | 542 for k, ns in repo.names.iteritems()) |
543 f = _showlist('namespace', list(namespaces), args) | 543 f = _showlist('namespace', list(namespaces), args) |
544 return _hybrid(f, namespaces, | 544 return _hybrid(f, namespaces, |
545 lambda k: {'namespace': k, 'names': namespaces[k]}, | 545 lambda k: {'namespace': k, 'names': namespaces[k]}, |
546 lambda x: x['namespace']) | 546 lambda x: x['namespace']) |
632 def showsubrepos(**args): | 632 def showsubrepos(**args): |
633 """List of strings. Updated subrepositories in the changeset.""" | 633 """List of strings. Updated subrepositories in the changeset.""" |
634 ctx = args['ctx'] | 634 ctx = args['ctx'] |
635 substate = ctx.substate | 635 substate = ctx.substate |
636 if not substate: | 636 if not substate: |
637 return showlist('subrepo', [], **args) | 637 return showlist('subrepo', [], args) |
638 psubstate = ctx.parents()[0].substate or {} | 638 psubstate = ctx.parents()[0].substate or {} |
639 subrepos = [] | 639 subrepos = [] |
640 for sub in substate: | 640 for sub in substate: |
641 if sub not in psubstate or substate[sub] != psubstate[sub]: | 641 if sub not in psubstate or substate[sub] != psubstate[sub]: |
642 subrepos.append(sub) # modified or newly added in ctx | 642 subrepos.append(sub) # modified or newly added in ctx |
643 for sub in psubstate: | 643 for sub in psubstate: |
644 if sub not in substate: | 644 if sub not in substate: |
645 subrepos.append(sub) # removed in ctx | 645 subrepos.append(sub) # removed in ctx |
646 return showlist('subrepo', sorted(subrepos), **args) | 646 return showlist('subrepo', sorted(subrepos), args) |
647 | 647 |
648 # don't remove "showtags" definition, even though namespaces will put | 648 # don't remove "showtags" definition, even though namespaces will put |
649 # a helper function for "tags" keyword into "keywords" map automatically, | 649 # a helper function for "tags" keyword into "keywords" map automatically, |
650 # because online help text is built without namespaces initialization | 650 # because online help text is built without namespaces initialization |
651 @templatekeyword('tags') | 651 @templatekeyword('tags') |
668 def showtroubles(**args): | 668 def showtroubles(**args): |
669 """List of strings. Evolution troubles affecting the changeset. | 669 """List of strings. Evolution troubles affecting the changeset. |
670 | 670 |
671 (EXPERIMENTAL) | 671 (EXPERIMENTAL) |
672 """ | 672 """ |
673 return showlist('trouble', args['ctx'].troubles(), **args) | 673 return showlist('trouble', args['ctx'].troubles(), args) |
674 | 674 |
675 # tell hggettext to extract docstrings from these functions: | 675 # tell hggettext to extract docstrings from these functions: |
676 i18nfunctions = keywords.values() | 676 i18nfunctions = keywords.values() |