Mercurial > hg
comparison mercurial/upgrade.py @ 32032:189778a06743
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.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 12 Apr 2017 16:48:13 +0200 |
parents | 11a2461fc9b1 |
children | bd872f64a8ba |
comparison
equal
deleted
inserted
replaced
32031:11a2461fc9b1 | 32032:189778a06743 |
---|---|
137 return not self == other | 137 return not self == other |
138 | 138 |
139 def __hash__(self): | 139 def __hash__(self): |
140 return hash(self.name) | 140 return hash(self.name) |
141 | 141 |
142 allformatvariant = [] | |
143 | |
144 def registerformatvariant(cls): | |
145 allformatvariant.append(cls) | |
146 return cls | |
147 | |
142 class formatvariant(improvement): | 148 class formatvariant(improvement): |
143 """an improvement subclass dedicated to repository format""" | 149 """an improvement subclass dedicated to repository format""" |
144 type = deficiency | 150 type = deficiency |
145 ### The following attributes should be defined for each class: | 151 ### The following attributes should be defined for each class: |
146 | 152 |
195 @classmethod | 201 @classmethod |
196 def fromconfig(cls, repo): | 202 def fromconfig(cls, repo): |
197 assert cls._requirement is not None | 203 assert cls._requirement is not None |
198 return cls._requirement in cls._newreporequirements(repo) | 204 return cls._requirement in cls._newreporequirements(repo) |
199 | 205 |
206 @registerformatvariant | |
200 class fncache(requirementformatvariant): | 207 class fncache(requirementformatvariant): |
201 name = 'fncache' | 208 name = 'fncache' |
202 | 209 |
203 _requirement = 'fncache' | 210 _requirement = 'fncache' |
204 | 211 |
209 | 216 |
210 upgrademessage = _('repository will be more resilient to storing ' | 217 upgrademessage = _('repository will be more resilient to storing ' |
211 'certain paths and performance of certain ' | 218 'certain paths and performance of certain ' |
212 'operations should be improved') | 219 'operations should be improved') |
213 | 220 |
221 @registerformatvariant | |
214 class dotencode(requirementformatvariant): | 222 class dotencode(requirementformatvariant): |
215 name = 'dotencode' | 223 name = 'dotencode' |
216 | 224 |
217 _requirement = 'dotencode' | 225 _requirement = 'dotencode' |
218 | 226 |
222 'space may not work correctly') | 230 'space may not work correctly') |
223 | 231 |
224 upgrademessage = _('repository will be better able to store files ' | 232 upgrademessage = _('repository will be better able to store files ' |
225 'beginning with a space or period') | 233 'beginning with a space or period') |
226 | 234 |
235 @registerformatvariant | |
227 class generaldelta(requirementformatvariant): | 236 class generaldelta(requirementformatvariant): |
228 name = 'generaldelta' | 237 name = 'generaldelta' |
229 | 238 |
230 _requirement = 'generaldelta' | 239 _requirement = 'generaldelta' |
231 | 240 |
243 'interacting with other repositories using this ' | 252 'interacting with other repositories using this ' |
244 'storage model should require less network and ' | 253 'storage model should require less network and ' |
245 'CPU resources, making "hg push" and "hg pull" ' | 254 'CPU resources, making "hg push" and "hg pull" ' |
246 'faster') | 255 'faster') |
247 | 256 |
257 @registerformatvariant | |
248 class removecldeltachain(formatvariant): | 258 class removecldeltachain(formatvariant): |
249 name = 'removecldeltachain' | 259 name = 'removecldeltachain' |
250 | 260 |
251 default = True | 261 default = True |
252 | 262 |
277 | 287 |
278 # We could detect lack of revlogv1 and store here, but they were added | 288 # We could detect lack of revlogv1 and store here, but they were added |
279 # in 0.9.2 and we don't support upgrading repos without these | 289 # in 0.9.2 and we don't support upgrading repos without these |
280 # requirements, so let's not bother. | 290 # requirements, so let's not bother. |
281 | 291 |
282 if not fncache.fromrepo(repo): | 292 for fv in allformatvariant: |
283 deficiencies.append(fncache) | 293 if not fv.fromrepo(repo): |
284 if not dotencode.fromrepo(repo): | 294 deficiencies.append(fv) |
285 deficiencies.append(dotencode) | |
286 if not generaldelta.fromrepo(repo): | |
287 deficiencies.append(generaldelta) | |
288 if not removecldeltachain.fromrepo(repo): | |
289 deficiencies.append(removecldeltachain) | |
290 | 295 |
291 return deficiencies | 296 return deficiencies |
292 | 297 |
293 def findoptimizations(repo): | 298 def findoptimizations(repo): |
294 """Determine optimisation that could be used during upgrade""" | 299 """Determine optimisation that could be used during upgrade""" |