diff mercurial/exchange.py @ 34365:ff406f3e57b2

exchange: perform stream clone with clone bundle with --uncompressed Previously, `hg clone --uncompressed` would always clone from the origin server, even if a streaming clone bundle were available. With this change, we invoke the clone bundle mechanism before the stream clone mechanism, giving clone bundles the opportunity to handle --uncompressed (which is mapped to pullop.streamclonepreferred). The clone bundle filtering code now filters out entries that aren't stream clones when a stream clone is requested. If a stream clone clone bundle entry is present, it will be used. Otherwise, the client will fall back to a server-based streaming clone. .. feature:: `hg clone --uncompressed` uses clone bundles when possible Differential Revision: https://phab.mercurial-scm.org/D833
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 28 Sep 2017 15:24:54 +0100
parents 6c7aaf59b21e
children cd3f39716fd3
line wrap: on
line diff
--- a/mercurial/exchange.py	Thu Sep 28 12:17:30 2017 +0200
+++ b/mercurial/exchange.py	Thu Sep 28 15:24:54 2017 +0100
@@ -1239,10 +1239,10 @@
         wlock = pullop.repo.wlock()
         lock = pullop.repo.lock()
         pullop.trmanager = transactionmanager(repo, 'pull', remote.url())
-        streamclone.maybeperformlegacystreamclone(pullop)
         # This should ideally be in _pullbundle2(). However, it needs to run
         # before discovery to avoid extra work.
         _maybeapplyclonebundle(pullop)
+        streamclone.maybeperformlegacystreamclone(pullop)
         _pulldiscovery(pullop)
         if pullop.canusebundle2:
             _pullbundle2(pullop)
@@ -1864,7 +1864,9 @@
                        'falling back to regular clone\n'))
         return
 
-    entries = filterclonebundleentries(repo, entries)
+    entries = filterclonebundleentries(
+        repo, entries, streamclonerequested=pullop.streamclonerequested)
+
     if not entries:
         # There is a thundering herd concern here. However, if a server
         # operator doesn't advertise bundles appropriate for its clients,
@@ -1933,7 +1935,7 @@
 
     return m
 
-def filterclonebundleentries(repo, entries):
+def filterclonebundleentries(repo, entries, streamclonerequested=False):
     """Remove incompatible clone bundle manifest entries.
 
     Accepts a list of entries parsed with ``parseclonebundlesmanifest``
@@ -1948,7 +1950,15 @@
         spec = entry.get('BUNDLESPEC')
         if spec:
             try:
-                parsebundlespec(repo, spec, strict=True)
+                comp, version, params = parsebundlespec(repo, spec, strict=True)
+
+                # If a stream clone was requested, filter out non-streamclone
+                # entries.
+                if streamclonerequested and (comp != 'UN' or version != 's1'):
+                    repo.ui.debug('filtering %s because not a stream clone\n' %
+                                  entry['URL'])
+                    continue
+
             except error.InvalidBundleSpecification as e:
                 repo.ui.debug(str(e) + '\n')
                 continue
@@ -1956,6 +1966,12 @@
                 repo.ui.debug('filtering %s because unsupported bundle '
                               'spec: %s\n' % (entry['URL'], str(e)))
                 continue
+        # If we don't have a spec and requested a stream clone, we don't know
+        # what the entry is so don't attempt to apply it.
+        elif streamclonerequested:
+            repo.ui.debug('filtering %s because cannot determine if a stream '
+                          'clone bundle\n' % entry['URL'])
+            continue
 
         if 'REQUIRESNI' in entry and not sslutil.hassni:
             repo.ui.debug('filtering %s because SNI not supported\n' %