Patchwork [5,of,5,V2] upgrade: register all format variants in a list

login
register
mail settings
Submitter Pierre-Yves David
Date April 17, 2017, 11:42 a.m.
Message ID <784d00c3da15c66b936e.1492429335@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20249/
State Accepted
Headers show

Comments

Pierre-Yves David - April 17, 2017, 11:42 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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)
 
+@registerformatvariant
 class fncache(requirementformatvariant):
     name = 'fncache'
 
@@ -211,6 +218,7 @@  class fncache(requirementformatvariant):
                        'certain paths and performance of certain '
                        'operations should be improved')
 
+@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')
 
+@registerformatvariant
 class generaldelta(requirementformatvariant):
     name='generaldelta'
 
@@ -245,6 +254,7 @@  class generaldelta(requirementformatvari
                        'CPU resources, making "hg push" and "hg pull" '
                        'faster')
 
+@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