comparison mercurial/revset.py @ 16820:20f55613fb2a

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.
author Simon King <simon@simonking.org.uk>
date Wed, 30 May 2012 23:13:33 +0100
parents 5260a9e93113
children 0946502fd3d5
comparison
equal deleted inserted replaced
16819:5260a9e93113 16820:20f55613fb2a
1165 """ 1165 """
1166 # i18n: "tag" is a keyword 1166 # i18n: "tag" is a keyword
1167 args = getargs(x, 0, 1, _("tag takes one or no arguments")) 1167 args = getargs(x, 0, 1, _("tag takes one or no arguments"))
1168 cl = repo.changelog 1168 cl = repo.changelog
1169 if args: 1169 if args:
1170 tn = getstring(args[0], 1170 pattern = getstring(args[0],
1171 # i18n: "tag" is a keyword 1171 # i18n: "tag" is a keyword
1172 _('the argument to tag must be a string')) 1172 _('the argument to tag must be a string'))
1173 if not repo.tags().get(tn, None): 1173 kind, pattern, matcher = _stringmatcher(pattern)
1174 raise util.Abort(_("tag '%s' does not exist") % tn) 1174 if kind == 'literal':
1175 s = set([cl.rev(n) for t, n in repo.tagslist() if t == tn]) 1175 if not repo.tags().get(pattern, None):
1176 raise util.Abort(_("tag '%s' does not exist") % pattern)
1177 s = set([cl.rev(n) for t, n in repo.tagslist() if t == pattern])
1178 else:
1179 s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
1180 if not s:
1181 raise util.Abort(_("no tags exist that match '%s'") % pattern)
1176 else: 1182 else:
1177 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip']) 1183 s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
1178 return [r for r in subset if r in s] 1184 return [r for r in subset if r in s]
1179 1185
1180 def tagged(repo, subset, x): 1186 def tagged(repo, subset, x):