Patchwork [4,of,5,modernize-streamclone] streamclone: refactor canperformstreamclone to accept a pullop

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 4, 2015, 8:11 p.m.
Message ID <ece85c11593b6bd8a318.1443989490@126.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/10787/
State Superseded
Commit 3515db5aae05abb273b837bc5f670e97de785cb2
Headers show

Comments

Gregory Szorc - Oct. 4, 2015, 8:11 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1443984642 25200
#      Sun Oct 04 11:50:42 2015 -0700
# Node ID ece85c11593b6bd8a318e40acd47804e40ceaf98
# Parent  1aa7ea121a54e5e2b6aaa3268452e7309fec7df5
streamclone: refactor canperformstreamclone to accept a pullop

This isn't strictly necessary. But a lot of pull functionality accepts a
pulloperation so extra state can be added easily. It also enables
extensions to perform more powerful things.

Patch

diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -16,24 +16,29 @@  from . import (
     store,
     util,
 )
 
-def canperformstreamclone(repo, remote, heads, streamrequested=None):
+def canperformstreamclone(pullop):
     """Whether it is possible to perform a streaming clone as part of pull.
 
     Returns a tuple of (supported, requirements). ``supported`` is True if
     streaming clone is supported and False otherwise. ``requirements`` is
     a set of repo requirements from the remote, or ``None`` if stream clone
     isn't supported.
     """
+    repo = pullop.repo
+    remote = pullop.remote
+
     # Streaming clone only works on empty repositories.
     if len(repo):
         return False, None
 
     # Streaming clone only works if all data is being requested.
-    if heads:
+    if pullop.heads:
         return False, None
 
+    streamrequested = pullop.streamclonerequested
+
     # If we don't have a preference, let the server decide for us. This
     # likely only comes into play in LANs.
     if streamrequested is None:
         # The server can advertise whether to prefer streaming clone.
@@ -74,18 +79,16 @@  def maybeperformlegacystreamclone(pullop
 
     A legacy stream clone will not be performed if a bundle2 stream clone is
     supported.
     """
-    repo = pullop.repo
-    remote = pullop.remote
-
-    r = canperformstreamclone(repo, remote, pullop.heads,
-                              streamrequested=pullop.streamclonerequested)
-    supported, requirements = r
+    supported, requirements = canperformstreamclone(pullop)
 
     if not supported:
         return
 
+    repo = pullop.repo
+    remote = pullop.remote
+
     # Save remote branchmap. We will use it later to speed up branchcache
     # creation.
     rbranchmap = None
     if remote.capable('branchmap'):