revlog: overwrite revlog config through copy of the config object
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 10 Oct 2023 10:02:13 +0200
changeset 51030 177e7d6bf875
parent 51029 498afb627f78
child 51031 133f5a54ed9d
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.
mercurial/revlog.py
tests/test-revlog-raw.py
--- a/mercurial/revlog.py	Tue Oct 10 10:02:05 2023 +0200
+++ b/mercurial/revlog.py	Tue Oct 10 10:02:13 2023 +0200
@@ -241,8 +241,13 @@
 hexdigits = b'0123456789abcdefABCDEF'
 
 
+class _Config:
+    def copy(self):
+        return self.__class__(**self.__dict__)
+
+
 @attr.s()
-class FeatureConfig:
+class FeatureConfig(_Config):
     """Hold configuration values about the available revlog features"""
 
     # the default compression engine
@@ -265,9 +270,14 @@
     # can ellipsis commit be used
     enable_ellipsis = attr.ib(default=False)
 
+    def copy(self):
+        new = super().copy()
+        new.compression_engine_options = self.compression_engine_options.copy()
+        return new
+
 
 @attr.s()
-class DataConfig:
+class DataConfig(_Config):
     """Hold configuration value about how the revlog data are read"""
 
     # should we try to open the "pending" version of the revlog
@@ -297,7 +307,7 @@
 
 
 @attr.s()
-class DeltaConfig:
+class DeltaConfig(_Config):
     """Hold configuration value about how new delta are computed
 
     Some attributes are duplicated from DataConfig to help havign each object
@@ -3375,9 +3385,8 @@
 
         # lazydelta and lazydeltabase controls whether to reuse a cached delta,
         # if possible.
-        oldlazydelta = destrevlog._lazydelta
-        oldlazydeltabase = destrevlog._lazydeltabase
-        oldamd = destrevlog._deltabothparents
+        old_delta_config = destrevlog.delta_config
+        destrevlog.delta_config = destrevlog.delta_config.copy()
 
         try:
             if deltareuse == self.DELTAREUSEALWAYS:
@@ -3390,7 +3399,9 @@
                 destrevlog.delta_config.lazy_delta_base = False
                 destrevlog.delta_config.lazy_delta = False
 
-            delta_both_parents = forcedeltabothparents or oldamd
+            delta_both_parents = (
+                forcedeltabothparents or old_delta_config.delta_both_parents
+            )
             destrevlog.delta_config.delta_both_parents = delta_both_parents
 
             with self.reading():
@@ -3404,9 +3415,7 @@
                 )
 
         finally:
-            destrevlog.delta_config.lazy_delta = oldlazydelta
-            destrevlog.delta_config.lazy_delta_base = oldlazydeltabase
-            destrevlog.delta_config.delta_both_parents = oldamd
+            destrevlog.delta_config = old_delta_config
 
     def _clone(
         self,
--- a/tests/test-revlog-raw.py	Tue Oct 10 10:02:05 2023 +0200
+++ b/tests/test-revlog-raw.py	Tue Oct 10 10:02:13 2023 +0200
@@ -371,7 +371,10 @@
 
 
 def slicingtest(rlog):
-    oldmin = rlog._srmingapsize
+    old_delta_config = rlog.delta_config
+    old_data_config = rlog.data_config
+    rlog.delta_config = rlog.delta_config.copy()
+    rlog.data_config = rlog.data_config.copy()
     try:
         # the test revlog is small, we remove the floor under which we
         # slicing is diregarded.
@@ -388,8 +391,8 @@
                 print('  expected: %s' % expected)
                 print('  result:   %s' % result)
     finally:
-        rlog.data_config.sr_min_gap_size = oldmin
-        rlog.delta_config.sr_min_gap_size = oldmin
+        rlog.delta_config = old_delta_config
+        rlog.data_config = old_data_config
 
 
 def md5sum(s):