Mercurial > hg
changeset 16661:de4b42daf396
revset: add function for matching extra data (issue2767)
author | Henrik Stuart <hg@hstuart.dk> |
---|---|
date | Sat, 12 May 2012 10:20:57 +0200 |
parents | 2a71cc53f244 |
children | ea7bf1d49bce |
files | mercurial/revset.py tests/test-revset.t |
diffstat | 2 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Fri May 11 18:51:35 2012 +0200 +++ b/mercurial/revset.py Sat May 12 10:20:57 2012 +0200 @@ -466,6 +466,24 @@ pc = repo._phasecache return [r for r in subset if pc.phase(repo, r) == phases.draft] +def extra(repo, subset, x): + """``extra(label, [value])`` + Changesets with the given label in the extra metadata, with the given + optional value.""" + + l = getargs(x, 1, 2, _('extra takes at least 1 and at most 2 arguments')) + label = getstring(l[0], _('first argument to extra must be a string')) + value = None + + if len(l) > 1: + value = getstring(l[1], _('second argument to extra must be a string')) + + def _matchvalue(r): + extra = repo[r].extra() + return label in extra and (value is None or value == extra[label]) + + return [r for r in subset if _matchvalue(r)] + def filelog(repo, subset, x): """``filelog(pattern)`` Changesets connected to the specified filelog. @@ -1147,6 +1165,7 @@ "descendants": descendants, "_firstdescendants": _firstdescendants, "draft": draft, + "extra": extra, "file": hasfile, "filelog": filelog, "first": first,
--- a/tests/test-revset.t Fri May 11 18:51:35 2012 +0200 +++ b/tests/test-revset.t Sat May 12 10:20:57 2012 +0200 @@ -32,6 +32,13 @@ (branches are permanent and global, did you want a bookmark?) $ hg ci -Aqm2 -u Bob + $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n' + 2 + $ hg log -r "extra('branch')" --template '{rev}\n' + 0 + 1 + 2 + $ hg co 1 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg branch +a+b+c+