Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 16822:da55d8a77390
revset: add pattern matching to 'bookmarks' revset expression
author | Simon King <simon@simonking.org.uk> |
---|---|
date | Wed, 30 May 2012 23:13:33 +0100 |
parents | 0946502fd3d5 |
children | b23bacb230c9 |
comparison
equal
deleted
inserted
replaced
16821:0946502fd3d5 | 16822:da55d8a77390 |
---|---|
303 return bisect(repo, subset, x) | 303 return bisect(repo, subset, x) |
304 | 304 |
305 def bookmark(repo, subset, x): | 305 def bookmark(repo, subset, x): |
306 """``bookmark([name])`` | 306 """``bookmark([name])`` |
307 The named bookmark or all bookmarks. | 307 The named bookmark or all bookmarks. |
308 | |
309 If `name` starts with `re:`, the remainder of the name is treated as | |
310 a regular expression. To match a bookmark that actually starts with `re:`, | |
311 use the prefix `literal:`. | |
308 """ | 312 """ |
309 # i18n: "bookmark" is a keyword | 313 # i18n: "bookmark" is a keyword |
310 args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) | 314 args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
311 if args: | 315 if args: |
312 bm = getstring(args[0], | 316 bm = getstring(args[0], |
313 # i18n: "bookmark" is a keyword | 317 # i18n: "bookmark" is a keyword |
314 _('the argument to bookmark must be a string')) | 318 _('the argument to bookmark must be a string')) |
315 bmrev = bookmarksmod.listbookmarks(repo).get(bm, None) | 319 kind, pattern, matcher = _stringmatcher(bm) |
316 if not bmrev: | 320 if kind == 'literal': |
317 raise util.Abort(_("bookmark '%s' does not exist") % bm) | 321 bmrev = bookmarksmod.listbookmarks(repo).get(bm, None) |
318 bmrev = repo[bmrev].rev() | 322 if not bmrev: |
319 return [r for r in subset if r == bmrev] | 323 raise util.Abort(_("bookmark '%s' does not exist") % bm) |
324 bmrev = repo[bmrev].rev() | |
325 return [r for r in subset if r == bmrev] | |
326 else: | |
327 matchrevs = set() | |
328 for name, bmrev in bookmarksmod.listbookmarks(repo).iteritems(): | |
329 if matcher(name): | |
330 matchrevs.add(bmrev) | |
331 if not matchrevs: | |
332 raise util.Abort(_("no bookmarks exist that match '%s'") | |
333 % pattern) | |
334 bmrevs = set() | |
335 for bmrev in matchrevs: | |
336 bmrevs.add(repo[bmrev].rev()) | |
337 return [r for r in subset if r in bmrevs] | |
338 | |
320 bms = set([repo[r].rev() | 339 bms = set([repo[r].rev() |
321 for r in bookmarksmod.listbookmarks(repo).values()]) | 340 for r in bookmarksmod.listbookmarks(repo).values()]) |
322 return [r for r in subset if r in bms] | 341 return [r for r in subset if r in bms] |
323 | 342 |
324 def branch(repo, subset, x): | 343 def branch(repo, subset, x): |