comparison mercurial/upgrade.py @ 32030:e47223576b8d

upgrade: introduce a 'formatvariant' class The 'deficiency' type has multiple specificities. We create a dedicated class to host them. More logic will be added incrementally in future changesets.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 10 Apr 2017 23:34:43 +0200
parents 9e35848fa007
children 11a2461fc9b1
comparison
equal deleted inserted replaced
32029:9e35848fa007 32030:e47223576b8d
118 worded in the future tense. 118 worded in the future tense.
119 119
120 upgrademessage 120 upgrademessage
121 Message intended for humans explaining what an upgrade addressing this 121 Message intended for humans explaining what an upgrade addressing this
122 issue will do. Should be worded in the future tense. 122 issue will do. Should be worded in the future tense.
123 123 """
124 fromdefault (``deficiency`` types only) 124 def __init__(self, name, type, description, upgrademessage):
125 Boolean indicating whether the current (deficient) state deviates
126 from Mercurial's default configuration.
127
128 fromconfig (``deficiency`` types only)
129 Boolean indicating whether the current (deficient) state deviates
130 from the current Mercurial configuration.
131 """
132 def __init__(self, name, type, description, upgrademessage, **kwargs):
133 self.name = name 125 self.name = name
134 self.type = type 126 self.type = type
135 self.description = description 127 self.description = description
136 self.upgrademessage = upgrademessage 128 self.upgrademessage = upgrademessage
137
138 for k, v in kwargs.items():
139 setattr(self, k, v)
140 129
141 def __eq__(self, other): 130 def __eq__(self, other):
142 if not isinstance(other, improvement): 131 if not isinstance(other, improvement):
143 # This is what python tell use to do 132 # This is what python tell use to do
144 return NotImplemented 133 return NotImplemented
148 return not self == other 137 return not self == other
149 138
150 def __hash__(self): 139 def __hash__(self):
151 return hash(self.name) 140 return hash(self.name)
152 141
142 class formatvariant(improvement):
143 """an improvement subclass dedicated to repository format
144
145 extra attributes:
146
147 fromdefault (``deficiency`` types only)
148 Boolean indicating whether the current (deficient) state deviates
149 from Mercurial's default configuration.
150
151 fromconfig (``deficiency`` types only)
152 Boolean indicating whether the current (deficient) state deviates
153 from the current Mercurial configuration.
154 """
155
156 def __init__(self, name, description, upgrademessage, fromdefault,
157 fromconfig):
158 super(formatvariant, self).__init__(name, deficiency, description,
159 upgrademessage)
160 self.fromdefault = fromdefault
161 self.fromconfig = fromconfig
162
153 def finddeficiencies(repo): 163 def finddeficiencies(repo):
154 """returns a list of deficiencies that the repo suffer from""" 164 """returns a list of deficiencies that the repo suffer from"""
155 newreporeqs = localrepo.newreporequirements(repo) 165 newreporeqs = localrepo.newreporequirements(repo)
156 166
157 deficiencies = [] 167 deficiencies = []
159 # We could detect lack of revlogv1 and store here, but they were added 169 # We could detect lack of revlogv1 and store here, but they were added
160 # in 0.9.2 and we don't support upgrading repos without these 170 # in 0.9.2 and we don't support upgrading repos without these
161 # requirements, so let's not bother. 171 # requirements, so let's not bother.
162 172
163 if 'fncache' not in repo.requirements: 173 if 'fncache' not in repo.requirements:
164 deficiencies.append(improvement( 174 deficiencies.append(formatvariant(
165 name='fncache', 175 name='fncache',
166 type=deficiency,
167 description=_('long and reserved filenames may not work correctly; ' 176 description=_('long and reserved filenames may not work correctly; '
168 'repository performance is sub-optimal'), 177 'repository performance is sub-optimal'),
169 upgrademessage=_('repository will be more resilient to storing ' 178 upgrademessage=_('repository will be more resilient to storing '
170 'certain paths and performance of certain ' 179 'certain paths and performance of certain '
171 'operations should be improved'), 180 'operations should be improved'),
172 fromdefault=True, 181 fromdefault=True,
173 fromconfig='fncache' in newreporeqs)) 182 fromconfig='fncache' in newreporeqs))
174 183
175 if 'dotencode' not in repo.requirements: 184 if 'dotencode' not in repo.requirements:
176 deficiencies.append(improvement( 185 deficiencies.append(formatvariant(
177 name='dotencode', 186 name='dotencode',
178 type=deficiency,
179 description=_('storage of filenames beginning with a period or ' 187 description=_('storage of filenames beginning with a period or '
180 'space may not work correctly'), 188 'space may not work correctly'),
181 upgrademessage=_('repository will be better able to store files ' 189 upgrademessage=_('repository will be better able to store files '
182 'beginning with a space or period'), 190 'beginning with a space or period'),
183 fromdefault=True, 191 fromdefault=True,
184 fromconfig='dotencode' in newreporeqs)) 192 fromconfig='dotencode' in newreporeqs))
185 193
186 if 'generaldelta' not in repo.requirements: 194 if 'generaldelta' not in repo.requirements:
187 deficiencies.append(improvement( 195 deficiencies.append(formatvariant(
188 name='generaldelta', 196 name='generaldelta',
189 type=deficiency,
190 description=_('deltas within internal storage are unable to ' 197 description=_('deltas within internal storage are unable to '
191 'choose optimal revisions; repository is larger and ' 198 'choose optimal revisions; repository is larger and '
192 'slower than it could be; interaction with other ' 199 'slower than it could be; interaction with other '
193 'repositories may require extra network and CPU ' 200 'repositories may require extra network and CPU '
194 'resources, making "hg push" and "hg pull" slower'), 201 'resources, making "hg push" and "hg pull" slower'),
206 # changelogs with deltas. 213 # changelogs with deltas.
207 cl = repo.changelog 214 cl = repo.changelog
208 for rev in cl: 215 for rev in cl:
209 chainbase = cl.chainbase(rev) 216 chainbase = cl.chainbase(rev)
210 if chainbase != rev: 217 if chainbase != rev:
211 deficiencies.append(improvement( 218 deficiencies.append(formatvariant(
212 name='removecldeltachain', 219 name='removecldeltachain',
213 type=deficiency,
214 description=_('changelog storage is using deltas instead of ' 220 description=_('changelog storage is using deltas instead of '
215 'raw entries; changelog reading and any ' 221 'raw entries; changelog reading and any '
216 'operation relying on changelog data are slower ' 222 'operation relying on changelog data are slower '
217 'than they could be'), 223 'than they could be'),
218 upgrademessage=_('changelog storage will be reformated to ' 224 upgrademessage=_('changelog storage will be reformated to '