Show More
@@ -351,7 +351,8 b' class templatefunc(_templateregistrarbas' | |||||
351 |
|
351 | |||
352 | templatefunc = registrar.templatefunc() |
|
352 | templatefunc = registrar.templatefunc() | |
353 |
|
353 | |||
354 |
@templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3' |
|
354 | @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3', | |
|
355 | requires={'ctx'}) | |||
355 | def myfuncfunc(context, mapping, args): |
|
356 | def myfuncfunc(context, mapping, args): | |
356 | '''Explanation of this template function .... |
|
357 | '''Explanation of this template function .... | |
357 | ''' |
|
358 | ''' | |
@@ -363,6 +364,9 b' class templatefunc(_templateregistrarbas' | |||||
363 | a dict of named arguments. Otherwise 'args' is a list of positional |
|
364 | a dict of named arguments. Otherwise 'args' is a list of positional | |
364 | arguments. |
|
365 | arguments. | |
365 |
|
366 | |||
|
367 | Optional argument 'requires' should be a collection of resource names | |||
|
368 | which the template function depends on. | |||
|
369 | ||||
366 | 'templatefunc' instance in example above can be used to |
|
370 | 'templatefunc' instance in example above can be used to | |
367 | decorate multiple functions. |
|
371 | decorate multiple functions. | |
368 |
|
372 | |||
@@ -374,8 +378,9 b' class templatefunc(_templateregistrarbas' | |||||
374 | """ |
|
378 | """ | |
375 | _getname = _funcregistrarbase._parsefuncdecl |
|
379 | _getname = _funcregistrarbase._parsefuncdecl | |
376 |
|
380 | |||
377 | def _extrasetup(self, name, func, argspec=None): |
|
381 | def _extrasetup(self, name, func, argspec=None, requires=()): | |
378 | func._argspec = argspec |
|
382 | func._argspec = argspec | |
|
383 | func._requires = requires | |||
379 |
|
384 | |||
380 | class internalmerge(_funcregistrarbase): |
|
385 | class internalmerge(_funcregistrarbase): | |
381 | """Decorator to register in-process merge tool |
|
386 | """Decorator to register in-process merge tool |
@@ -85,7 +85,7 b' def dict_(context, mapping, args):' | |||||
85 | for k, v in args['kwargs'].iteritems()) |
|
85 | for k, v in args['kwargs'].iteritems()) | |
86 | return templateutil.hybriddict(data) |
|
86 | return templateutil.hybriddict(data) | |
87 |
|
87 | |||
88 | @templatefunc('diff([includepattern [, excludepattern]])') |
|
88 | @templatefunc('diff([includepattern [, excludepattern]])', requires={'ctx'}) | |
89 | def diff(context, mapping, args): |
|
89 | def diff(context, mapping, args): | |
90 | """Show a diff, optionally |
|
90 | """Show a diff, optionally | |
91 | specifying files to include or exclude.""" |
|
91 | specifying files to include or exclude.""" | |
@@ -105,7 +105,7 b' def diff(context, mapping, args):' | |||||
105 |
|
105 | |||
106 | return ''.join(chunks) |
|
106 | return ''.join(chunks) | |
107 |
|
107 | |||
108 | @templatefunc('extdata(source)', argspec='source') |
|
108 | @templatefunc('extdata(source)', argspec='source', requires={'ctx', 'cache'}) | |
109 | def extdata(context, mapping, args): |
|
109 | def extdata(context, mapping, args): | |
110 | """Show a text read from the specified extdata source. (EXPERIMENTAL)""" |
|
110 | """Show a text read from the specified extdata source. (EXPERIMENTAL)""" | |
111 | if 'source' not in args: |
|
111 | if 'source' not in args: | |
@@ -128,7 +128,7 b' def extdata(context, mapping, args):' | |||||
128 | data = cache[source] = scmutil.extdatasource(ctx.repo(), source) |
|
128 | data = cache[source] = scmutil.extdatasource(ctx.repo(), source) | |
129 | return data.get(ctx.rev(), '') |
|
129 | return data.get(ctx.rev(), '') | |
130 |
|
130 | |||
131 | @templatefunc('files(pattern)') |
|
131 | @templatefunc('files(pattern)', requires={'ctx'}) | |
132 | def files(context, mapping, args): |
|
132 | def files(context, mapping, args): | |
133 | """All files of the current changeset matching the pattern. See |
|
133 | """All files of the current changeset matching the pattern. See | |
134 | :hg:`help patterns`.""" |
|
134 | :hg:`help patterns`.""" | |
@@ -166,7 +166,7 b' def fill(context, mapping, args):' | |||||
166 |
|
166 | |||
167 | return templatefilters.fill(text, width, initindent, hangindent) |
|
167 | return templatefilters.fill(text, width, initindent, hangindent) | |
168 |
|
168 | |||
169 | @templatefunc('formatnode(node)') |
|
169 | @templatefunc('formatnode(node)', requires={'ui'}) | |
170 | def formatnode(context, mapping, args): |
|
170 | def formatnode(context, mapping, args): | |
171 | """Obtain the preferred form of a changeset hash. (DEPRECATED)""" |
|
171 | """Obtain the preferred form of a changeset hash. (DEPRECATED)""" | |
172 | if len(args) != 1: |
|
172 | if len(args) != 1: | |
@@ -179,7 +179,7 b' def formatnode(context, mapping, args):' | |||||
179 | return node |
|
179 | return node | |
180 | return templatefilters.short(node) |
|
180 | return templatefilters.short(node) | |
181 |
|
181 | |||
182 | @templatefunc('mailmap(author)') |
|
182 | @templatefunc('mailmap(author)', requires={'repo', 'cache'}) | |
183 | def mailmap(context, mapping, args): |
|
183 | def mailmap(context, mapping, args): | |
184 | """Return the author, updated according to the value |
|
184 | """Return the author, updated according to the value | |
185 | set in the .mailmap file""" |
|
185 | set in the .mailmap file""" | |
@@ -331,7 +331,7 b' def join(context, mapping, args):' | |||||
331 | joiner = evalstring(context, mapping, args[1]) |
|
331 | joiner = evalstring(context, mapping, args[1]) | |
332 | return joinset.join(context, mapping, joiner) |
|
332 | return joinset.join(context, mapping, joiner) | |
333 |
|
333 | |||
334 | @templatefunc('label(label, expr)') |
|
334 | @templatefunc('label(label, expr)', requires={'ui'}) | |
335 | def label(context, mapping, args): |
|
335 | def label(context, mapping, args): | |
336 | """Apply a label to generated content. Content with |
|
336 | """Apply a label to generated content. Content with | |
337 | a label applied can result in additional post-processing, such as |
|
337 | a label applied can result in additional post-processing, such as | |
@@ -504,7 +504,7 b' def obsfateverb(context, mapping, args):' | |||||
504 | errmsg = _("obsfateverb first argument should be countable") |
|
504 | errmsg = _("obsfateverb first argument should be countable") | |
505 | raise error.ParseError(errmsg) |
|
505 | raise error.ParseError(errmsg) | |
506 |
|
506 | |||
507 | @templatefunc('relpath(path)') |
|
507 | @templatefunc('relpath(path)', requires={'repo'}) | |
508 | def relpath(context, mapping, args): |
|
508 | def relpath(context, mapping, args): | |
509 | """Convert a repository-absolute path into a filesystem path relative to |
|
509 | """Convert a repository-absolute path into a filesystem path relative to | |
510 | the current working directory.""" |
|
510 | the current working directory.""" | |
@@ -516,7 +516,7 b' def relpath(context, mapping, args):' | |||||
516 | path = evalstring(context, mapping, args[0]) |
|
516 | path = evalstring(context, mapping, args[0]) | |
517 | return repo.pathto(path) |
|
517 | return repo.pathto(path) | |
518 |
|
518 | |||
519 | @templatefunc('revset(query[, formatargs...])') |
|
519 | @templatefunc('revset(query[, formatargs...])', requires={'repo', 'cache'}) | |
520 | def revset(context, mapping, args): |
|
520 | def revset(context, mapping, args): | |
521 | """Execute a revision set query. See |
|
521 | """Execute a revision set query. See | |
522 | :hg:`help revset`.""" |
|
522 | :hg:`help revset`.""" | |
@@ -577,7 +577,7 b' def separate(context, mapping, args):' | |||||
577 | yield sep |
|
577 | yield sep | |
578 | yield argstr |
|
578 | yield argstr | |
579 |
|
579 | |||
580 | @templatefunc('shortest(node, minlength=4)') |
|
580 | @templatefunc('shortest(node, minlength=4)', requires={'repo'}) | |
581 | def shortest(context, mapping, args): |
|
581 | def shortest(context, mapping, args): | |
582 | """Obtain the shortest representation of |
|
582 | """Obtain the shortest representation of | |
583 | a node.""" |
|
583 | a node.""" |
General Comments 0
You need to be logged in to leave comments.
Login now