[PATCH 5 of 5 V2] upgrade: register all format variants in a list
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Apr 17 07:42:15 EDT 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1492008493 -7200
# Wed Apr 12 16:48:13 2017 +0200
# Node ID 784d00c3da15c66b936ee44f1f2d8610de546af7
# Parent 00332fda84a431fd0a45e6b912a4823da729be57
# EXP-Topic upgraderepo
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
# hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 784d00c3da15
upgrade: register all format variants in a list
Now that all known format variants exists outside of the function, we can gather
them in a lists. This build a single entry point other code can use (current
target: extensions).
The repository upgrade code is updated to simply use entries from this list.
As a side effect this will also allow extensions to register their own format
variants, to do this "properly" we should introduce a "registrar" for this
category of object. However I prefer to keep this series simple, and that will
be adventure for future time.
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -139,6 +139,12 @@ class improvement(object):
def __hash__(self):
return hash(self.name)
+allformatvariant = []
+
+def registerformatvariant(cls):
+ allformatvariant.append(cls)
+ return cls
+
class formatvariant(improvement):
"""an improvement subclass dedicated to repository format"""
type = deficiency
@@ -197,6 +203,7 @@ class requirementformatvariant(formatvar
assert cls._requirement is not None
return cls._requirement in cls._newreporequirements(repo)
+ at registerformatvariant
class fncache(requirementformatvariant):
name = 'fncache'
@@ -211,6 +218,7 @@ class fncache(requirementformatvariant):
'certain paths and performance of certain '
'operations should be improved')
+ at registerformatvariant
class dotencode(requirementformatvariant):
name = 'dotencode'
@@ -224,6 +232,7 @@ class dotencode(requirementformatvariant
upgrademessage = _('repository will be better able to store files '
'beginning with a space or period')
+ at registerformatvariant
class generaldelta(requirementformatvariant):
name='generaldelta'
@@ -245,6 +254,7 @@ class generaldelta(requirementformatvari
'CPU resources, making "hg push" and "hg pull" '
'faster')
+ at registerformatvariant
class removecldeltachain(formatvariant):
name='removecldeltachain'
@@ -279,14 +289,9 @@ def finddeficiencies(repo):
# in 0.9.2 and we don't support upgrading repos without these
# requirements, so let's not bother.
- if not fncache.fromrepo(repo):
- deficiencies.append(fncache)
- if not dotencode.fromrepo(repo):
- deficiencies.append(dotencode)
- if not generaldelta.fromrepo(repo):
- deficiencies.append(generaldelta)
- if not removecldeltachain.fromrepo(repo):
- deficiencies.append(removecldeltachain)
+ for fv in allformatvariant:
+ if not fv.fromrepo(repo):
+ deficiencies.append(fv)
return deficiencies
More information about the Mercurial-devel
mailing list