Patchwork [5,of,9,(38,total)] push: move `force` argument into the push object

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 2, 2014, 1:33 a.m.
Message ID <e6a6efb51b7ad608d518.1391304781@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3430/
State Accepted
Commit 89f90457979eb0e114e63a64a40668b0c5701ee7
Headers show

Comments

Pierre-Yves David - Feb. 2, 2014, 1:33 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1391129965 28800
#      Thu Jan 30 16:59:25 2014 -0800
# Node ID e6a6efb51b7ad608d5189206226226701fa4bcd4
# Parent  e527306f01c128e8441266b26bd8db2f5a96e9b0
push: move `force` argument into the push object

One more step toward a more modular push function.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -19,27 +19,29 @@  class pushoperation(object):
 
     A new should be created at the begining of each push and discarded
     afterward.
     """
 
-    def __init__(self, repo, remote):
+    def __init__(self, repo, remote, force=False):
         # repo we push from
         self.repo = repo
         self.ui = repo.ui
         # repo we push to
         self.remote = remote
+        # force option provided
+        self.force = force
 
 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)
+    pushop = pushoperation(repo, remote, force)
     if pushop.remote.local():
         missing = (set(pushop.repo.requirements)
                    - pushop.remote.local().supported)
         if missing:
             msg = _("required features are not"
@@ -82,32 +84,32 @@  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(force, revs)
+        pushop.repo.checkpush(pushop.force, 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=force)
+            commoninc = fci(unfi, pushop.remote, force=pushop.force)
             common, inc, remoteheads = commoninc
             fco = discovery.findcommonoutgoing
             outgoing = fco(unfi, pushop.remote, onlyheads=revs,
-                           commoninc=commoninc, force=force)
+                           commoninc=commoninc, force=pushop.force)
 
 
             if not outgoing.missing:
                 # nothing to push
                 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
                 ret = None
             else:
                 # something to push
-                if not force:
+                if not pushop.force:
                     # if repo.obsstore == False --> no obsolete
                     # then, save the iteration
                     if unfi.obsstore:
                         # this message are here for 80 char limit reason
                         mso = _("push includes obsolete changeset: %s!")
@@ -152,11 +154,11 @@  def push(repo, remote, force=False, revs
                 if unbundle:
                     # local repo finds heads on server, finds out what
                     # revs it must push. once revs transferred, if server
                     # finds it has different heads (someone else won
                     # commit/push race), server aborts.
-                    if force:
+                    if pushop.force:
                         remoteheads = ['force']
                     # ssh: return remote's addchangegroup()
                     # http: return remote's addchangegroup() or 0 for error
                     ret = pushop.remote.unbundle(cg, remoteheads, 'push')
                 else: