comparison hgext/bookmarks.py @ 12714:f5178fbcd197

bookmarks: add revset for referencing bookmarks
author Augie Fackler <durin42@gmail.com>
date Sun, 10 Oct 2010 12:40:25 -0500
parents 9d45f78c465b
children 175fb1b193f4
comparison
equal deleted inserted replaced
12713:bd37e7492478 12714:f5178fbcd197
27 using, and only update it. This is similar to git's approach to 27 using, and only update it. This is similar to git's approach to
28 branching. 28 branching.
29 ''' 29 '''
30 30
31 from mercurial.i18n import _ 31 from mercurial.i18n import _
32 from mercurial.node import nullid, nullrev, hex, short 32 from mercurial.node import nullid, nullrev, bin, hex, short
33 from mercurial import util, commands, repair, extensions, pushkey, hg, url 33 from mercurial import util, commands, repair, extensions, pushkey, hg, url
34 from mercurial import revset
34 import os 35 import os
35 36
36 def write(repo): 37 def write(repo):
37 '''Write bookmarks 38 '''Write bookmarks
38 39
534 if not rev and len(args) > 0: 535 if not rev and len(args) > 0:
535 rev = args[0] 536 rev = args[0]
536 setcurrent(repo, rev) 537 setcurrent(repo, rev)
537 return res 538 return res
538 539
540 def bmrevset(repo, subset, x):
541 args = revset.getargs(x, 0, 1, _('bookmark takes one or no arguments'))
542 if args:
543 bm = revset.getstring(args[0],
544 _('the argument to bookmark must be a string'))
545 bmrev = listbookmarks(repo).get(bm, None)
546 if bmrev:
547 bmrev = repo.changelog.rev(bin(bmrev))
548 return [r for r in subset if r == bmrev]
549 bms = set([repo.changelog.rev(bin(r)) for r in listbookmarks(repo).values()])
550 return [r for r in subset if r in bms]
551 revset.symbols['bookmark'] = bmrevset
552
553 def revsetdoc():
554 doc = help.loaddoc('revsets')()
555 doc += _('\nAdded by the bookmarks extension:\n\n'
556 '``bookmark([name])``\n'
557 ' The named bookmark or all bookmarks.\n')
558 return doc
559
539 cmdtable = { 560 cmdtable = {
540 "bookmarks": 561 "bookmarks":
541 (bookmark, 562 (bookmark,
542 [('f', 'force', False, _('force')), 563 [('f', 'force', False, _('force')),
543 ('r', 'rev', '', _('revision'), _('REV')), 564 ('r', 'rev', '', _('revision'), _('REV')),