comparison mercurial/commands.py @ 28548:b7a31068cc80

templater: add debugtemplate command This is useful for debugging template parsing. Several tests are ported to this command.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 14 Feb 2016 01:06:12 +0900
parents e0d19d955608
children 6433da9c96a9
comparison
equal deleted inserted replaced
28547:73d01cba5810 28548:b7a31068cc80
66 setdiscovery, 66 setdiscovery,
67 simplemerge, 67 simplemerge,
68 sshserver, 68 sshserver,
69 streamclone, 69 streamclone,
70 templatekw, 70 templatekw,
71 templater,
71 treediscovery, 72 treediscovery,
72 ui as uimod, 73 ui as uimod,
73 util, 74 util,
74 ) 75 )
75 76
2755 err = inst 2756 err = inst
2756 problems += 1 2757 problems += 1
2757 fm.condwrite(err, 'extensionserror', " %s\n", err) 2758 fm.condwrite(err, 'extensionserror', " %s\n", err)
2758 2759
2759 # templates 2760 # templates
2760 from . import templater
2761 p = templater.templatepaths() 2761 p = templater.templatepaths()
2762 fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p)) 2762 fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p))
2763 fm.condwrite(not p, '', _(" no template directories found\n")) 2763 fm.condwrite(not p, '', _(" no template directories found\n"))
2764 if p: 2764 if p:
2765 m = templater.templatepath("map-cmdline.default") 2765 m = templater.templatepath("map-cmdline.default")
3589 ui.write(node2str(succsset[0])) 3589 ui.write(node2str(succsset[0]))
3590 for node in succsset[1:]: 3590 for node in succsset[1:]:
3591 ui.write(' ') 3591 ui.write(' ')
3592 ui.write(node2str(node)) 3592 ui.write(node2str(node))
3593 ui.write('\n') 3593 ui.write('\n')
3594
3595 @command('debugtemplate',
3596 [('r', 'rev', [], _('apply template on changesets'), _('REV')),
3597 ('D', 'define', [], _('define template keyword'), _('KEY=VALUE'))],
3598 _('[-r REV]... [-D KEY=VALUE]... TEMPLATE'),
3599 optionalrepo=True)
3600 def debugtemplate(ui, repo, tmpl, **opts):
3601 """parse and apply a template
3602
3603 If -r/--rev is given, the template is processed as a log template and
3604 applied to the given changesets. Otherwise, it is processed as a generic
3605 template.
3606
3607 Use --verbose to print the parsed tree.
3608 """
3609 revs = None
3610 if opts['rev']:
3611 if repo is None:
3612 raise error.RepoError(_('there is no Mercurial repository here '
3613 '(.hg not found)'))
3614 revs = scmutil.revrange(repo, opts['rev'])
3615
3616 props = {}
3617 for d in opts['define']:
3618 try:
3619 k, v = (e.strip() for e in d.split('=', 1))
3620 if not k:
3621 raise ValueError
3622 props[k] = v
3623 except ValueError:
3624 raise error.Abort(_('malformed keyword definition: %s') % d)
3625
3626 if ui.verbose:
3627 tree = templater.parse(tmpl)
3628 ui.note(templater.prettyformat(tree), '\n')
3629
3630 mapfile = None
3631 if revs is None:
3632 k = 'debugtemplate'
3633 t = templater.templater(mapfile)
3634 t.cache[k] = tmpl
3635 ui.write(templater.stringify(t(k, **props)))
3636 else:
3637 displayer = cmdutil.changeset_templater(ui, repo, None, opts, tmpl,
3638 mapfile, buffered=False)
3639 for r in revs:
3640 displayer.show(repo[r], **props)
3641 displayer.close()
3594 3642
3595 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True) 3643 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True)
3596 def debugwalk(ui, repo, *pats, **opts): 3644 def debugwalk(ui, repo, *pats, **opts):
3597 """show how files match on given patterns""" 3645 """show how files match on given patterns"""
3598 m = scmutil.match(repo[None], pats, opts) 3646 m = scmutil.match(repo[None], pats, opts)