mercurial/templatekw.py
changeset 32972 26e710f0468f
parent 32970 11c0bb4ccc76
child 32973 20ca19e6c74e
equal deleted inserted replaced
32971:accfa165736b 32972:26e710f0468f
    18     encoding,
    18     encoding,
    19     error,
    19     error,
    20     hbisect,
    20     hbisect,
    21     obsutil,
    21     obsutil,
    22     patch,
    22     patch,
       
    23     pycompat,
    23     registrar,
    24     registrar,
    24     scmutil,
    25     scmutil,
    25     util,
    26     util,
    26 )
    27 )
    27 
    28 
   291 def showbranches(**args):
   292 def showbranches(**args):
   292     """List of strings. The name of the branch on which the
   293     """List of strings. The name of the branch on which the
   293     changeset was committed. Will be empty if the branch name was
   294     changeset was committed. Will be empty if the branch name was
   294     default. (DEPRECATED)
   295     default. (DEPRECATED)
   295     """
   296     """
       
   297     args = pycompat.byteskwargs(args)
   296     branch = args['ctx'].branch()
   298     branch = args['ctx'].branch()
   297     if branch != 'default':
   299     if branch != 'default':
   298         return showlist('branch', [branch], args, plural='branches')
   300         return showlist('branch', [branch], args, plural='branches')
   299     return showlist('branch', [], args, plural='branches')
   301     return showlist('branch', [], args, plural='branches')
   300 
   302 
   301 @templatekeyword('bookmarks')
   303 @templatekeyword('bookmarks')
   302 def showbookmarks(**args):
   304 def showbookmarks(**args):
   303     """List of strings. Any bookmarks associated with the
   305     """List of strings. Any bookmarks associated with the
   304     changeset. Also sets 'active', the name of the active bookmark.
   306     changeset. Also sets 'active', the name of the active bookmark.
   305     """
   307     """
       
   308     args = pycompat.byteskwargs(args)
   306     repo = args['ctx']._repo
   309     repo = args['ctx']._repo
   307     bookmarks = args['ctx'].bookmarks()
   310     bookmarks = args['ctx'].bookmarks()
   308     active = repo._activebookmark
   311     active = repo._activebookmark
   309     makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
   312     makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
   310     f = _showlist('bookmark', bookmarks, args)
   313     f = _showlist('bookmark', bookmarks, args)
   311     return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
   314     return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
   312 
   315 
   313 @templatekeyword('children')
   316 @templatekeyword('children')
   314 def showchildren(**args):
   317 def showchildren(**args):
   315     """List of strings. The children of the changeset."""
   318     """List of strings. The children of the changeset."""
       
   319     args = pycompat.byteskwargs(args)
   316     ctx = args['ctx']
   320     ctx = args['ctx']
   317     childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
   321     childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
   318     return showlist('children', childrevs, args, element='child')
   322     return showlist('children', childrevs, args, element='child')
   319 
   323 
   320 # Deprecated, but kept alive for help generation a purpose.
   324 # Deprecated, but kept alive for help generation a purpose.
   358     return '%s: +%s/-%s' % (len(stats), adds, removes)
   362     return '%s: +%s/-%s' % (len(stats), adds, removes)
   359 
   363 
   360 @templatekeyword('envvars')
   364 @templatekeyword('envvars')
   361 def showenvvars(repo, **args):
   365 def showenvvars(repo, **args):
   362     """A dictionary of environment variables. (EXPERIMENTAL)"""
   366     """A dictionary of environment variables. (EXPERIMENTAL)"""
       
   367     args = pycompat.byteskwargs(args)
   363     env = repo.ui.exportableenviron()
   368     env = repo.ui.exportableenviron()
   364     env = util.sortdict((k, env[k]) for k in sorted(env))
   369     env = util.sortdict((k, env[k]) for k in sorted(env))
   365     return showdict('envvar', env, args, plural='envvars')
   370     return showdict('envvar', env, args, plural='envvars')
   366 
   371 
   367 @templatekeyword('extras')
   372 @templatekeyword('extras')
   368 def showextras(**args):
   373 def showextras(**args):
   369     """List of dicts with key, value entries of the 'extras'
   374     """List of dicts with key, value entries of the 'extras'
   370     field of this changeset."""
   375     field of this changeset."""
       
   376     args = pycompat.byteskwargs(args)
   371     extras = args['ctx'].extra()
   377     extras = args['ctx'].extra()
   372     extras = util.sortdict((k, extras[k]) for k in sorted(extras))
   378     extras = util.sortdict((k, extras[k]) for k in sorted(extras))
   373     makemap = lambda k: {'key': k, 'value': extras[k]}
   379     makemap = lambda k: {'key': k, 'value': extras[k]}
   374     c = [makemap(k) for k in extras]
   380     c = [makemap(k) for k in extras]
   375     f = _showlist('extra', c, args, plural='extras')
   381     f = _showlist('extra', c, args, plural='extras')
   377                    lambda x: '%s=%s' % (x['key'], util.escapestr(x['value'])))
   383                    lambda x: '%s=%s' % (x['key'], util.escapestr(x['value'])))
   378 
   384 
   379 @templatekeyword('file_adds')
   385 @templatekeyword('file_adds')
   380 def showfileadds(**args):
   386 def showfileadds(**args):
   381     """List of strings. Files added by this changeset."""
   387     """List of strings. Files added by this changeset."""
       
   388     args = pycompat.byteskwargs(args)
   382     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   389     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   383     return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
   390     return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
   384                     element='file')
   391                     element='file')
   385 
   392 
   386 @templatekeyword('file_copies')
   393 @templatekeyword('file_copies')
   387 def showfilecopies(**args):
   394 def showfilecopies(**args):
   388     """List of strings. Files copied in this changeset with
   395     """List of strings. Files copied in this changeset with
   389     their sources.
   396     their sources.
   390     """
   397     """
       
   398     args = pycompat.byteskwargs(args)
   391     cache, ctx = args['cache'], args['ctx']
   399     cache, ctx = args['cache'], args['ctx']
   392     copies = args['revcache'].get('copies')
   400     copies = args['revcache'].get('copies')
   393     if copies is None:
   401     if copies is None:
   394         if 'getrenamed' not in cache:
   402         if 'getrenamed' not in cache:
   395             cache['getrenamed'] = getrenamedfn(args['repo'])
   403             cache['getrenamed'] = getrenamedfn(args['repo'])
   410 @templatekeyword('file_copies_switch')
   418 @templatekeyword('file_copies_switch')
   411 def showfilecopiesswitch(**args):
   419 def showfilecopiesswitch(**args):
   412     """List of strings. Like "file_copies" but displayed
   420     """List of strings. Like "file_copies" but displayed
   413     only if the --copied switch is set.
   421     only if the --copied switch is set.
   414     """
   422     """
       
   423     args = pycompat.byteskwargs(args)
   415     copies = args['revcache'].get('copies') or []
   424     copies = args['revcache'].get('copies') or []
   416     copies = util.sortdict(copies)
   425     copies = util.sortdict(copies)
   417     return showdict('file_copy', copies, args, plural='file_copies',
   426     return showdict('file_copy', copies, args, plural='file_copies',
   418                     key='name', value='source', fmt='%s (%s)')
   427                     key='name', value='source', fmt='%s (%s)')
   419 
   428 
   420 @templatekeyword('file_dels')
   429 @templatekeyword('file_dels')
   421 def showfiledels(**args):
   430 def showfiledels(**args):
   422     """List of strings. Files removed by this changeset."""
   431     """List of strings. Files removed by this changeset."""
       
   432     args = pycompat.byteskwargs(args)
   423     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   433     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   424     return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
   434     return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
   425                     element='file')
   435                     element='file')
   426 
   436 
   427 @templatekeyword('file_mods')
   437 @templatekeyword('file_mods')
   428 def showfilemods(**args):
   438 def showfilemods(**args):
   429     """List of strings. Files modified by this changeset."""
   439     """List of strings. Files modified by this changeset."""
       
   440     args = pycompat.byteskwargs(args)
   430     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   441     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
   431     return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
   442     return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
   432                     element='file')
   443                     element='file')
   433 
   444 
   434 @templatekeyword('files')
   445 @templatekeyword('files')
   435 def showfiles(**args):
   446 def showfiles(**args):
   436     """List of strings. All files modified, added, or removed by this
   447     """List of strings. All files modified, added, or removed by this
   437     changeset.
   448     changeset.
   438     """
   449     """
       
   450     args = pycompat.byteskwargs(args)
   439     return showlist('file', args['ctx'].files(), args)
   451     return showlist('file', args['ctx'].files(), args)
   440 
   452 
   441 @templatekeyword('graphnode')
   453 @templatekeyword('graphnode')
   442 def showgraphnode(repo, ctx, **args):
   454 def showgraphnode(repo, ctx, **args):
   443     """String. The character representing the changeset node in
   455     """String. The character representing the changeset node in
   468     """
   480     """
   469     return showlatesttags(None, **args)
   481     return showlatesttags(None, **args)
   470 
   482 
   471 def showlatesttags(pattern, **args):
   483 def showlatesttags(pattern, **args):
   472     """helper method for the latesttag keyword and function"""
   484     """helper method for the latesttag keyword and function"""
       
   485     args = pycompat.byteskwargs(args)
   473     repo, ctx = args['repo'], args['ctx']
   486     repo, ctx = args['repo'], args['ctx']
   474     cache = args['cache']
   487     cache = args['cache']
   475     latesttags = getlatesttags(repo, ctx, cache, pattern)
   488     latesttags = getlatesttags(repo, ctx, cache, pattern)
   476 
   489 
   477     # latesttag[0] is an implementation detail for sorting csets on different
   490     # latesttag[0] is an implementation detail for sorting csets on different
   524                  'node': hex(mnode)})
   537                  'node': hex(mnode)})
   525     return templ('manifest', **args)
   538     return templ('manifest', **args)
   526 
   539 
   527 def shownames(namespace, **args):
   540 def shownames(namespace, **args):
   528     """helper method to generate a template keyword for a namespace"""
   541     """helper method to generate a template keyword for a namespace"""
       
   542     args = pycompat.byteskwargs(args)
   529     ctx = args['ctx']
   543     ctx = args['ctx']
   530     repo = ctx.repo()
   544     repo = ctx.repo()
   531     ns = repo.names[namespace]
   545     ns = repo.names[namespace]
   532     names = ns.names(repo, ctx.node())
   546     names = ns.names(repo, ctx.node())
   533     return showlist(ns.templatename, names, args, plural=namespace)
   547     return showlist(ns.templatename, names, args, plural=namespace)
   534 
   548 
   535 @templatekeyword('namespaces')
   549 @templatekeyword('namespaces')
   536 def shownamespaces(**args):
   550 def shownamespaces(**args):
   537     """Dict of lists. Names attached to this changeset per
   551     """Dict of lists. Names attached to this changeset per
   538     namespace."""
   552     namespace."""
       
   553     args = pycompat.byteskwargs(args)
   539     ctx = args['ctx']
   554     ctx = args['ctx']
   540     repo = ctx.repo()
   555     repo = ctx.repo()
   541     namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
   556     namespaces = util.sortdict((k, showlist('name', ns.names(repo, ctx.node()),
   542                                             args))
   557                                             args))
   543                                for k, ns in repo.names.iteritems())
   558                                for k, ns in repo.names.iteritems())
   601 @templatekeyword('parents')
   616 @templatekeyword('parents')
   602 def showparents(**args):
   617 def showparents(**args):
   603     """List of strings. The parents of the changeset in "rev:node"
   618     """List of strings. The parents of the changeset in "rev:node"
   604     format. If the changeset has only one "natural" parent (the predecessor
   619     format. If the changeset has only one "natural" parent (the predecessor
   605     revision) nothing is shown."""
   620     revision) nothing is shown."""
       
   621     args = pycompat.byteskwargs(args)
   606     repo = args['repo']
   622     repo = args['repo']
   607     ctx = args['ctx']
   623     ctx = args['ctx']
   608     pctxs = scmutil.meaningfulparents(repo, ctx)
   624     pctxs = scmutil.meaningfulparents(repo, ctx)
   609     prevs = [str(p.rev()) for p in pctxs]  # ifcontains() needs a list of str
   625     prevs = [str(p.rev()) for p in pctxs]  # ifcontains() needs a list of str
   610     parents = [[('rev', p.rev()),
   626     parents = [[('rev', p.rev()),
   631     return scmutil.intrev(ctx)
   647     return scmutil.intrev(ctx)
   632 
   648 
   633 def showrevslist(name, revs, **args):
   649 def showrevslist(name, revs, **args):
   634     """helper to generate a list of revisions in which a mapped template will
   650     """helper to generate a list of revisions in which a mapped template will
   635     be evaluated"""
   651     be evaluated"""
       
   652     args = pycompat.byteskwargs(args)
   636     repo = args['ctx'].repo()
   653     repo = args['ctx'].repo()
   637     revs = [str(r) for r in revs]  # ifcontains() needs a list of str
   654     revs = [str(r) for r in revs]  # ifcontains() needs a list of str
   638     f = _showlist(name, revs, args)
   655     f = _showlist(name, revs, args)
   639     return _hybrid(f, revs,
   656     return _hybrid(f, revs,
   640                    lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
   657                    lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
   641                    lambda d: d[name])
   658                    lambda d: d[name])
   642 
   659 
   643 @templatekeyword('subrepos')
   660 @templatekeyword('subrepos')
   644 def showsubrepos(**args):
   661 def showsubrepos(**args):
   645     """List of strings. Updated subrepositories in the changeset."""
   662     """List of strings. Updated subrepositories in the changeset."""
       
   663     args = pycompat.byteskwargs(args)
   646     ctx = args['ctx']
   664     ctx = args['ctx']
   647     substate = ctx.substate
   665     substate = ctx.substate
   648     if not substate:
   666     if not substate:
   649         return showlist('subrepo', [], args)
   667         return showlist('subrepo', [], args)
   650     psubstate = ctx.parents()[0].substate or {}
   668     psubstate = ctx.parents()[0].substate or {}
   680 def showtroubles(**args):
   698 def showtroubles(**args):
   681     """List of strings. Evolution troubles affecting the changeset.
   699     """List of strings. Evolution troubles affecting the changeset.
   682 
   700 
   683     (EXPERIMENTAL)
   701     (EXPERIMENTAL)
   684     """
   702     """
       
   703     args = pycompat.byteskwargs(args)
   685     return showlist('trouble', args['ctx'].troubles(), args)
   704     return showlist('trouble', args['ctx'].troubles(), args)
   686 
   705 
   687 # tell hggettext to extract docstrings from these functions:
   706 # tell hggettext to extract docstrings from these functions:
   688 i18nfunctions = keywords.values()
   707 i18nfunctions = keywords.values()