Patchwork [2,of,7,(push,is,done;,12,more,to,go,for,pull)] push: move changeset push logic in its own function

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 11, 2014, 9:32 p.m.
Message ID <d90f282f42ed0f761e95.1392154372@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3583/
State Accepted
Commit f1b532a310e4d8dc1e29dbe50c4d8f1f06567163
Headers show

Comments

Pierre-Yves David - Feb. 11, 2014, 9:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1391143495 28800
#      Thu Jan 30 20:44:55 2014 -0800
# Node ID d90f282f42ed0f761e95cffb997088cf4974e2b8
# Parent  783539ede731dee892842d1d07d27e8be95f8fa3
push: move changeset push  logic in its own function

Now that every necessary information is held in the `pushoperation` object, we
can extract the logic pushing changeset  to it's own function.

This changeset is pure code movement only.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -139,47 +139,11 @@  def push(repo, remote, force=False, revs
                                                     ctx))
                     newbm = pushop.ui.configlist('bookmarks', 'pushing')
                     discovery.checkheads(unfi, pushop.remote, outgoing,
                                          remoteheads, pushop.newbranch,
                                          bool(inc), newbm)
-
-                # TODO: get bundlecaps from remote
-                bundlecaps = None
-                # create a changegroup from local
-                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,
-                                                        bundler,
-                                                        'push',
-                                                        fastpath=True)
-                else:
-                    cg = pushop.repo.getlocalbundle('push', outgoing,
-                                                    bundlecaps)
-
-                # 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 pushop.force:
-                        remoteheads = ['force']
-                    else:
-                        remoteheads = pushop.remoteheads
-                    # ssh: return remote's addchangegroup()
-                    # http: return remote's addchangegroup() or 0 for error
-                    pushop.ret = pushop.remote.unbundle(cg, remoteheads,
-                                                        'push')
-                else:
-                    # we return an integer indicating remote head count
-                    # change
-                    pushop.ret = pushop.remote.addchangegroup(cg, 'push',
-                                                              pushop.repo.url())
-
+                _pushchangeset(pushop)
             _pushsyncphase(pushop)
             _pushobsolete(pushop)
         finally:
             if lock is not None:
                 lock.release()
@@ -188,10 +152,49 @@  def push(repo, remote, force=False, revs
             locallock.release()
 
     _pushbookmark(pushop)
     return pushop.ret
 
+def _pushchangeset(pushop):
+    """Make the actual push of changeset bundle to remote repo"""
+    outgoing = pushop.outgoing
+    unbundle = pushop.remote.capable('unbundle')
+    # TODO: get bundlecaps from remote
+    bundlecaps = None
+    # create a changegroup from local
+    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,
+                                            bundler,
+                                            'push',
+                                            fastpath=True)
+    else:
+        cg = pushop.repo.getlocalbundle('push', outgoing, bundlecaps)
+
+    # 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 pushop.force:
+            remoteheads = ['force']
+        else:
+            remoteheads = pushop.remoteheads
+        # ssh: return remote's addchangegroup()
+        # http: return remote's addchangegroup() or 0 for error
+        pushop.ret = pushop.remote.unbundle(cg, remoteheads,
+                                            'push')
+    else:
+        # we return an integer indicating remote head count
+        # change
+        pushop.ret = pushop.remote.addchangegroup(cg, 'push',
+                                                              pushop.repo.url())
+
 def _pushsyncphase(pushop):
     """synchronise phase information locally and remotly"""
     unfi = pushop.repo.unfiltered()
     if pushop.ret:
         # push succeed, synchronize target of the push