comparison hgext/bookmarks.py @ 11379:e1a145eebb6a

bookmarks: add support for push --bookmark to export bookmarks
author Matt Mackall <mpm@selenic.com>
date Thu, 17 Jun 2010 15:54:26 -0500
parents cb21fb1b55ba
children cac256790aa4
comparison
equal deleted inserted replaced
11378:cb21fb1b55ba 11379:e1a145eebb6a
407 repo._bookmarks[b] = repo[rb[b]].node() 407 repo._bookmarks[b] = repo[rb[b]].node()
408 write(repo) 408 write(repo)
409 409
410 return result 410 return result
411 411
412 def push(oldpush, ui, repo, dest=None, **opts):
413 dopush = True
414 if opts.get('bookmark'):
415 dopush = False
416 for b in opts['bookmark']:
417 if b in repo._bookmarks:
418 dopush = True
419 opts.setdefault('rev', []).append(b)
420
421 result = 0
422 if dopush:
423 result = oldpush(ui, repo, dest, **opts)
424
425 if opts.get('bookmark'):
426 # this is an unpleasant hack as push will do this internally
427 dest = ui.expandpath(dest or 'default-push', dest or 'default')
428 dest, branches = hg.parseurl(dest, opts.get('branch'))
429 other = hg.repository(hg.remoteui(repo, opts), dest)
430 rb = other.listkeys('bookmarks')
431 for b in opts['bookmark']:
432 # explicit push overrides remote bookmark if any
433 if b in repo._bookmarks:
434 ui.status(_("exporting bookmark %s\n") % b)
435 new = repo[b].hex()
436 else:
437 ui.status(_("deleting remote bookmark %s\n") % b)
438 new = '' # delete
439 old = rb.get(b, '')
440 r = other.pushkey('bookmarks', b, old, new)
441 if not r:
442 ui.warn(_('updating bookmark %s failed!\n') % b)
443 if not result:
444 result = 2
445
446 return result
447
412 def uisetup(ui): 448 def uisetup(ui):
413 extensions.wrapfunction(repair, "strip", strip) 449 extensions.wrapfunction(repair, "strip", strip)
414 if ui.configbool('bookmarks', 'track.current'): 450 if ui.configbool('bookmarks', 'track.current'):
415 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) 451 extensions.wrapcommand(commands.table, 'update', updatecurbookmark)
416 452
417 entry = extensions.wrapcommand(commands.table, 'pull', pull) 453 entry = extensions.wrapcommand(commands.table, 'pull', pull)
418 entry[1].append(('B', 'bookmark', [], 454 entry[1].append(('B', 'bookmark', [],
419 _("bookmark to import"))) 455 _("bookmark to import")))
456 entry = extensions.wrapcommand(commands.table, 'push', push)
457 entry[1].append(('B', 'bookmark', [],
458 _("bookmark to export")))
420 459
421 pushkey.register('bookmarks', pushbookmark, listbookmarks) 460 pushkey.register('bookmarks', pushbookmark, listbookmarks)
422 461
423 def updatecurbookmark(orig, ui, repo, *args, **opts): 462 def updatecurbookmark(orig, ui, repo, *args, **opts):
424 '''Set the current bookmark 463 '''Set the current bookmark