mercurial/templatekw.py
changeset 36520 a7fbe11a5d59
parent 36519 94c4ae452293
child 36521 c3692364b344
equal deleted inserted replaced
36519:94c4ae452293 36520:a7fbe11a5d59
   133         return value
   133         return value
   134     if util.safehasattr(value, '_makemap'):
   134     if util.safehasattr(value, '_makemap'):
   135         # a nested hybrid list/dict, which has its own way of map operation
   135         # a nested hybrid list/dict, which has its own way of map operation
   136         return value
   136         return value
   137     return _mappable(None, key, value, makemap)
   137     return _mappable(None, key, value, makemap)
       
   138 
       
   139 def compatdict(context, mapping, name, data, key='key', value='value',
       
   140                fmt='%s=%s', plural=None, separator=' '):
       
   141     """Wrap data like hybriddict(), but also supports old-style list template
       
   142 
       
   143     This exists for backward compatibility with the old-style template. Use
       
   144     hybriddict() for new template keywords.
       
   145     """
       
   146     c = [{key: k, value: v} for k, v in data.iteritems()]
       
   147     t = context.resource(mapping, 'templ')
       
   148     f = _showlist(name, c, t, mapping, plural, separator)
       
   149     return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
   138 
   150 
   139 def showdict(name, data, mapping, plural=None, key='key', value='value',
   151 def showdict(name, data, mapping, plural=None, key='key', value='value',
   140              fmt='%s=%s', separator=' '):
   152              fmt='%s=%s', separator=' '):
   141     c = [{key: k, value: v} for k, v in data.iteritems()]
   153     c = [{key: k, value: v} for k, v in data.iteritems()]
   142     f = _showlist(name, c, mapping['templ'], mapping, plural, separator)
   154     f = _showlist(name, c, mapping['templ'], mapping, plural, separator)
   435     ctx = context.resource(mapping, 'ctx')
   447     ctx = context.resource(mapping, 'ctx')
   436     stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
   448     stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
   437     maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
   449     maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
   438     return '%d: +%d/-%d' % (len(stats), adds, removes)
   450     return '%d: +%d/-%d' % (len(stats), adds, removes)
   439 
   451 
   440 @templatekeyword('envvars')
   452 @templatekeyword('envvars', requires={'ui', 'templ'})
   441 def showenvvars(ui, **args):
   453 def showenvvars(context, mapping):
   442     """A dictionary of environment variables. (EXPERIMENTAL)"""
   454     """A dictionary of environment variables. (EXPERIMENTAL)"""
   443     args = pycompat.byteskwargs(args)
   455     ui = context.resource(mapping, 'ui')
   444     env = ui.exportableenviron()
   456     env = ui.exportableenviron()
   445     env = util.sortdict((k, env[k]) for k in sorted(env))
   457     env = util.sortdict((k, env[k]) for k in sorted(env))
   446     return showdict('envvar', env, args, plural='envvars')
   458     return compatdict(context, mapping, 'envvar', env, plural='envvars')
   447 
   459 
   448 @templatekeyword('extras')
   460 @templatekeyword('extras')
   449 def showextras(**args):
   461 def showextras(**args):
   450     """List of dicts with key, value entries of the 'extras'
   462     """List of dicts with key, value entries of the 'extras'
   451     field of this changeset."""
   463     field of this changeset."""