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.
--- a/mercurial/upgrade.py Wed Apr 12 16:34:05 2017 +0200
+++ b/mercurial/upgrade.py Wed Apr 12 16:48:13 2017 +0200
@@ -139,6 +139,12 @@
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 @@
assert cls._requirement is not None
return cls._requirement in cls._newreporequirements(repo)
+@registerformatvariant
class fncache(requirementformatvariant):
name = 'fncache'
@@ -211,6 +218,7 @@
'certain paths and performance of certain '
'operations should be improved')
+@registerformatvariant
class dotencode(requirementformatvariant):
name = 'dotencode'
@@ -224,6 +232,7 @@
upgrademessage = _('repository will be better able to store files '
'beginning with a space or period')
+@registerformatvariant
class generaldelta(requirementformatvariant):
name = 'generaldelta'
@@ -245,6 +254,7 @@
'CPU resources, making "hg push" and "hg pull" '
'faster')
+@registerformatvariant
class removecldeltachain(formatvariant):
name = 'removecldeltachain'
@@ -279,14 +289,9 @@
# 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