[PATCH 4 of 9 (38 total)] push: move `remote` argument in the push object

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Sat Feb 1 19:33:00 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391129821 28800
#      Thu Jan 30 16:57:01 2014 -0800
# Node ID e527306f01c128e8441266b26bd8db2f5a96e9b0
# Parent  912430e402d6b3ddf6c2a85247a6127f2fe852a0
push: move `remote` argument in the push object

One more step toward a more modular push function.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -19,27 +19,30 @@ class pushoperation(object):
 
     A new should be created at the begining of each push and discarded
     afterward.
     """
 
-    def __init__(self, repo):
+    def __init__(self, repo, remote):
         # repo we push from
         self.repo = repo
         self.ui = repo.ui
+        # repo we push to
+        self.remote = remote
 
 def push(repo, remote, force=False, revs=None, newbranch=False):
     '''Push outgoing changesets (limited by revs) from a local
     repository to remote. Return an integer:
       - None means nothing to push
       - 0 means HTTP error
       - 1 means we pushed and remote head count is unchanged *or*
         we have outgoing changesets but refused to push
       - other values as described by addchangegroup()
     '''
-    pushop = pushoperation(repo)
-    if remote.local():
-        missing = set(pushop.repo.requirements) - remote.local().supported
+    pushop = pushoperation(repo, remote)
+    if pushop.remote.local():
+        missing = (set(pushop.repo.requirements)
+                   - pushop.remote.local().supported)
         if missing:
             msg = _("required features are not"
                     " supported in the destination:"
                     " %s") % (', '.join(sorted(missing)))
             raise util.Abort(msg)
@@ -50,11 +53,11 @@ def push(repo, remote, force=False, revs
     # repo (local filesystem, old ssh servers).
     #
     # unbundle assumes local user cannot lock remote repo (new ssh
     # servers, http servers).
 
-    if not remote.canpush():
+    if not pushop.remote.canpush():
         raise util.Abort(_("destination does not support push"))
     unfi = pushop.repo.unfiltered()
     def localphasemove(nodes, phase=phases.public):
         """move <nodes> to <phase> in the local source repo"""
         if locallock is not None:
@@ -81,20 +84,20 @@ def push(repo, remote, force=False, revs
         msg = 'cannot lock source repository: %s\n' % err
         pushop.ui.debug(msg)
     try:
         pushop.repo.checkpush(force, revs)
         lock = None
-        unbundle = remote.capable('unbundle')
+        unbundle = pushop.remote.capable('unbundle')
         if not unbundle:
-            lock = remote.lock()
+            lock = pushop.remote.lock()
         try:
             # discovery
             fci = discovery.findcommonincoming
-            commoninc = fci(unfi, remote, force=force)
+            commoninc = fci(unfi, pushop.remote, force=force)
             common, inc, remoteheads = commoninc
             fco = discovery.findcommonoutgoing
-            outgoing = fco(unfi, remote, onlyheads=revs,
+            outgoing = fco(unfi, pushop.remote, onlyheads=revs,
                            commoninc=commoninc, force=force)
 
 
             if not outgoing.missing:
                 # nothing to push
@@ -124,11 +127,11 @@ def push(repo, remote, force=False, revs
                             elif ctx.troubled():
                                 raise util.Abort(_(mst)
                                                  % (ctx.troubles()[0],
                                                     ctx))
                     newbm = pushop.ui.configlist('bookmarks', 'pushing')
-                    discovery.checkheads(unfi, remote, outgoing,
+                    discovery.checkheads(unfi, pushop.remote, outgoing,
                                          remoteheads, newbranch,
                                          bool(inc), newbm)
 
                 # TODO: get bundlecaps from remote
                 bundlecaps = None
@@ -153,15 +156,16 @@ def push(repo, remote, force=False, revs
                     # commit/push race), server aborts.
                     if force:
                         remoteheads = ['force']
                     # ssh: return remote's addchangegroup()
                     # http: return remote's addchangegroup() or 0 for error
-                    ret = remote.unbundle(cg, remoteheads, 'push')
+                    ret = pushop.remote.unbundle(cg, remoteheads, 'push')
                 else:
                     # we return an integer indicating remote head count
                     # change
-                    ret = remote.addchangegroup(cg, 'push', pushop.repo.url())
+                    ret = pushop.remote.addchangegroup(cg, 'push',
+                                                       pushop.repo.url())
 
             if ret:
                 # push succeed, synchronize target of the push
                 cheads = outgoing.missingheads
             elif revs is None:
@@ -190,11 +194,11 @@ def push(repo, remote, force=False, revs
                 revset = unfi.set('%ln and parents(roots(%ln))',
                                  outgoing.commonheads,
                                  outgoing.missing)
                 cheads.extend(c.node() for c in revset)
             # even when we don't push, exchanging phase data is useful
-            remotephases = remote.listkeys('phases')
+            remotephases = pushop.remote.listkeys('phases')
             if (pushop.ui.configbool('ui', '_usedassubrepo', False)
                 and remotephases    # server supports phases
                 and ret is None # nothing was pushed
                 and remotephases.get('publishing', False)):
                 # When:
@@ -226,23 +230,23 @@ def push(repo, remote, force=False, revs
                 # XXX Beware that revset break if droots is not strictly
                 # XXX root we may want to ensure it is but it is costly
                 outdated =  unfi.set('heads((%ln::%ln) and public())',
                                      droots, cheads)
                 for newremotehead in outdated:
-                    r = remote.pushkey('phases',
-                                       newremotehead.hex(),
-                                       str(phases.draft),
-                                       str(phases.public))
+                    r = pushop.remote.pushkey('phases',
+                                              newremotehead.hex(),
+                                              str(phases.draft),
+                                              str(phases.public))
                     if not r:
                         pushop.ui.warn(_('updating %s to public failed!\n')
                                        % newremotehead)
             pushop.ui.debug('try to push obsolete markers to remote\n')
-            obsolete.syncpush(pushop.repo, remote)
+            obsolete.syncpush(pushop.repo, pushop.remote)
         finally:
             if lock is not None:
                 lock.release()
     finally:
         if locallock is not None:
             locallock.release()
 
-    bookmarks.updateremote(pushop.ui, unfi, remote, revs)
+    bookmarks.updateremote(pushop.ui, unfi, pushop.remote, revs)
     return ret


More information about the Mercurial-devel mailing list