@@ -362,6 +362,46 @@
if changed:
localmarks.write()
+def pushtoremote(ui, repo, remote, targets):
+ class InvalidBookmark(KeyError):
+ """Exception raised when specified bookmark doesn't exist on
+ the local or remote repository"""
+
+ def push(b, old, new):
+ r = remote.pushkey('bookmarks', b, old, new)
+ if not r:
+ ui.warn(_('updating bookmark %s failed!\n') % b)
+ return True
+ def export(b, scid, dcid):
+ ui.status(_("exporting bookmark %s\n") % b)
+ if dcid is None:
+ dcid = ''
+ return push(b, dcid, scid)
+ def delete(b, scid, dcid):
+ # treat as "deleted locally"
+ ui.status(_("deleting remote bookmark %s\n") % b)
+ return push(b, dcid, '')
+ def invalid(b, scid, dcid):
+ raise InvalidBookmark(b)
+
+ try:
+ if _execactions(compare(repo, repo._bookmarks,
+ remote.listkeys('bookmarks'),
+ srchex=hex, targets=targets),
+ {'addsrc': export,
+ 'adddst': delete,
+ 'advsrc': export,
+ 'advdst': export,
+ 'diverge': export,
+ 'differ': export,
+ 'invalid': invalid,
+ }):
+ return 1
+ except InvalidBookmark, inst:
+ ui.warn(_('bookmark %s does not exist on the local '
+ 'or remote repository!\n') % inst.args[0])
+ return 2
+
def diff(ui, dst, src):
ui.status(_("searching for changed bookmarks\n"))
@@ -4698,25 +4698,11 @@
result = not result
if opts.get('bookmark'):
- rb = other.listkeys('bookmarks')
- for b in opts['bookmark']:
- # explicit push overrides remote bookmark if any
- if b in repo._bookmarks:
- ui.status(_("exporting bookmark %s\n") % b)
- new = repo[b].hex()
- elif b in rb:
- ui.status(_("deleting remote bookmark %s\n") % b)
- new = '' # delete
- else:
- ui.warn(_('bookmark %s does not exist on the local '
- 'or remote repository!\n') % b)
- return 2
- old = rb.get(b, '')
- r = other.pushkey('bookmarks', b, old, new)
- if not r:
- ui.warn(_('updating bookmark %s failed!\n') % b)
- if not result:
- result = 2
+ bresult = bookmarks.pushtoremote(ui, repo, other, opts['bookmark'])
+ if bresult == 2:
+ return 2
+ if not result and bresult:
+ result = 2
return result