Mercurial > hg
comparison hgext/bookmarks.py @ 11378:cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 17 Jun 2010 14:26:23 -0500 |
parents | e291c039d8ec |
children | e1a145eebb6a |
comparison
equal
deleted
inserted
replaced
11377:9916263d9a60 | 11378:cb21fb1b55ba |
---|---|
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, hex, short |
33 from mercurial import util, commands, repair, extensions, pushkey | 33 from mercurial import util, commands, repair, extensions, pushkey, hg |
34 import os | 34 import os |
35 | 35 |
36 def write(repo): | 36 def write(repo): |
37 '''Write bookmarks | 37 '''Write bookmarks |
38 | 38 |
381 write(repo) | 381 write(repo) |
382 return True | 382 return True |
383 finally: | 383 finally: |
384 w.release() | 384 w.release() |
385 | 385 |
386 def pull(oldpull, ui, repo, source="default", **opts): | |
387 # translate bookmark args to rev args for actual pull | |
388 if opts.get('bookmark'): | |
389 # this is an unpleasant hack as pull will do this internally | |
390 source, branches = hg.parseurl(ui.expandpath(source), | |
391 opts.get('branch')) | |
392 other = hg.repository(hg.remoteui(repo, opts), source) | |
393 rb = other.listkeys('bookmarks') | |
394 | |
395 for b in opts['bookmark']: | |
396 if b not in rb: | |
397 raise util.Abort(_('remote bookmark %s not found!') % b) | |
398 opts.setdefault('rev', []).append(b) | |
399 | |
400 result = oldpull(ui, repo, source, **opts) | |
401 | |
402 # update specified bookmarks | |
403 if opts.get('bookmark'): | |
404 for b in opts['bookmark']: | |
405 # explicit pull overrides local bookmark if any | |
406 ui.status(_("importing bookmark %s\n") % b) | |
407 repo._bookmarks[b] = repo[rb[b]].node() | |
408 write(repo) | |
409 | |
410 return result | |
411 | |
386 def uisetup(ui): | 412 def uisetup(ui): |
387 extensions.wrapfunction(repair, "strip", strip) | 413 extensions.wrapfunction(repair, "strip", strip) |
388 if ui.configbool('bookmarks', 'track.current'): | 414 if ui.configbool('bookmarks', 'track.current'): |
389 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) | 415 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) |
416 | |
417 entry = extensions.wrapcommand(commands.table, 'pull', pull) | |
418 entry[1].append(('B', 'bookmark', [], | |
419 _("bookmark to import"))) | |
420 | |
390 pushkey.register('bookmarks', pushbookmark, listbookmarks) | 421 pushkey.register('bookmarks', pushbookmark, listbookmarks) |
391 | 422 |
392 def updatecurbookmark(orig, ui, repo, *args, **opts): | 423 def updatecurbookmark(orig, ui, repo, *args, **opts): |
393 '''Set the current bookmark | 424 '''Set the current bookmark |
394 | 425 |