[PATCH 6 of 9 (38 total)] push: move `revs` argument into the push object

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


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391130263 28800
#      Thu Jan 30 17:04:23 2014 -0800
# Node ID c3c073e07c5fa463eac93c8d3489d466d01fbe8c
# Parent  e6a6efb51b7ad608d5189206226226701fa4bcd4
push: move `revs` argument into 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,29 +19,31 @@ class pushoperation(object):
 
     A new should be created at the begining of each push and discarded
     afterward.
     """
 
-    def __init__(self, repo, remote, force=False):
+    def __init__(self, repo, remote, force=False, revs=None):
         # repo we push from
         self.repo = repo
         self.ui = repo.ui
         # repo we push to
         self.remote = remote
         # force option provided
         self.force = force
+        # revs to be pushed (None is "all")
+        self.revs = revs
 
 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, remote, force)
+    pushop = pushoperation(repo, remote, force, revs)
     if pushop.remote.local():
         missing = (set(pushop.repo.requirements)
                    - pushop.remote.local().supported)
         if missing:
             msg = _("required features are not"
@@ -84,22 +86,22 @@ def push(repo, remote, force=False, revs
         # We do not abort the push, but just disable the local phase
         # synchronisation.
         msg = 'cannot lock source repository: %s\n' % err
         pushop.ui.debug(msg)
     try:
-        pushop.repo.checkpush(pushop.force, revs)
+        pushop.repo.checkpush(pushop.force, pushop.revs)
         lock = None
         unbundle = pushop.remote.capable('unbundle')
         if not unbundle:
             lock = pushop.remote.lock()
         try:
             # discovery
             fci = discovery.findcommonincoming
             commoninc = fci(unfi, pushop.remote, force=pushop.force)
             common, inc, remoteheads = commoninc
             fco = discovery.findcommonoutgoing
-            outgoing = fco(unfi, pushop.remote, onlyheads=revs,
+            outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
                            commoninc=commoninc, force=pushop.force)
 
 
             if not outgoing.missing:
                 # nothing to push
@@ -136,11 +138,11 @@ def push(repo, remote, force=False, revs
                                          bool(inc), newbm)
 
                 # TODO: get bundlecaps from remote
                 bundlecaps = None
                 # create a changegroup from local
-                if revs is None and not (outgoing.excluded
+                if pushop.revs is None and not (outgoing.excluded
                                         or pushop.repo.changelog.filteredrevs):
                     # push everything,
                     # use the fast path, no race possible on push
                     bundler = changegroup.bundle10(pushop.repo, bundlecaps)
                     cg = pushop.repo._changegroupsubset(outgoing,
@@ -168,11 +170,11 @@ def push(repo, remote, force=False, revs
                                                        pushop.repo.url())
 
             if ret:
                 # push succeed, synchronize target of the push
                 cheads = outgoing.missingheads
-            elif revs is None:
+            elif pushop.revs is None:
                 # All out push fails. synchronize all common
                 cheads = outgoing.commonheads
             else:
                 # I want cheads = heads(::missingheads and ::commonheads)
                 # (missingheads is revs with secret changeset filtered out)
@@ -188,11 +190,11 @@ def push(repo, remote, force=False, revs
                 #
                 # We can pick:
                 # * missingheads part of common (::commonheads)
                 common = set(outgoing.common)
                 nm = pushop.repo.changelog.nodemap
-                cheads = [node for node in revs if nm[node] in common]
+                cheads = [node for node in pushop.revs if nm[node] in common]
                 # and
                 # * commonheads parents on missing
                 revset = unfi.set('%ln and parents(roots(%ln))',
                                  outgoing.commonheads,
                                  outgoing.missing)
@@ -248,7 +250,7 @@ def push(repo, remote, force=False, revs
                 lock.release()
     finally:
         if locallock is not None:
             locallock.release()
 
-    bookmarks.updateremote(pushop.ui, unfi, pushop.remote, revs)
+    bookmarks.updateremote(pushop.ui, unfi, pushop.remote, pushop.revs)
     return ret


More information about the Mercurial-devel mailing list