##// END OF EJS Templates
templater: add debugtemplate command...
Yuya Nishihara -
r28548:b7a31068 default
parent child Browse files
Show More
@@ -68,6 +68,7 b' from . import ('
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,
@@ -2757,7 +2758,6 b' def debuginstall(ui, **opts):'
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"))
@@ -3592,6 +3592,54 b' def debugsuccessorssets(ui, repo, *revs)'
3592 ui.write(node2str(node))
3592 ui.write(node2str(node))
3593 ui.write('\n')
3593 ui.write('\n')
3594
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()
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"""
@@ -2861,27 +2861,55 b' Test invalid date:'
2861
2861
2862 Test integer literal:
2862 Test integer literal:
2863
2863
2864 $ hg log -Ra -r0 -T '{(0)}\n'
2864 $ hg debugtemplate -v '{(0)}\n'
2865 (template
2866 (group
2867 ('integer', '0'))
2868 ('string', '\n'))
2865 0
2869 0
2866 $ hg log -Ra -r0 -T '{(123)}\n'
2870 $ hg debugtemplate -v '{(123)}\n'
2871 (template
2872 (group
2873 ('integer', '123'))
2874 ('string', '\n'))
2867 123
2875 123
2868 $ hg log -Ra -r0 -T '{(-4)}\n'
2876 $ hg debugtemplate -v '{(-4)}\n'
2877 (template
2878 (group
2879 ('integer', '-4'))
2880 ('string', '\n'))
2869 -4
2881 -4
2870 $ hg log -Ra -r0 -T '{(-)}\n'
2882 $ hg debugtemplate '{(-)}\n'
2871 hg: parse error at 2: integer literal without digits
2883 hg: parse error at 2: integer literal without digits
2872 [255]
2884 [255]
2873 $ hg log -Ra -r0 -T '{(-a)}\n'
2885 $ hg debugtemplate '{(-a)}\n'
2874 hg: parse error at 2: integer literal without digits
2886 hg: parse error at 2: integer literal without digits
2875 [255]
2887 [255]
2876
2888
2877 top-level integer literal is interpreted as symbol (i.e. variable name):
2889 top-level integer literal is interpreted as symbol (i.e. variable name):
2878
2890
2879 $ hg log -Ra -r0 -T '{1}\n'
2891 $ hg debugtemplate -D 1=one -v '{1}\n'
2880
2892 (template
2881 $ hg log -Ra -r0 -T '{if("t", "{1}")}\n'
2893 ('integer', '1')
2882
2894 ('string', '\n'))
2883 $ hg log -Ra -r0 -T '{1|stringify}\n'
2895 one
2884
2896 $ hg debugtemplate -D 1=one -v '{if("t", "{1}")}\n'
2897 (template
2898 (func
2899 ('symbol', 'if')
2900 (list
2901 ('string', 't')
2902 (template
2903 ('integer', '1'))))
2904 ('string', '\n'))
2905 one
2906 $ hg debugtemplate -D 1=one -v '{1|stringify}\n'
2907 (template
2908 (|
2909 ('integer', '1')
2910 ('symbol', 'stringify'))
2911 ('string', '\n'))
2912 one
2885
2913
2886 unless explicit symbol is expected:
2914 unless explicit symbol is expected:
2887
2915
@@ -2894,13 +2922,29 b' unless explicit symbol is expected:'
2894
2922
2895 Test string literal:
2923 Test string literal:
2896
2924
2897 $ hg log -Ra -r0 -T '{"string with no template fragment"}\n'
2925 $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n'
2926 (template
2927 ('string', 'string with no template fragment')
2928 ('string', '\n'))
2898 string with no template fragment
2929 string with no template fragment
2899 $ hg log -Ra -r0 -T '{"template: {rev}"}\n'
2930 $ hg debugtemplate -Ra -r0 -v '{"template: {rev}"}\n'
2931 (template
2932 (template
2933 ('string', 'template: ')
2934 ('symbol', 'rev'))
2935 ('string', '\n'))
2900 template: 0
2936 template: 0
2901 $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n'
2937 $ hg debugtemplate -Ra -r0 -v '{r"rawstring: {rev}"}\n'
2938 (template
2939 ('string', 'rawstring: {rev}')
2940 ('string', '\n'))
2902 rawstring: {rev}
2941 rawstring: {rev}
2903 $ hg log -Ra -r0 -T '{files % r"rawstring: {file}"}\n'
2942 $ hg debugtemplate -Ra -r0 -v '{files % r"rawstring: {file}"}\n'
2943 (template
2944 (%
2945 ('symbol', 'files')
2946 ('string', 'rawstring: {file}'))
2947 ('string', '\n'))
2904 rawstring: {file}
2948 rawstring: {file}
2905
2949
2906 Test string escaping:
2950 Test string escaping:
@@ -108,6 +108,7 b' Show debug commands if there are no othe'
108 debugsetparents
108 debugsetparents
109 debugsub
109 debugsub
110 debugsuccessorssets
110 debugsuccessorssets
111 debugtemplate
111 debugwalk
112 debugwalk
112 debugwireargs
113 debugwireargs
113
114
@@ -272,6 +273,7 b' Show all commands + options'
272 debugsetparents:
273 debugsetparents:
273 debugsub: rev
274 debugsub: rev
274 debugsuccessorssets:
275 debugsuccessorssets:
276 debugtemplate: rev, define
275 debugwalk: include, exclude
277 debugwalk: include, exclude
276 debugwireargs: three, four, five, ssh, remotecmd, insecure
278 debugwireargs: three, four, five, ssh, remotecmd, insecure
277 files: rev, print0, include, exclude, template, subrepos
279 files: rev, print0, include, exclude, template, subrepos
@@ -861,6 +861,8 b' Test list of internal help commands'
861 debugsub (no help text available)
861 debugsub (no help text available)
862 debugsuccessorssets
862 debugsuccessorssets
863 show set of successors for revision
863 show set of successors for revision
864 debugtemplate
865 parse and apply a template
864 debugwalk show how files match on given patterns
866 debugwalk show how files match on given patterns
865 debugwireargs
867 debugwireargs
866 (no help text available)
868 (no help text available)
General Comments 0
You need to be logged in to leave comments. Login now