Patchwork [4,of,5,modernize-streamclone,V2] streamclone: teach canperformstreamclone to be bundle2 aware

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 5, 2015, 1:46 a.m.
Message ID <c90070c260be1174e33f.1444009596@126.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/10798/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 5, 2015, 1:46 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1444008919 25200
#      Sun Oct 04 18:35:19 2015 -0700
# Node ID c90070c260be1174e33feff8743ca4b4f99af308
# Parent  abab88d826b9b38360897f99679ad67eaa22e7c9
streamclone: teach canperformstreamclone to be bundle2 aware

We add an argument to canperformstreamclone() to return False if a
bundle2 stream clone is available. This will enable the legacy stream
clone step to no-op when a bundle2 stream clone is supported.

The commented code will be made active when bundle2 supports streaming
clone.

This patch does foreshadow the introduction of the "stream" bundle2
capability and its "v1" sub-capability. The bundle2 capability mirrors
the existing "stream" capability and is needed so clients know whether a
server explicitly supports streaming clones over bundle2 (servers up to
this point support bundle2 without streaming clone support).

The sub-capability will denote which data formats and variations are
supported. Currently, the value "v1" denotes the existing streaming
clone data format, which I intend to reuse inside a bundle2 part. My
intent is to eventually introduce alternate data formats that can be
produced and consumed more efficiently. Having a sub-capability means
we don't need to introduce a new top-level bundle2 capability when new
formats are introduced. This doesn't really have any implications
beyond making the capabilities namespace more organized.
Pierre-Yves David - Oct. 5, 2015, 2:18 a.m.
On 10/04/2015 06:46 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1444008919 25200
> #      Sun Oct 04 18:35:19 2015 -0700
> # Node ID c90070c260be1174e33feff8743ca4b4f99af308
> # Parent  abab88d826b9b38360897f99679ad67eaa22e7c9
> streamclone: teach canperformstreamclone to be bundle2 aware

patch 1-4 are pushed to the clowcopter, thanks!

Patch

diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -16,19 +16,38 @@  from . import (
     store,
     util,
 )
 
-def canperformstreamclone(pullop):
+def canperformstreamclone(pullop, bailifbundle2supported=False):
     """Whether it is possible to perform a streaming clone as part of pull.
 
+    ``bailifbundle2supported`` will cause the function to return False if
+    bundle2 stream clones are supported. It should only be called by the
+    legacy stream clone code path.
+
     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
 
+    bundle2supported = False
+    if pullop.canusebundle2:
+        if 'v1' in pullop.remotebundle2caps.get('stream', []):
+            bundle2supported = True
+        # else
+            # Server doesn't support bundle2 stream clone or doesn't support
+            # the versions we support. Fall back and possibly allow legacy.
+
+    # Ensures legacy code path uses available bundle2.
+    if bailifbundle2supported and bundle2supported:
+        return False, None
+    # Ensures bundle2 doesn't try to do a stream clone if it isn't supported.
+    #elif not bailifbundle2supported and not bundle2supported:
+    #    return False, None
+
     # Streaming clone only works on empty repositories.
     if len(repo):
         return False, None