changeset 20026:84905561ad41

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()".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 08 Nov 2013 12:45:52 +0900
parents e8a11791abfc
children 4b06b2a445a1
files mercurial/bookmarks.py mercurial/commands.py
diffstat 2 files changed, 35 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Fri Nov 08 12:45:52 2013 +0900
+++ b/mercurial/bookmarks.py	Fri Nov 08 12:45:52 2013 +0900
@@ -364,6 +364,36 @@
             writer(msg)
         localmarks.write()
 
+def pushtoremote(ui, repo, remote, targets):
+    (addsrc, adddst, advsrc, advdst, diverge, differ, invalid
+     ) = compare(repo, repo._bookmarks, remote.listkeys('bookmarks'),
+                 srchex=hex, targets=targets)
+    if invalid:
+        b, scid, dcid = invalid[0]
+        ui.warn(_('bookmark %s does not exist on the local '
+                  'or remote repository!\n') % b)
+        return 2
+
+    def push(b, old, new):
+        r = remote.pushkey('bookmarks', b, old, new)
+        if not r:
+            ui.warn(_('updating bookmark %s failed!\n') % b)
+            return 1
+        return 0
+    failed = 0
+    for b, scid, dcid in sorted(addsrc + advsrc + advdst + diverge + differ):
+        ui.status(_("exporting bookmark %s\n") % b)
+        if dcid is None:
+            dcid = ''
+        failed += push(b, dcid, scid)
+    for b, scid, dcid in adddst:
+        # treat as "deleted locally"
+        ui.status(_("deleting remote bookmark %s\n") % b)
+        failed += push(b, dcid, '')
+
+    if failed:
+        return 1
+
 def diff(ui, dst, src):
     ui.status(_("searching for changed bookmarks\n"))
 
--- a/mercurial/commands.py	Fri Nov 08 12:45:52 2013 +0900
+++ b/mercurial/commands.py	Fri Nov 08 12:45:52 2013 +0900
@@ -4711,25 +4711,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