comparison mercurial/templatekw.py @ 36591:121a20e5da56

templatekw: switch most of showlist template keywords to new API (issue5779) Non-trivial changes will follow.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Feb 2018 16:45:44 +0900
parents 0083e373e5f5
children 900e5ee44307
comparison
equal deleted inserted replaced
36590:0083e373e5f5 36591:121a20e5da56
383 committed. 383 committed.
384 """ 384 """
385 ctx = context.resource(mapping, 'ctx') 385 ctx = context.resource(mapping, 'ctx')
386 return ctx.branch() 386 return ctx.branch()
387 387
388 @templatekeyword('branches') 388 @templatekeyword('branches', requires={'ctx', 'templ'})
389 def showbranches(**args): 389 def showbranches(context, mapping):
390 """List of strings. The name of the branch on which the 390 """List of strings. The name of the branch on which the
391 changeset was committed. Will be empty if the branch name was 391 changeset was committed. Will be empty if the branch name was
392 default. (DEPRECATED) 392 default. (DEPRECATED)
393 """ 393 """
394 args = pycompat.byteskwargs(args) 394 ctx = context.resource(mapping, 'ctx')
395 branch = args['ctx'].branch() 395 branch = ctx.branch()
396 if branch != 'default': 396 if branch != 'default':
397 return showlist('branch', [branch], args, plural='branches') 397 return compatlist(context, mapping, 'branch', [branch],
398 return showlist('branch', [], args, plural='branches') 398 plural='branches')
399 return compatlist(context, mapping, 'branch', [], plural='branches')
399 400
400 @templatekeyword('bookmarks') 401 @templatekeyword('bookmarks')
401 def showbookmarks(**args): 402 def showbookmarks(**args):
402 """List of strings. Any bookmarks associated with the 403 """List of strings. Any bookmarks associated with the
403 changeset. Also sets 'active', the name of the active bookmark. 404 changeset. Also sets 'active', the name of the active bookmark.
480 c = [makemap(k) for k in extras] 481 c = [makemap(k) for k in extras]
481 f = _showlist('extra', c, args['templ'], args, plural='extras') 482 f = _showlist('extra', c, args['templ'], args, plural='extras')
482 return _hybrid(f, extras, makemap, 483 return _hybrid(f, extras, makemap,
483 lambda k: '%s=%s' % (k, util.escapestr(extras[k]))) 484 lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
484 485
485 def _showfilesbystat(args, name, index): 486 def _showfilesbystat(context, mapping, name, index):
486 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] 487 repo = context.resource(mapping, 'repo')
488 ctx = context.resource(mapping, 'ctx')
489 revcache = context.resource(mapping, 'revcache')
487 if 'files' not in revcache: 490 if 'files' not in revcache:
488 revcache['files'] = repo.status(ctx.p1(), ctx)[:3] 491 revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
489 files = revcache['files'][index] 492 files = revcache['files'][index]
490 return showlist(name, files, args, element='file') 493 return compatlist(context, mapping, name, files, element='file')
491 494
492 @templatekeyword('file_adds') 495 @templatekeyword('file_adds', requires={'repo', 'ctx', 'revcache', 'templ'})
493 def showfileadds(**args): 496 def showfileadds(context, mapping):
494 """List of strings. Files added by this changeset.""" 497 """List of strings. Files added by this changeset."""
495 args = pycompat.byteskwargs(args) 498 return _showfilesbystat(context, mapping, 'file_add', 1)
496 return _showfilesbystat(args, 'file_add', 1)
497 499
498 @templatekeyword('file_copies', 500 @templatekeyword('file_copies',
499 requires={'repo', 'ctx', 'cache', 'revcache', 'templ'}) 501 requires={'repo', 'ctx', 'cache', 'revcache', 'templ'})
500 def showfilecopies(context, mapping): 502 def showfilecopies(context, mapping):
501 """List of strings. Files copied in this changeset with 503 """List of strings. Files copied in this changeset with
532 copies = util.sortdict(copies) 534 copies = util.sortdict(copies)
533 return compatdict(context, mapping, 'file_copy', copies, 535 return compatdict(context, mapping, 'file_copy', copies,
534 key='name', value='source', fmt='%s (%s)', 536 key='name', value='source', fmt='%s (%s)',
535 plural='file_copies') 537 plural='file_copies')
536 538
537 @templatekeyword('file_dels') 539 @templatekeyword('file_dels', requires={'repo', 'ctx', 'revcache', 'templ'})
538 def showfiledels(**args): 540 def showfiledels(context, mapping):
539 """List of strings. Files removed by this changeset.""" 541 """List of strings. Files removed by this changeset."""
540 args = pycompat.byteskwargs(args) 542 return _showfilesbystat(context, mapping, 'file_del', 2)
541 return _showfilesbystat(args, 'file_del', 2) 543
542 544 @templatekeyword('file_mods', requires={'repo', 'ctx', 'revcache', 'templ'})
543 @templatekeyword('file_mods') 545 def showfilemods(context, mapping):
544 def showfilemods(**args):
545 """List of strings. Files modified by this changeset.""" 546 """List of strings. Files modified by this changeset."""
546 args = pycompat.byteskwargs(args) 547 return _showfilesbystat(context, mapping, 'file_mod', 0)
547 return _showfilesbystat(args, 'file_mod', 0) 548
548 549 @templatekeyword('files', requires={'ctx', 'templ'})
549 @templatekeyword('files') 550 def showfiles(context, mapping):
550 def showfiles(**args):
551 """List of strings. All files modified, added, or removed by this 551 """List of strings. All files modified, added, or removed by this
552 changeset. 552 changeset.
553 """ 553 """
554 args = pycompat.byteskwargs(args) 554 ctx = context.resource(mapping, 'ctx')
555 return showlist('file', args['ctx'].files(), args) 555 return compatlist(context, mapping, 'file', ctx.files())
556 556
557 @templatekeyword('graphnode', requires={'repo', 'ctx'}) 557 @templatekeyword('graphnode', requires={'repo', 'ctx'})
558 def showgraphnode(context, mapping): 558 def showgraphnode(context, mapping):
559 """String. The character representing the changeset node in an ASCII 559 """String. The character representing the changeset node in an ASCII
560 revision graph.""" 560 revision graph."""
911 f = _showlist(name, ['%d' % r for r in revs], args['templ'], args) 911 f = _showlist(name, ['%d' % r for r in revs], args['templ'], args)
912 return _hybrid(f, revs, 912 return _hybrid(f, revs,
913 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, 913 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}},
914 pycompat.identity, keytype=int) 914 pycompat.identity, keytype=int)
915 915
916 @templatekeyword('subrepos') 916 @templatekeyword('subrepos', requires={'ctx', 'templ'})
917 def showsubrepos(**args): 917 def showsubrepos(context, mapping):
918 """List of strings. Updated subrepositories in the changeset.""" 918 """List of strings. Updated subrepositories in the changeset."""
919 args = pycompat.byteskwargs(args) 919 ctx = context.resource(mapping, 'ctx')
920 ctx = args['ctx']
921 substate = ctx.substate 920 substate = ctx.substate
922 if not substate: 921 if not substate:
923 return showlist('subrepo', [], args) 922 return compatlist(context, mapping, 'subrepo', [])
924 psubstate = ctx.parents()[0].substate or {} 923 psubstate = ctx.parents()[0].substate or {}
925 subrepos = [] 924 subrepos = []
926 for sub in substate: 925 for sub in substate:
927 if sub not in psubstate or substate[sub] != psubstate[sub]: 926 if sub not in psubstate or substate[sub] != psubstate[sub]:
928 subrepos.append(sub) # modified or newly added in ctx 927 subrepos.append(sub) # modified or newly added in ctx
929 for sub in psubstate: 928 for sub in psubstate:
930 if sub not in substate: 929 if sub not in substate:
931 subrepos.append(sub) # removed in ctx 930 subrepos.append(sub) # removed in ctx
932 return showlist('subrepo', sorted(subrepos), args) 931 return compatlist(context, mapping, 'subrepo', sorted(subrepos))
933 932
934 # don't remove "showtags" definition, even though namespaces will put 933 # don't remove "showtags" definition, even though namespaces will put
935 # a helper function for "tags" keyword into "keywords" map automatically, 934 # a helper function for "tags" keyword into "keywords" map automatically,
936 # because online help text is built without namespaces initialization 935 # because online help text is built without namespaces initialization
937 @templatekeyword('tags') 936 @templatekeyword('tags')
943 def showtermwidth(context, mapping): 942 def showtermwidth(context, mapping):
944 """Integer. The width of the current terminal.""" 943 """Integer. The width of the current terminal."""
945 ui = context.resource(mapping, 'ui') 944 ui = context.resource(mapping, 'ui')
946 return ui.termwidth() 945 return ui.termwidth()
947 946
948 @templatekeyword('instabilities') 947 @templatekeyword('instabilities', requires={'ctx', 'templ'})
949 def showinstabilities(**args): 948 def showinstabilities(context, mapping):
950 """List of strings. Evolution instabilities affecting the changeset. 949 """List of strings. Evolution instabilities affecting the changeset.
951 (EXPERIMENTAL) 950 (EXPERIMENTAL)
952 """ 951 """
953 args = pycompat.byteskwargs(args) 952 ctx = context.resource(mapping, 'ctx')
954 return showlist('instability', args['ctx'].instabilities(), args, 953 return compatlist(context, mapping, 'instability', ctx.instabilities(),
955 plural='instabilities') 954 plural='instabilities')
956 955
957 @templatekeyword('verbosity', requires={'ui'}) 956 @templatekeyword('verbosity', requires={'ui'})
958 def showverbosity(context, mapping): 957 def showverbosity(context, mapping):
959 """String. The current output verbosity in 'debug', 'quiet', 'verbose', 958 """String. The current output verbosity in 'debug', 'quiet', 'verbose',
960 or ''.""" 959 or ''."""