# HG changeset patch # User Matt Mackall # Date 1276802783 18000 # Node ID cb21fb1b55ba744a70bc0f69dcefb3190ee57f63 # Parent 9916263d9a60ffcaac9180d358b99fa454b04df2 bookmarks: add support for pull --bookmark to import remote bookmarks diff -r 9916263d9a60 -r cb21fb1b55ba hgext/bookmarks.py --- a/hgext/bookmarks.py Thu Jun 17 15:51:27 2010 +0200 +++ b/hgext/bookmarks.py Thu Jun 17 14:26:23 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, pushkey +from mercurial import util, commands, repair, extensions, pushkey, hg import os def write(repo): @@ -383,10 +383,41 @@ finally: w.release() +def pull(oldpull, ui, repo, source="default", **opts): + # translate bookmark args to rev args for actual pull + if opts.get('bookmark'): + # this is an unpleasant hack as pull will do this internally + source, branches = hg.parseurl(ui.expandpath(source), + opts.get('branch')) + other = hg.repository(hg.remoteui(repo, opts), source) + rb = other.listkeys('bookmarks') + + for b in opts['bookmark']: + if b not in rb: + raise util.Abort(_('remote bookmark %s not found!') % b) + opts.setdefault('rev', []).append(b) + + result = oldpull(ui, repo, source, **opts) + + # update specified bookmarks + if opts.get('bookmark'): + for b in opts['bookmark']: + # explicit pull overrides local bookmark if any + ui.status(_("importing bookmark %s\n") % b) + repo._bookmarks[b] = repo[rb[b]].node() + write(repo) + + return result + def uisetup(ui): extensions.wrapfunction(repair, "strip", strip) if ui.configbool('bookmarks', 'track.current'): extensions.wrapcommand(commands.table, 'update', updatecurbookmark) + + entry = extensions.wrapcommand(commands.table, 'pull', pull) + entry[1].append(('B', 'bookmark', [], + _("bookmark to import"))) + pushkey.register('bookmarks', pushbookmark, listbookmarks) def updatecurbookmark(orig, ui, repo, *args, **opts):