rust/hg-core/src/dirstate_tree/dirstate_map.rs
branchstable
changeset 50222 ecd28d89c29e
parent 50221 1891086f6c7f
child 50243 6cce0afc1454
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Fri Feb 24 18:21:54 2023 +0100
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Tue Feb 28 15:49:53 2023 +0100
@@ -42,6 +42,7 @@
 pub enum DirstateMapWriteMode {
     Auto,
     ForceNewDataFile,
+    ForceAppend,
 }
 
 #[derive(Debug)]
@@ -69,6 +70,9 @@
     pub(super) old_data_size: usize,
 
     pub(super) dirstate_version: DirstateVersion,
+
+    /// Controlled by config option `devel.dirstate.v2.data_update_mode`
+    pub(super) write_mode: DirstateMapWriteMode,
 }
 
 /// Using a plain `HgPathBuf` of the full path from the repository root as a
@@ -457,6 +461,7 @@
             unreachable_bytes: 0,
             old_data_size: 0,
             dirstate_version: DirstateVersion::V1,
+            write_mode: DirstateMapWriteMode::Auto,
         }
     }
 
@@ -525,8 +530,15 @@
     /// append to the existing data file that contains `self.on_disk` (true),
     /// or create a new data file from scratch (false).
     pub(super) fn write_should_append(&self) -> bool {
-        let ratio = self.unreachable_bytes as f32 / self.on_disk.len() as f32;
-        ratio < ACCEPTABLE_UNREACHABLE_BYTES_RATIO
+        match self.write_mode {
+            DirstateMapWriteMode::ForceAppend => true,
+            DirstateMapWriteMode::ForceNewDataFile => false,
+            DirstateMapWriteMode::Auto => {
+                let ratio =
+                    self.unreachable_bytes as f32 / self.on_disk.len() as f32;
+                ratio < ACCEPTABLE_UNREACHABLE_BYTES_RATIO
+            }
+        }
     }
 
     fn get_node<'tree>(
@@ -923,6 +935,10 @@
             *unreachable_bytes += path.len() as u32
         }
     }
+
+    pub(crate) fn set_write_mode(&mut self, write_mode: DirstateMapWriteMode) {
+        self.write_mode = write_mode;
+    }
 }
 
 /// Like `Iterator::filter_map`, but over a fallible iterator of `Result`s.