##// END OF EJS Templates
revset: add pattern matching to 'bookmarks' revset expression
Simon King -
r16822:da55d8a7 default
parent child Browse files
Show More
@@ -305,6 +305,10 b' def bisected(repo, subset, x):'
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'))
@@ -312,11 +316,26 b' def bookmark(repo, subset, x):'
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]
@@ -84,6 +84,20 b' bookmarks revset'
84 date: Thu Jan 01 00:00:00 1970 +0000
84 date: Thu Jan 01 00:00:00 1970 +0000
85 summary: 1
85 summary: 1
86
86
87 $ hg log -r 'bookmark("re:X")'
88 changeset: 0:f7b1eb17ad24
89 bookmark: X
90 user: test
91 date: Thu Jan 01 00:00:00 1970 +0000
92 summary: 0
93
94 changeset: 1:925d80f479bb
95 bookmark: X2
96 tag: tip
97 user: test
98 date: Thu Jan 01 00:00:00 1970 +0000
99 summary: 1
100
87 $ hg log -r 'bookmark(unknown)'
101 $ hg log -r 'bookmark(unknown)'
88 abort: bookmark 'unknown' does not exist
102 abort: bookmark 'unknown' does not exist
89 [255]
103 [255]
General Comments 0
You need to be logged in to leave comments. Login now