# HG changeset patch # User Simon King # Date 2012-05-30 22:13:33 # Node ID 20f55613fb2a3127a7bd7cc8789e0a155275eb1e # Parent 5260a9e9311390efbc279d62c06c06ddcdaef5a2 revset: add pattern matching to 'tag' revset expression If the string provided to the 'tag' predicate starts with 're:', the rest of the string will be treated as a regular expression and matched against all tags in the repository. There is a slight backwards-compatibility problem for people who actually have tags that start with 're:'. As a workaround, these tags can be matched using a 'literal:' prefix. If no tags match the pattern, an error is raised. This matches the behaviour of the previous exact-match code. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1167,12 +1167,18 @@ def tag(repo, subset, x): args = getargs(x, 0, 1, _("tag takes one or no arguments")) cl = repo.changelog if args: - tn = getstring(args[0], - # i18n: "tag" is a keyword - _('the argument to tag must be a string')) - if not repo.tags().get(tn, None): - raise util.Abort(_("tag '%s' does not exist") % tn) - s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn]) + pattern = getstring(args[0], + # i18n: "tag" is a keyword + _('the argument to tag must be a string')) + kind, pattern, matcher = _stringmatcher(pattern) + if kind == 'literal': + if not repo.tags().get(pattern, None): + raise util.Abort(_("tag '%s' does not exist") % pattern) + s = set([cl.rev(n) for t, n in repo.tagslist() if t == pattern]) + else: + s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)]) + if not s: + raise util.Abort(_("no tags exist that match '%s'") % pattern) else: s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) return [r for r in subset if r in s] diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -369,6 +369,22 @@ quoting needed 6 $ log 'tag(tip)' 9 + +we can use patterns when searching for tags + + $ log 'tag("1..*")' + abort: tag '1..*' does not exist + [255] + $ log 'tag("re:1..*")' + 6 + $ log 'tag("re:[0-9].[0-9]")' + 6 + $ log 'tag("literal:1.0")' + 6 + $ log 'tag("re:0..*")' + abort: no tags exist that match '0..*' + [255] + $ log 'tag(unknown)' abort: tag 'unknown' does not exist [255]