From patchwork Sun Sep 22 14:05:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [03, of, 12, V2] bookmarks: rewrite pushing local bookmarks in "commands.push()" by "compare()" From: Katsunori FUJIWARA X-Patchwork-Id: 2598 Message-Id: <474ac158844b0e554239.1379858729@feefifofum> To: mercurial-devel@selenic.com Date: Sun, 22 Sep 2013 23:05:29 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1379858556 -32400 # Sun Sep 22 23:02:36 2013 +0900 # Node ID 474ac158844b0e55423971e4b8345318796e6305 # Parent 6f60d541bdf5bd90778c0e8395b3504d09d985d6 bookmarks: rewrite pushing local bookmarks in "commands.push()" by "compare()" This patch adds "pushtoremote()", which uses "compare()" to compare bookmarks between the local and the remote repositories, to replace pushing local bookmarks in "commands.push()". diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py --- a/mercurial/bookmarks.py +++ b/mercurial/bookmarks.py @@ -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")) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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