Show More
@@ -68,6 +68,7 b' from . import (' | |||
|
68 | 68 | sshserver, |
|
69 | 69 | streamclone, |
|
70 | 70 | templatekw, |
|
71 | templater, | |
|
71 | 72 | treediscovery, |
|
72 | 73 | ui as uimod, |
|
73 | 74 | util, |
@@ -2757,7 +2758,6 b' def debuginstall(ui, **opts):' | |||
|
2757 | 2758 | fm.condwrite(err, 'extensionserror', " %s\n", err) |
|
2758 | 2759 | |
|
2759 | 2760 | # templates |
|
2760 | from . import templater | |
|
2761 | 2761 | p = templater.templatepaths() |
|
2762 | 2762 | fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p)) |
|
2763 | 2763 | fm.condwrite(not p, '', _(" no template directories found\n")) |
@@ -3592,6 +3592,54 b' def debugsuccessorssets(ui, repo, *revs)' | |||
|
3592 | 3592 | ui.write(node2str(node)) |
|
3593 | 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 | 3643 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True) |
|
3596 | 3644 | def debugwalk(ui, repo, *pats, **opts): |
|
3597 | 3645 | """show how files match on given patterns""" |
@@ -2861,27 +2861,55 b' Test invalid date:' | |||
|
2861 | 2861 | |
|
2862 | 2862 | Test integer literal: |
|
2863 | 2863 | |
|
2864 |
$ hg |
|
|
2864 | $ hg debugtemplate -v '{(0)}\n' | |
|
2865 | (template | |
|
2866 | (group | |
|
2867 | ('integer', '0')) | |
|
2868 | ('string', '\n')) | |
|
2865 | 2869 | 0 |
|
2866 |
$ hg |
|
|
2870 | $ hg debugtemplate -v '{(123)}\n' | |
|
2871 | (template | |
|
2872 | (group | |
|
2873 | ('integer', '123')) | |
|
2874 | ('string', '\n')) | |
|
2867 | 2875 | 123 |
|
2868 |
$ hg |
|
|
2876 | $ hg debugtemplate -v '{(-4)}\n' | |
|
2877 | (template | |
|
2878 | (group | |
|
2879 | ('integer', '-4')) | |
|
2880 | ('string', '\n')) | |
|
2869 | 2881 | -4 |
|
2870 |
$ hg |
|
|
2882 | $ hg debugtemplate '{(-)}\n' | |
|
2871 | 2883 | hg: parse error at 2: integer literal without digits |
|
2872 | 2884 | [255] |
|
2873 |
$ hg |
|
|
2885 | $ hg debugtemplate '{(-a)}\n' | |
|
2874 | 2886 | hg: parse error at 2: integer literal without digits |
|
2875 | 2887 | [255] |
|
2876 | 2888 | |
|
2877 | 2889 | top-level integer literal is interpreted as symbol (i.e. variable name): |
|
2878 | 2890 | |
|
2879 | $ hg log -Ra -r0 -T '{1}\n' | |
|
2880 | ||
|
2881 | $ hg log -Ra -r0 -T '{if("t", "{1}")}\n' | |
|
2882 | ||
|
2883 | $ hg log -Ra -r0 -T '{1|stringify}\n' | |
|
2884 | ||
|
2891 | $ hg debugtemplate -D 1=one -v '{1}\n' | |
|
2892 | (template | |
|
2893 | ('integer', '1') | |
|
2894 | ('string', '\n')) | |
|
2895 | one | |
|
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 | 2914 | unless explicit symbol is expected: |
|
2887 | 2915 | |
@@ -2894,13 +2922,29 b' unless explicit symbol is expected:' | |||
|
2894 | 2922 | |
|
2895 | 2923 | Test string literal: |
|
2896 | 2924 | |
|
2897 |
$ hg |
|
|
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 | 2929 | string with no template fragment |
|
2899 |
$ hg |
|
|
2930 | $ hg debugtemplate -Ra -r0 -v '{"template: {rev}"}\n' | |
|
2931 | (template | |
|
2932 | (template | |
|
2933 | ('string', 'template: ') | |
|
2934 | ('symbol', 'rev')) | |
|
2935 | ('string', '\n')) | |
|
2900 | 2936 | template: 0 |
|
2901 |
$ hg |
|
|
2937 | $ hg debugtemplate -Ra -r0 -v '{r"rawstring: {rev}"}\n' | |
|
2938 | (template | |
|
2939 | ('string', 'rawstring: {rev}') | |
|
2940 | ('string', '\n')) | |
|
2902 | 2941 | rawstring: {rev} |
|
2903 |
$ hg |
|
|
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 | 2948 | rawstring: {file} |
|
2905 | 2949 | |
|
2906 | 2950 | Test string escaping: |
@@ -108,6 +108,7 b' Show debug commands if there are no othe' | |||
|
108 | 108 | debugsetparents |
|
109 | 109 | debugsub |
|
110 | 110 | debugsuccessorssets |
|
111 | debugtemplate | |
|
111 | 112 | debugwalk |
|
112 | 113 | debugwireargs |
|
113 | 114 | |
@@ -272,6 +273,7 b' Show all commands + options' | |||
|
272 | 273 | debugsetparents: |
|
273 | 274 | debugsub: rev |
|
274 | 275 | debugsuccessorssets: |
|
276 | debugtemplate: rev, define | |
|
275 | 277 | debugwalk: include, exclude |
|
276 | 278 | debugwireargs: three, four, five, ssh, remotecmd, insecure |
|
277 | 279 | files: rev, print0, include, exclude, template, subrepos |
@@ -861,6 +861,8 b' Test list of internal help commands' | |||
|
861 | 861 | debugsub (no help text available) |
|
862 | 862 | debugsuccessorssets |
|
863 | 863 | show set of successors for revision |
|
864 | debugtemplate | |
|
865 | parse and apply a template | |
|
864 | 866 | debugwalk show how files match on given patterns |
|
865 | 867 | debugwireargs |
|
866 | 868 | (no help text available) |
General Comments 0
You need to be logged in to leave comments.
Login now