##// END OF EJS Templates
template: add revset() template function...
Durham Goode -
r20519:cda9d2b6 default
parent child Browse files
Show More
@@ -7,7 +7,7
7
7
8 from i18n import _
8 from i18n import _
9 import sys, os, re
9 import sys, os, re
10 import util, config, templatefilters, parser, error
10 import util, config, templatefilters, templatekw, parser, error
11 import types
11 import types
12 import minirst
12 import minirst
13
13
@@ -356,6 +356,32 def label(context, mapping, args):
356 # ignore args[0] (the label string) since this is supposed to be a a no-op
356 # ignore args[0] (the label string) since this is supposed to be a a no-op
357 yield _evalifliteral(args[1], context, mapping)
357 yield _evalifliteral(args[1], context, mapping)
358
358
359 def revset(context, mapping, args):
360 """usage: revset(query[, formatargs...])
361 """
362 if not len(args) > 0:
363 # i18n: "revset" is a keyword
364 raise error.ParseError(_("revset expects one or more arguments"))
365
366 raw = args[0][1]
367 ctx = mapping['ctx']
368 repo = ctx._repo
369
370 if len(args) > 1:
371 formatargs = list([a[0](context, mapping, a[1]) for a in args[1:]])
372 revs = repo.revs(raw, *formatargs)
373 revs = list([str(r) for r in revs])
374 else:
375 revsetcache = mapping['cache'].setdefault("revsetcache", {})
376 if raw in revsetcache:
377 revs = revsetcache[raw]
378 else:
379 revs = repo.revs(raw)
380 revs = list([str(r) for r in revs])
381 revsetcache[raw] = revs
382
383 return templatekw.showlist("revision", revs, **mapping)
384
359 def rstdoc(context, mapping, args):
385 def rstdoc(context, mapping, args):
360 if len(args) != 2:
386 if len(args) != 2:
361 # i18n: "rstdoc" is a keyword
387 # i18n: "rstdoc" is a keyword
@@ -454,6 +480,7 funcs = {
454 "join": join,
480 "join": join,
455 "label": label,
481 "label": label,
456 "pad": pad,
482 "pad": pad,
483 "revset": revset,
457 "rstdoc": rstdoc,
484 "rstdoc": rstdoc,
458 "shortest": shortest,
485 "shortest": shortest,
459 "strip": strip,
486 "strip": strip,
@@ -1657,3 +1657,22 Test ifcontains function
1657 $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
1657 $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
1658 1 did not add a
1658 1 did not add a
1659 0 added a
1659 0 added a
1660
1661 Test revset function
1662
1663 $ hg log --template '{rev} {ifcontains(rev, revset("."), "current rev", "not current rev")}\n'
1664 1 current rev
1665 0 not current rev
1666
1667 $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
1668 1 Parents: 0
1669 0 Parents:
1670
1671 $ hg log --template 'Rev: {rev}\n{revset("::%s", rev) % "Ancestor: {revision}\n"}\n'
1672 Rev: 1
1673 Ancestor: 0
1674 Ancestor: 1
1675
1676 Rev: 0
1677 Ancestor: 0
1678
@@ -34,7 +34,7 these may expose other cycles.
34 relative: discovery, error, hbisect, phases, util
34 relative: discovery, error, hbisect, phases, util
35 mercurial/templater.py mixed imports
35 mercurial/templater.py mixed imports
36 stdlib: parser
36 stdlib: parser
37 relative: config, error, templatefilters, util
37 relative: config, error, templatefilters, templatekw, util
38 mercurial/ui.py mixed imports
38 mercurial/ui.py mixed imports
39 stdlib: formatter
39 stdlib: formatter
40 relative: config, error, scmutil, util
40 relative: config, error, scmutil, util
General Comments 0
You need to be logged in to leave comments. Login now