Show More
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import sys, os, re |
|
10 | import util, config, templatefilters, parser, error | |
|
10 | import util, config, templatefilters, templatekw, parser, error | |
|
11 | 11 | import types |
|
12 | 12 | import minirst |
|
13 | 13 | |
@@ -356,6 +356,32 b' def label(context, mapping, args):' | |||
|
356 | 356 | # ignore args[0] (the label string) since this is supposed to be a a no-op |
|
357 | 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 | 385 | def rstdoc(context, mapping, args): |
|
360 | 386 | if len(args) != 2: |
|
361 | 387 | # i18n: "rstdoc" is a keyword |
@@ -454,6 +480,7 b' funcs = {' | |||
|
454 | 480 | "join": join, |
|
455 | 481 | "label": label, |
|
456 | 482 | "pad": pad, |
|
483 | "revset": revset, | |
|
457 | 484 | "rstdoc": rstdoc, |
|
458 | 485 | "shortest": shortest, |
|
459 | 486 | "strip": strip, |
@@ -1657,3 +1657,22 b' Test ifcontains function' | |||
|
1657 | 1657 | $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n' |
|
1658 | 1658 | 1 did not add a |
|
1659 | 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 b' these may expose other cycles.' | |||
|
34 | 34 | relative: discovery, error, hbisect, phases, util |
|
35 | 35 | mercurial/templater.py mixed imports |
|
36 | 36 | stdlib: parser |
|
37 | relative: config, error, templatefilters, util | |
|
37 | relative: config, error, templatefilters, templatekw, util | |
|
38 | 38 | mercurial/ui.py mixed imports |
|
39 | 39 | stdlib: formatter |
|
40 | 40 | relative: config, error, scmutil, util |
General Comments 0
You need to be logged in to leave comments.
Login now