Patchwork [12,of,16] push: extract bundle pushing in a dedicated method

login
register
mail settings
Submitter Pierre-Yves David
Date April 17, 2013, 3:58 p.m.
Message ID <9b8ee7a0d0f9c3c047f0.1366214327@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/1401/
State Deferred, archived
Headers show

Comments

Pierre-Yves David - April 17, 2013, 3:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366210875 -7200
#      Wed Apr 17 17:01:15 2013 +0200
# Node ID 9b8ee7a0d0f9c3c047f0fb14ca90d2796dd5deb1
# Parent  74fe7f2c9abe580306ed39c0968fa87188a9bbaa
push: extract bundle pushing in a dedicated method

Another stop toward god function diet

Patch

diff --git a/mercurial/exchangeutil.py b/mercurial/exchangeutil.py
--- a/mercurial/exchangeutil.py
+++ b/mercurial/exchangeutil.py
@@ -61,35 +61,11 @@  class pushoperation(object):
                     # nothing to push
                     scmutil.nochangesfound(unfi.ui, unfi,
                                            self._outgoing.excluded)
                     ret = None
                 else:
-                    # create a changegroup from local
-                    if self.revs is None and not self._outgoing.excluded:
-                        # push everything,
-                        # use the fast path, no race possible on push
-                        cg = repo._changegroup(self._outgoing.missing, 'push')
-                    else:
-                        cg = repo.getlocalbundle('push', self._outgoing)
-
-                    # apply changegroup to remote
-                    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 self.force:
-                            remoteheads = ['force']
-                        else:
-                            remoteheads = self._remoteheads
-                        # ssh: return remote's addchangegroup()
-                        # http: return remote's addchangegroup() or 0 for error
-                        ret = remote.unbundle(cg, remoteheads, 'push')
-                    else:
-                        # we return an integer indicating remote head count
-                        # change
-                        ret = remote.addchangegroup(cg, 'push', repo.url())
+                    ret = self._pushbundle()
 
                 if ret:
                     # push succeed, synchronize target of the push
                     cheads = self._outgoing.missingheads
                 elif self.revs is None:
@@ -207,10 +183,38 @@  class pushoperation(object):
                                             ctx))
             discovery.checkheads(unfi, self.remote, outgoing,
                                  remoteheads, self.newbranch, bool(inc))
         return outgoing, remoteheads
 
+    def _pushbundle(self):
+        # create a changegroup from local
+        if self.revs is None and not self._outgoing.excluded:
+            # push everything,
+            # use the fast path, no race possible on push
+            cg = self.repo._changegroup(self._outgoing.missing, 'push')
+        else:
+            cg = self.repo.getlocalbundle('push', self._outgoing)
+
+        # apply changegroup to remote
+        if self.remote.capable('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 self.force:
+                remoteheads = ['force']
+            else:
+                remoteheads = self._remoteheads
+            # ssh: return remote's addchangegroup()
+            # http: return remote's addchangegroup() or 0 for error
+            return self.remote.unbundle(cg, remoteheads, 'push')
+        else:
+            # we return an integer indicating remote head count
+            # change
+            return self.remote.addchangegroup(cg, 'push', self.repo.url())
+
+
 
 
     def _pushobsolescence(self):
         """Send local obsolescence marker to remote"""
         self.repo.ui.debug('try to push obsolete markers to remote\n')