# HG changeset patch # User Matt Mackall # Date 1276790511 18000 # Node ID 735f2d561747948fc6b1187201618e18b90e7e60 # Parent 4c8842ee97ff654d0e0dde216860168ccce62b78 bookmarks: add pushkey server-side support diff -r 4c8842ee97ff -r 735f2d561747 hgext/bookmarks.py --- a/hgext/bookmarks.py Wed Jun 16 16:05:47 2010 -0500 +++ b/hgext/bookmarks.py Thu Jun 17 11:01:51 2010 -0500 @@ -30,7 +30,7 @@ from mercurial.i18n import _ from mercurial.node import nullid, nullrev, hex, short -from mercurial import util, commands, repair, extensions +from mercurial import util, commands, repair, extensions, pushkey import os def write(repo): @@ -312,10 +312,34 @@ repo.__class__ = bookmark_repo +def listbookmarks(repo): + d = {} + for k, v in repo._bookmarks.iteritems(): + d[k] = hex(v) + return d + +def pushbookmark(repo, key, old, new): + w = repo.wlock() + try: + marks = repo._bookmarks + if hex(marks.get(key, '')) != old: + return False + if new == '': + del marks[key] + else: + if new not in repo: + return False + marks[key] = repo[new].node() + write(repo) + return True + finally: + w.release() + def uisetup(ui): extensions.wrapfunction(repair, "strip", strip) if ui.configbool('bookmarks', 'track.current'): extensions.wrapcommand(commands.table, 'update', updatecurbookmark) + pushkey.register('bookmarks', pushbookmark, listbookmarks) def updatecurbookmark(orig, ui, repo, *args, **opts): '''Set the current bookmark