diff mercurial/exchange.py @ 22651:b901645a8784

push: gather all bookmark decisions together The discovery phases for bookmarks now use the list of explicitly pushed bookmarks to do addition, removal and overwriting. Tests are impacted because this reduces the amount of listkeys calls issued, removes some duplicated messages and improves the accuracy of some messages.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 27 Sep 2014 20:51:53 -0700
parents 36952c91e6c3
children d94f5bec9c8e
line wrap: on
line diff
--- a/mercurial/exchange.py	Fri Sep 26 18:33:11 2014 -0700
+++ b/mercurial/exchange.py	Sat Sep 27 20:51:53 2014 -0700
@@ -226,10 +226,6 @@
         if locallock is not None:
             locallock.release()
 
-    if pushop.bookmarks:
-        pushop.bkresult = bookmod.pushtoremote(repo.ui, repo, remote,
-                                               pushop.bookmarks)
-
     return pushop
 
 # list of steps to perform discovery before push
@@ -334,11 +330,40 @@
         ancestors = repo.changelog.ancestors(revnums, inclusive=True)
     remotebookmark = remote.listkeys('bookmarks')
 
+    explicit = set(pushop.bookmarks)
+
     comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
     addsrc, adddst, advsrc, advdst, diverge, differ, invalid = comp
     for b, scid, dcid in advsrc:
+        if b in explicit:
+            explicit.remove(b)
         if not ancestors or repo[scid].rev() in ancestors:
             pushop.outbookmarks.append((b, dcid, scid))
+    # search added bookmark
+    for b, scid, dcid in addsrc:
+        if b in explicit:
+            explicit.remove(b)
+            pushop.outbookmarks.append((b, '', scid))
+    # search for overwritten bookmark
+    for b, scid, dcid in advdst + diverge + differ:
+        if b in explicit:
+            explicit.remove(b)
+            pushop.outbookmarks.append((b, dcid, scid))
+    # search for bookmark to delete
+    for b, scid, dcid in adddst:
+        if b in explicit:
+            explicit.remove(b)
+            # treat as "deleted locally"
+            pushop.outbookmarks.append((b, dcid, ''))
+
+    if explicit:
+        explicit = sorted(explicit)
+        # we should probably list all of them
+        ui.warn(_('bookmark %s does not exist on the local '
+                  'or remote repository!\n') % explicit[0])
+        pushop.bkresult = 2
+
+    pushop.outbookmarks.sort()
 
 def _pushcheckoutgoing(pushop):
     outgoing = pushop.outgoing