75 """Return an object which can be stringified possibly by using a legacy |
75 """Return an object which can be stringified possibly by using a legacy |
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 |
|
81 def showdict(name, data, mapping, plural=None, key='key', value='value', |
|
82 fmt='%s=%s', separator=' '): |
|
83 c = [{key: k, value: v} for k, v in data.iteritems()] |
|
84 f = _showlist(name, c, mapping, plural, separator) |
|
85 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
80 |
86 |
81 def showlist(name, values, mapping, plural=None, element=None, separator=' '): |
87 def showlist(name, values, mapping, plural=None, element=None, separator=' '): |
82 if not element: |
88 if not element: |
83 element = name |
89 element = name |
84 f = _showlist(name, values, mapping, plural, separator) |
90 f = _showlist(name, values, mapping, plural, separator) |
346 return '%s: +%s/-%s' % (len(stats), adds, removes) |
352 return '%s: +%s/-%s' % (len(stats), adds, removes) |
347 |
353 |
348 @templatekeyword('envvars') |
354 @templatekeyword('envvars') |
349 def showenvvars(repo, **args): |
355 def showenvvars(repo, **args): |
350 """A dictionary of environment variables. (EXPERIMENTAL)""" |
356 """A dictionary of environment variables. (EXPERIMENTAL)""" |
351 |
|
352 env = repo.ui.exportableenviron() |
357 env = repo.ui.exportableenviron() |
353 env = util.sortdict((k, env[k]) for k in sorted(env)) |
358 env = util.sortdict((k, env[k]) for k in sorted(env)) |
354 makemap = lambda k: {'key': k, 'value': env[k]} |
359 return showdict('envvar', env, args, plural='envvars') |
355 c = [makemap(k) for k in env] |
|
356 f = _showlist('envvar', c, args, plural='envvars') |
|
357 return _hybrid(f, env, makemap, |
|
358 lambda x: '%s=%s' % (x['key'], x['value'])) |
|
359 |
360 |
360 @templatekeyword('extras') |
361 @templatekeyword('extras') |
361 def showextras(**args): |
362 def showextras(**args): |
362 """List of dicts with key, value entries of the 'extras' |
363 """List of dicts with key, value entries of the 'extras' |
363 field of this changeset.""" |
364 field of this changeset.""" |
392 rename = getrenamed(fn, ctx.rev()) |
393 rename = getrenamed(fn, ctx.rev()) |
393 if rename: |
394 if rename: |
394 copies.append((fn, rename[0])) |
395 copies.append((fn, rename[0])) |
395 |
396 |
396 copies = util.sortdict(copies) |
397 copies = util.sortdict(copies) |
397 makemap = lambda k: {'name': k, 'source': copies[k]} |
398 return showdict('file_copy', copies, args, plural='file_copies', |
398 c = [makemap(k) for k in copies] |
399 key='name', value='source', fmt='%s (%s)') |
399 f = _showlist('file_copy', c, args, plural='file_copies') |
|
400 return _hybrid(f, copies, makemap, |
|
401 lambda x: '%s (%s)' % (x['name'], x['source'])) |
|
402 |
400 |
403 # showfilecopiesswitch() displays file copies only if copy records are |
401 # showfilecopiesswitch() displays file copies only if copy records are |
404 # provided before calling the templater, usually with a --copies |
402 # provided before calling the templater, usually with a --copies |
405 # command line switch. |
403 # command line switch. |
406 @templatekeyword('file_copies_switch') |
404 @templatekeyword('file_copies_switch') |
408 """List of strings. Like "file_copies" but displayed |
406 """List of strings. Like "file_copies" but displayed |
409 only if the --copied switch is set. |
407 only if the --copied switch is set. |
410 """ |
408 """ |
411 copies = args['revcache'].get('copies') or [] |
409 copies = args['revcache'].get('copies') or [] |
412 copies = util.sortdict(copies) |
410 copies = util.sortdict(copies) |
413 makemap = lambda k: {'name': k, 'source': copies[k]} |
411 return showdict('file_copy', copies, args, plural='file_copies', |
414 c = [makemap(k) for k in copies] |
412 key='name', value='source', fmt='%s (%s)') |
415 f = _showlist('file_copy', c, args, plural='file_copies') |
|
416 return _hybrid(f, copies, makemap, |
|
417 lambda x: '%s (%s)' % (x['name'], x['source'])) |
|
418 |
413 |
419 @templatekeyword('file_dels') |
414 @templatekeyword('file_dels') |
420 def showfiledels(**args): |
415 def showfiledels(**args): |
421 """List of strings. Files removed by this changeset.""" |
416 """List of strings. Files removed by this changeset.""" |
422 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |
417 repo, ctx, revcache = args['repo'], args['ctx'], args['revcache'] |