[PATCH] push: move handling of explicitly pushed bookmarks into localrepo.push()

Kevin Bullock kbullock+mercurial at ringworld.org
Fri Dec 7 12:51:13 CST 2012


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1354905590 21600
# Node ID 47f4b9b1667a8af4df75fce5d2af8d12160f3f0b
# Parent  f3991bcf4f0ff43b43a1b1d0210925a629ef3b9c
push: move handling of explicitly pushed bookmarks into localrepo.push()

This puts the handling of bookmarks pushed with -B/--bookmark in the
same place as already-shared bookmarks.

As a side effect, the undocumented exit code 2 for push (indicating
that bookmarks explicitly listed couldn't be synched) is eliminated.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4766,33 +4766,9 @@ def push(ui, repo, dest=None, **opts):
                 return False
     finally:
         del repo._subtoppath
-    result = repo.push(other, opts.get('force'), revs=revs,
-                       newbranch=opts.get('new_branch'))
-
-    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
-
-    return result
+    return not repo.push(other, opts.get('force'), revs=revs,
+                         newbranch=opts.get('new_branch'),
+                         marks=opts.get('bookmark'))
 
 @command('recover', [])
 def recover(ui, repo):
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1866,7 +1866,7 @@ class localrepository(object):
         """
         pass
 
-    def push(self, remote, force=False, revs=None, newbranch=False):
+    def push(self, remote, force=False, revs=None, newbranch=False, marks=[]):
         '''Push outgoing changesets (limited by revs) from the current
         repository to remote. Return an integer:
           - None means nothing to push
@@ -2049,6 +2049,22 @@ class localrepository(object):
                         else:
                             self.ui.warn(_('updating bookmark %s'
                                            ' failed!\n') % k)
+        for b in marks:
+            # explicit push overrides remote bookmark if any
+            if b in unfi._bookmarks:
+                self.ui.status(_("exporting bookmark %s\n") % b)
+                new = self[b].hex()
+            elif b in rb:
+                self.ui.status(_("deleting remote bookmark %s\n") % b)
+                new = '' # delete
+            else:
+                self.ui.warn(_('bookmark %s does not exist on the local '
+                          'or remote repository!\n') % b)
+                break
+            old = rb.get(b, '')
+            r = remote.pushkey('bookmarks', b, old, new)
+            if not r:
+                self.ui.warn(_('updating bookmark %s failed!\n') % b)
 
         return ret
 
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -101,7 +101,7 @@ push/pull name that doesn't exist
   searching for changes
   no changes found
   bookmark badname does not exist on the local or remote repository!
-  [2]
+  [1]
   $ hg pull -B anotherbadname ../a
   pulling from ../a
   abort: remote bookmark anotherbadname not found!


More information about the Mercurial-devel mailing list