diff mercurial/changegroup.py @ 27953:88609cfa3745 stable

changegroup: fix pulling to treemanifest repo from flat repo (issue5066) In c0f11347b107 (changegroup: don't support versions 01 and 02 with treemanifests, 2016-01-19), I stopped supporting use of cg1 and cg2 with treemanifest repos. What I had not considered was that it's perfectly safe to pull *to* a treemanifest repo using any changegroup version. As reported in issue5066, I therefore broke pull from old repos into a treemanifest repo. It was not covered by the test case, because that pulled from a local repo while enabling treemanifests, which enabled treemanifests on the source repo as well. After switching to pulling via HTTP, it breaks. Fix by splitting up changegroup.supportedversions() into supportedincomingversions() and supportedoutgoingversions().
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 27 Jan 2016 09:07:28 -0800
parents ca8d2b73155d
children 1c36cc8e7870
line wrap: on
line diff
--- a/mercurial/changegroup.py	Thu Jan 28 13:49:05 2016 -0800
+++ b/mercurial/changegroup.py	Wed Jan 27 09:07:28 2016 -0800
@@ -949,10 +949,25 @@
              '03': (cg3packer, cg3unpacker),
 }
 
-def supportedversions(repo):
+def allsupportedversions(ui):
     versions = set(_packermap.keys())
-    if ('treemanifest' in repo.requirements or
-        repo.ui.configbool('experimental', 'treemanifest')):
+    versions.discard('03')
+    if (ui.configbool('experimental', 'changegroup3') or
+        ui.configbool('experimental', 'treemanifest')):
+        versions.add('03')
+    return versions
+
+# Changegroup versions that can be applied to the repo
+def supportedincomingversions(repo):
+    versions = allsupportedversions(repo.ui)
+    if 'treemanifest' in repo.requirements:
+        versions.add('03')
+    return versions
+
+# Changegroup versions that can be created from the repo
+def supportedoutgoingversions(repo):
+    versions = allsupportedversions(repo.ui)
+    if 'treemanifest' in repo.requirements:
         # Versions 01 and 02 support only flat manifests and it's just too
         # expensive to convert between the flat manifest and tree manifest on
         # the fly. Since tree manifests are hashed differently, all of history
@@ -960,22 +975,21 @@
         # support versions 01 and 02.
         versions.discard('01')
         versions.discard('02')
-    elif not repo.ui.configbool('experimental', 'changegroup3'):
-        versions.discard('03')
+        versions.add('03')
     return versions
 
 def safeversion(repo):
     # Finds the smallest version that it's safe to assume clients of the repo
     # will support. For example, all hg versions that support generaldelta also
     # support changegroup 02.
-    versions = supportedversions(repo)
+    versions = supportedoutgoingversions(repo)
     if 'generaldelta' in repo.requirements:
         versions.discard('01')
     assert versions
     return min(versions)
 
 def getbundler(version, repo, bundlecaps=None):
-    assert version in supportedversions(repo)
+    assert version in supportedoutgoingversions(repo)
     return _packermap[version][0](repo, bundlecaps)
 
 def getunbundler(version, fh, alg):