Mercurial > hg
comparison mercurial/templatekw.py @ 37069:724f2e21d870
templatekw: stop using _showlist() which is about to be deprecated
Use the new context-based API instead.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 16 Mar 2018 23:01:51 +0900 |
parents | aa97e06a1912 |
children | 1101d6747d2d |
comparison
equal
deleted
inserted
replaced
37068:aa97e06a1912 | 37069:724f2e21d870 |
---|---|
229 if branch != 'default': | 229 if branch != 'default': |
230 return compatlist(context, mapping, 'branch', [branch], | 230 return compatlist(context, mapping, 'branch', [branch], |
231 plural='branches') | 231 plural='branches') |
232 return compatlist(context, mapping, 'branch', [], plural='branches') | 232 return compatlist(context, mapping, 'branch', [], plural='branches') |
233 | 233 |
234 @templatekeyword('bookmarks', requires={'repo', 'ctx', 'templ'}) | 234 @templatekeyword('bookmarks', requires={'repo', 'ctx'}) |
235 def showbookmarks(context, mapping): | 235 def showbookmarks(context, mapping): |
236 """List of strings. Any bookmarks associated with the | 236 """List of strings. Any bookmarks associated with the |
237 changeset. Also sets 'active', the name of the active bookmark. | 237 changeset. Also sets 'active', the name of the active bookmark. |
238 """ | 238 """ |
239 repo = context.resource(mapping, 'repo') | 239 repo = context.resource(mapping, 'repo') |
240 ctx = context.resource(mapping, 'ctx') | 240 ctx = context.resource(mapping, 'ctx') |
241 templ = context.resource(mapping, 'templ') | |
242 bookmarks = ctx.bookmarks() | 241 bookmarks = ctx.bookmarks() |
243 active = repo._activebookmark | 242 active = repo._activebookmark |
244 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active} | 243 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active} |
245 f = _showlist('bookmark', bookmarks, templ, mapping) | 244 f = _showcompatlist(context, mapping, 'bookmark', bookmarks) |
246 return _hybrid(f, bookmarks, makemap, pycompat.identity) | 245 return _hybrid(f, bookmarks, makemap, pycompat.identity) |
247 | 246 |
248 @templatekeyword('children', requires={'ctx'}) | 247 @templatekeyword('children', requires={'ctx'}) |
249 def showchildren(context, mapping): | 248 def showchildren(context, mapping): |
250 """List of strings. The children of the changeset.""" | 249 """List of strings. The children of the changeset.""" |
302 ui = context.resource(mapping, 'ui') | 301 ui = context.resource(mapping, 'ui') |
303 env = ui.exportableenviron() | 302 env = ui.exportableenviron() |
304 env = util.sortdict((k, env[k]) for k in sorted(env)) | 303 env = util.sortdict((k, env[k]) for k in sorted(env)) |
305 return compatdict(context, mapping, 'envvar', env, plural='envvars') | 304 return compatdict(context, mapping, 'envvar', env, plural='envvars') |
306 | 305 |
307 @templatekeyword('extras', requires={'ctx', 'templ'}) | 306 @templatekeyword('extras', requires={'ctx'}) |
308 def showextras(context, mapping): | 307 def showextras(context, mapping): |
309 """List of dicts with key, value entries of the 'extras' | 308 """List of dicts with key, value entries of the 'extras' |
310 field of this changeset.""" | 309 field of this changeset.""" |
311 ctx = context.resource(mapping, 'ctx') | 310 ctx = context.resource(mapping, 'ctx') |
312 templ = context.resource(mapping, 'templ') | |
313 extras = ctx.extra() | 311 extras = ctx.extra() |
314 extras = util.sortdict((k, extras[k]) for k in sorted(extras)) | 312 extras = util.sortdict((k, extras[k]) for k in sorted(extras)) |
315 makemap = lambda k: {'key': k, 'value': extras[k]} | 313 makemap = lambda k: {'key': k, 'value': extras[k]} |
316 c = [makemap(k) for k in extras] | 314 c = [makemap(k) for k in extras] |
317 f = _showlist('extra', c, templ, mapping, plural='extras') | 315 f = _showcompatlist(context, mapping, 'extra', c, plural='extras') |
318 return _hybrid(f, extras, makemap, | 316 return _hybrid(f, extras, makemap, |
319 lambda k: '%s=%s' % (k, util.escapestr(extras[k]))) | 317 lambda k: '%s=%s' % (k, util.escapestr(extras[k]))) |
320 | 318 |
321 def _showfilesbystat(context, mapping, name, index): | 319 def _showfilesbystat(context, mapping, name, index): |
322 repo = context.resource(mapping, 'repo') | 320 repo = context.resource(mapping, 'repo') |
422 def showindex(context, mapping): | 420 def showindex(context, mapping): |
423 """Integer. The current iteration of the loop. (0 indexed)""" | 421 """Integer. The current iteration of the loop. (0 indexed)""" |
424 # just hosts documentation; should be overridden by template mapping | 422 # just hosts documentation; should be overridden by template mapping |
425 raise error.Abort(_("can't use index in this context")) | 423 raise error.Abort(_("can't use index in this context")) |
426 | 424 |
427 @templatekeyword('latesttag', requires={'repo', 'ctx', 'cache', 'templ'}) | 425 @templatekeyword('latesttag', requires={'repo', 'ctx', 'cache'}) |
428 def showlatesttag(context, mapping): | 426 def showlatesttag(context, mapping): |
429 """List of strings. The global tags on the most recent globally | 427 """List of strings. The global tags on the most recent globally |
430 tagged ancestor of this changeset. If no such tags exist, the list | 428 tagged ancestor of this changeset. If no such tags exist, the list |
431 consists of the single string "null". | 429 consists of the single string "null". |
432 """ | 430 """ |
445 'latesttag': v, # BC with {latesttag % '{latesttag}'} | 443 'latesttag': v, # BC with {latesttag % '{latesttag}'} |
446 'tag': v | 444 'tag': v |
447 } | 445 } |
448 | 446 |
449 tags = latesttags[2] | 447 tags = latesttags[2] |
450 templ = context.resource(mapping, 'templ') | 448 f = _showcompatlist(context, mapping, 'latesttag', tags, separator=':') |
451 f = _showlist('latesttag', tags, templ, mapping, separator=':') | |
452 return _hybrid(f, tags, makemap, pycompat.identity) | 449 return _hybrid(f, tags, makemap, pycompat.identity) |
453 | 450 |
454 @templatekeyword('latesttagdistance', requires={'repo', 'ctx', 'cache'}) | 451 @templatekeyword('latesttagdistance', requires={'repo', 'ctx', 'cache'}) |
455 def showlatesttagdistance(context, mapping): | 452 def showlatesttagdistance(context, mapping): |
456 """Integer. Longest path to the latest tag.""" | 453 """Integer. Longest path to the latest tag.""" |
495 f = context.process('manifest', mapping) | 492 f = context.process('manifest', mapping) |
496 # TODO: perhaps 'ctx' should be dropped from mapping because manifest | 493 # TODO: perhaps 'ctx' should be dropped from mapping because manifest |
497 # rev and node are completely different from changeset's. | 494 # rev and node are completely different from changeset's. |
498 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) | 495 return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) |
499 | 496 |
500 @templatekeyword('obsfate', requires={'ui', 'repo', 'ctx', 'templ'}) | 497 @templatekeyword('obsfate', requires={'ui', 'repo', 'ctx'}) |
501 def showobsfate(context, mapping): | 498 def showobsfate(context, mapping): |
502 # this function returns a list containing pre-formatted obsfate strings. | 499 # this function returns a list containing pre-formatted obsfate strings. |
503 # | 500 # |
504 # This function will be replaced by templates fragments when we will have | 501 # This function will be replaced by templates fragments when we will have |
505 # the verbosity templatekw available. | 502 # the verbosity templatekw available. |
520 ns = repo.names[namespace] | 517 ns = repo.names[namespace] |
521 names = ns.names(repo, ctx.node()) | 518 names = ns.names(repo, ctx.node()) |
522 return compatlist(context, mapping, ns.templatename, names, | 519 return compatlist(context, mapping, ns.templatename, names, |
523 plural=namespace) | 520 plural=namespace) |
524 | 521 |
525 @templatekeyword('namespaces', requires={'repo', 'ctx', 'templ'}) | 522 @templatekeyword('namespaces', requires={'repo', 'ctx'}) |
526 def shownamespaces(context, mapping): | 523 def shownamespaces(context, mapping): |
527 """Dict of lists. Names attached to this changeset per | 524 """Dict of lists. Names attached to this changeset per |
528 namespace.""" | 525 namespace.""" |
529 repo = context.resource(mapping, 'repo') | 526 repo = context.resource(mapping, 'repo') |
530 ctx = context.resource(mapping, 'ctx') | 527 ctx = context.resource(mapping, 'ctx') |
531 templ = context.resource(mapping, 'templ') | |
532 | 528 |
533 namespaces = util.sortdict() | 529 namespaces = util.sortdict() |
534 def makensmapfn(ns): | 530 def makensmapfn(ns): |
535 # 'name' for iterating over namespaces, templatename for local reference | 531 # 'name' for iterating over namespaces, templatename for local reference |
536 return lambda v: {'name': v, ns.templatename: v} | 532 return lambda v: {'name': v, ns.templatename: v} |
537 | 533 |
538 for k, ns in repo.names.iteritems(): | 534 for k, ns in repo.names.iteritems(): |
539 names = ns.names(repo, ctx.node()) | 535 names = ns.names(repo, ctx.node()) |
540 f = _showlist('name', names, templ, mapping) | 536 f = _showcompatlist(context, mapping, 'name', names) |
541 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity) | 537 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity) |
542 | 538 |
543 f = _showlist('namespace', list(namespaces), templ, mapping) | 539 f = _showcompatlist(context, mapping, 'namespace', list(namespaces)) |
544 | 540 |
545 def makemap(ns): | 541 def makemap(ns): |
546 return { | 542 return { |
547 'namespace': ns, | 543 'namespace': ns, |
548 'names': namespaces[ns], | 544 'names': namespaces[ns], |
631 yield "; ".join(render(d) for d in data) | 627 yield "; ".join(render(d) for d in data) |
632 | 628 |
633 return _hybrid(gen(data), data, lambda x: {'successorset': x}, | 629 return _hybrid(gen(data), data, lambda x: {'successorset': x}, |
634 pycompat.identity) | 630 pycompat.identity) |
635 | 631 |
636 @templatekeyword("succsandmarkers", requires={'repo', 'ctx', 'templ'}) | 632 @templatekeyword("succsandmarkers", requires={'repo', 'ctx'}) |
637 def showsuccsandmarkers(context, mapping): | 633 def showsuccsandmarkers(context, mapping): |
638 """Returns a list of dict for each final successor of ctx. The dict | 634 """Returns a list of dict for each final successor of ctx. The dict |
639 contains successors node id in "successors" keys and the list of | 635 contains successors node id in "successors" keys and the list of |
640 obs-markers from ctx to the set of successors in "markers". | 636 obs-markers from ctx to the set of successors in "markers". |
641 (EXPERIMENTAL) | 637 (EXPERIMENTAL) |
642 """ | 638 """ |
643 repo = context.resource(mapping, 'repo') | 639 repo = context.resource(mapping, 'repo') |
644 ctx = context.resource(mapping, 'ctx') | 640 ctx = context.resource(mapping, 'ctx') |
645 templ = context.resource(mapping, 'templ') | |
646 | 641 |
647 values = obsutil.successorsandmarkers(repo, ctx) | 642 values = obsutil.successorsandmarkers(repo, ctx) |
648 | 643 |
649 if values is None: | 644 if values is None: |
650 values = [] | 645 values = [] |
671 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] | 666 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] |
672 finalmarkers.append(newmarker) | 667 finalmarkers.append(newmarker) |
673 | 668 |
674 data.append({'successors': successors, 'markers': finalmarkers}) | 669 data.append({'successors': successors, 'markers': finalmarkers}) |
675 | 670 |
676 f = _showlist('succsandmarkers', data, templ, mapping) | 671 f = _showcompatlist(context, mapping, 'succsandmarkers', data) |
677 return _hybrid(f, data, lambda x: x, pycompat.identity) | 672 return _hybrid(f, data, lambda x: x, pycompat.identity) |
678 | 673 |
679 @templatekeyword('p1rev', requires={'ctx'}) | 674 @templatekeyword('p1rev', requires={'ctx'}) |
680 def showp1rev(context, mapping): | 675 def showp1rev(context, mapping): |
681 """Integer. The repository-local revision number of the changeset's | 676 """Integer. The repository-local revision number of the changeset's |
704 parent, as a 40 digit hexadecimal string. If the changeset has no second | 699 parent, as a 40 digit hexadecimal string. If the changeset has no second |
705 parent, all digits are 0.""" | 700 parent, all digits are 0.""" |
706 ctx = context.resource(mapping, 'ctx') | 701 ctx = context.resource(mapping, 'ctx') |
707 return ctx.p2().hex() | 702 return ctx.p2().hex() |
708 | 703 |
709 @templatekeyword('parents', requires={'repo', 'ctx', 'templ'}) | 704 @templatekeyword('parents', requires={'repo', 'ctx'}) |
710 def showparents(context, mapping): | 705 def showparents(context, mapping): |
711 """List of strings. The parents of the changeset in "rev:node" | 706 """List of strings. The parents of the changeset in "rev:node" |
712 format. If the changeset has only one "natural" parent (the predecessor | 707 format. If the changeset has only one "natural" parent (the predecessor |
713 revision) nothing is shown.""" | 708 revision) nothing is shown.""" |
714 repo = context.resource(mapping, 'repo') | 709 repo = context.resource(mapping, 'repo') |
715 ctx = context.resource(mapping, 'ctx') | 710 ctx = context.resource(mapping, 'ctx') |
716 templ = context.resource(mapping, 'templ') | |
717 pctxs = scmutil.meaningfulparents(repo, ctx) | 711 pctxs = scmutil.meaningfulparents(repo, ctx) |
718 prevs = [p.rev() for p in pctxs] | 712 prevs = [p.rev() for p in pctxs] |
719 parents = [[('rev', p.rev()), | 713 parents = [[('rev', p.rev()), |
720 ('node', p.hex()), | 714 ('node', p.hex()), |
721 ('phase', p.phasestr())] | 715 ('phase', p.phasestr())] |
722 for p in pctxs] | 716 for p in pctxs] |
723 f = _showlist('parent', parents, templ, mapping) | 717 f = _showcompatlist(context, mapping, 'parent', parents) |
724 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, | 718 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, |
725 lambda x: scmutil.formatchangeid(repo[x]), keytype=int) | 719 lambda x: scmutil.formatchangeid(repo[x]), keytype=int) |
726 | 720 |
727 @templatekeyword('phase', requires={'ctx'}) | 721 @templatekeyword('phase', requires={'ctx'}) |
728 def showphase(context, mapping): | 722 def showphase(context, mapping): |
744 | 738 |
745 def showrevslist(context, mapping, name, revs): | 739 def showrevslist(context, mapping, name, revs): |
746 """helper to generate a list of revisions in which a mapped template will | 740 """helper to generate a list of revisions in which a mapped template will |
747 be evaluated""" | 741 be evaluated""" |
748 repo = context.resource(mapping, 'repo') | 742 repo = context.resource(mapping, 'repo') |
749 templ = context.resource(mapping, 'templ') | 743 f = _showcompatlist(context, mapping, name, ['%d' % r for r in revs]) |
750 f = _showlist(name, ['%d' % r for r in revs], templ, mapping) | |
751 return _hybrid(f, revs, | 744 return _hybrid(f, revs, |
752 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, | 745 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, |
753 pycompat.identity, keytype=int) | 746 pycompat.identity, keytype=int) |
754 | 747 |
755 @templatekeyword('subrepos', requires={'ctx'}) | 748 @templatekeyword('subrepos', requires={'ctx'}) |