[PATCH 3 of 5 STABLE] changegroup: introduce safeversion()

Martin von Zweigbergk martinvonz at google.com
Wed Jan 20 14:19:12 CST 2016


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1453246352 28800
#      Tue Jan 19 15:32:32 2016 -0800
# Branch stable
# Node ID 6b0741a1cc768d53b2c6e7f0d12c639960eacba6
# Parent  14760037c4e4be0a409fdea14fad06d9a8205a66
changegroup: introduce safeversion()

In a few places (at least repair.py and shelve.py), we want to find
the best changegroup version that we can assume users of the repo will
understand. For example, we choose version 01 by default, but if it's
a generaldelta repo, we expect clients to support version 02 anyway,
so we choose that for new bundles (for e.g. "hg strip"). Let's create
a helper for this functionality in changegroup, so we can reuse it
elsewhere later.

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -956,6 +956,15 @@
         versions.discard('03')
     return versions
 
+def safeversion(repo):
+    # Finds the smallest version that it's safe to assume clients of the repo
+    # will support.
+    versions = supportedversions(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)
     return _packermap[version][0](repo, bundlecaps)


More information about the Mercurial-devel mailing list