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

login
register
mail settings
Submitter Pierre-Yves David
Date April 12, 2017, 11:12 p.m.
Message ID <4ec292a08314b87403b8.1492038736@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20141/
State Superseded
Headers show

Comments

Pierre-Yves David - April 12, 2017, 11:12 p.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 4ec292a08314b87403b879d2797b104235591cc5
# Parent  346b07413137d7f56196941212958df03e55b202
# 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 4ec292a08314
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
@@ -133,6 +133,11 @@  class improvement(object):
             return NotImplemented
         return self.name == other.name
 
+allformatvariant = []
+def registerformatvariant(cls):
+    allformatvariant.append(cls)
+    return cls
+
 class formatvariant(object):
     """an improvement subclass dedicated to repository format"""
     type = deficiency
@@ -188,6 +193,7 @@  class requirementformatvariant(formatvar
         assert cls._requirement is not None
         return cls._requirement in cls._newreporequirements(repo)
 
+@registerformatvariant
 class fncache(requirementformatvariant):
     name = 'fncache'
 
@@ -202,6 +208,7 @@  class fncache(requirementformatvariant):
                      'certain paths and performance of certain '
                      'operations should be improved')
 
+@registerformatvariant
 class dotencode(requirementformatvariant):
     name = 'dotencode'
 
@@ -215,6 +222,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'
 
@@ -236,6 +244,7 @@  class generaldelta(requirementformatvari
                      'CPU resources, making "hg push" and "hg pull" '
                      'faster')
 
+@registerformatvariant
 class removecldeltachain(formatvariant):
     name='removecldeltachain'
 
@@ -270,14 +279,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