Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 51027:177e7d6bf875
revlog: overwrite revlog config through copy of the config object
The new objects allow for this kind of blanket approach that make things
cleaner.
If we have more cases, it would probably deserve a context manager, but since we
only have two usage, I don't think it is worth it.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 10 Oct 2023 10:02:13 +0200 |
parents | 498afb627f78 |
children | 133f5a54ed9d |
comparison
equal
deleted
inserted
replaced
51026:498afb627f78 | 51027:177e7d6bf875 |
---|---|
239 ) | 239 ) |
240 | 240 |
241 hexdigits = b'0123456789abcdefABCDEF' | 241 hexdigits = b'0123456789abcdefABCDEF' |
242 | 242 |
243 | 243 |
244 class _Config: | |
245 def copy(self): | |
246 return self.__class__(**self.__dict__) | |
247 | |
248 | |
244 @attr.s() | 249 @attr.s() |
245 class FeatureConfig: | 250 class FeatureConfig(_Config): |
246 """Hold configuration values about the available revlog features""" | 251 """Hold configuration values about the available revlog features""" |
247 | 252 |
248 # the default compression engine | 253 # the default compression engine |
249 compression_engine = attr.ib(default=b'zlib') | 254 compression_engine = attr.ib(default=b'zlib') |
250 # compression engines options | 255 # compression engines options |
263 # meta-encoded files, so allow it to disable this behavior. | 268 # meta-encoded files, so allow it to disable this behavior. |
264 canonical_parent_order = attr.ib(default=False) | 269 canonical_parent_order = attr.ib(default=False) |
265 # can ellipsis commit be used | 270 # can ellipsis commit be used |
266 enable_ellipsis = attr.ib(default=False) | 271 enable_ellipsis = attr.ib(default=False) |
267 | 272 |
273 def copy(self): | |
274 new = super().copy() | |
275 new.compression_engine_options = self.compression_engine_options.copy() | |
276 return new | |
277 | |
268 | 278 |
269 @attr.s() | 279 @attr.s() |
270 class DataConfig: | 280 class DataConfig(_Config): |
271 """Hold configuration value about how the revlog data are read""" | 281 """Hold configuration value about how the revlog data are read""" |
272 | 282 |
273 # should we try to open the "pending" version of the revlog | 283 # should we try to open the "pending" version of the revlog |
274 try_pending = attr.ib(default=False) | 284 try_pending = attr.ib(default=False) |
275 # should we try to open the "splitted" version of the revlog | 285 # should we try to open the "splitted" version of the revlog |
295 # are delta encoded against arbitrary bases. | 305 # are delta encoded against arbitrary bases. |
296 generaldelta = attr.ib(default=False) | 306 generaldelta = attr.ib(default=False) |
297 | 307 |
298 | 308 |
299 @attr.s() | 309 @attr.s() |
300 class DeltaConfig: | 310 class DeltaConfig(_Config): |
301 """Hold configuration value about how new delta are computed | 311 """Hold configuration value about how new delta are computed |
302 | 312 |
303 Some attributes are duplicated from DataConfig to help havign each object | 313 Some attributes are duplicated from DataConfig to help havign each object |
304 self contained. | 314 self contained. |
305 """ | 315 """ |
3373 if getattr(destrevlog, 'filteredrevs', None): | 3383 if getattr(destrevlog, 'filteredrevs', None): |
3374 raise ValueError(_(b'destination revlog has filtered revisions')) | 3384 raise ValueError(_(b'destination revlog has filtered revisions')) |
3375 | 3385 |
3376 # lazydelta and lazydeltabase controls whether to reuse a cached delta, | 3386 # lazydelta and lazydeltabase controls whether to reuse a cached delta, |
3377 # if possible. | 3387 # if possible. |
3378 oldlazydelta = destrevlog._lazydelta | 3388 old_delta_config = destrevlog.delta_config |
3379 oldlazydeltabase = destrevlog._lazydeltabase | 3389 destrevlog.delta_config = destrevlog.delta_config.copy() |
3380 oldamd = destrevlog._deltabothparents | |
3381 | 3390 |
3382 try: | 3391 try: |
3383 if deltareuse == self.DELTAREUSEALWAYS: | 3392 if deltareuse == self.DELTAREUSEALWAYS: |
3384 destrevlog.delta_config.lazy_delta_base = True | 3393 destrevlog.delta_config.lazy_delta_base = True |
3385 destrevlog.delta_config.lazy_delta = True | 3394 destrevlog.delta_config.lazy_delta = True |
3388 destrevlog.delta_config.lazy_delta = True | 3397 destrevlog.delta_config.lazy_delta = True |
3389 elif deltareuse == self.DELTAREUSENEVER: | 3398 elif deltareuse == self.DELTAREUSENEVER: |
3390 destrevlog.delta_config.lazy_delta_base = False | 3399 destrevlog.delta_config.lazy_delta_base = False |
3391 destrevlog.delta_config.lazy_delta = False | 3400 destrevlog.delta_config.lazy_delta = False |
3392 | 3401 |
3393 delta_both_parents = forcedeltabothparents or oldamd | 3402 delta_both_parents = ( |
3403 forcedeltabothparents or old_delta_config.delta_both_parents | |
3404 ) | |
3394 destrevlog.delta_config.delta_both_parents = delta_both_parents | 3405 destrevlog.delta_config.delta_both_parents = delta_both_parents |
3395 | 3406 |
3396 with self.reading(): | 3407 with self.reading(): |
3397 self._clone( | 3408 self._clone( |
3398 tr, | 3409 tr, |
3402 forcedeltabothparents, | 3413 forcedeltabothparents, |
3403 sidedata_helpers, | 3414 sidedata_helpers, |
3404 ) | 3415 ) |
3405 | 3416 |
3406 finally: | 3417 finally: |
3407 destrevlog.delta_config.lazy_delta = oldlazydelta | 3418 destrevlog.delta_config = old_delta_config |
3408 destrevlog.delta_config.lazy_delta_base = oldlazydeltabase | |
3409 destrevlog.delta_config.delta_both_parents = oldamd | |
3410 | 3419 |
3411 def _clone( | 3420 def _clone( |
3412 self, | 3421 self, |
3413 tr, | 3422 tr, |
3414 destrevlog, | 3423 destrevlog, |