dirstate-v2: Reserve a few bytes of space for future extensions
authorSimon Sapin <simon.sapin@octobus.net>
Fri, 16 Jul 2021 16:19:31 +0200
changeset 47684 852262e2e7d9
parent 47683 284a20269a97
child 47685 265cdfaad372
dirstate-v2: Reserve a few bytes of space for future extensions See doc-comment Differential Revision: https://phab.mercurial-scm.org/D11101
mercurial/dirstateutils/docket.py
rust/hg-core/src/dirstate_tree/on_disk.rs
--- a/mercurial/dirstateutils/docket.py	Fri Jul 16 14:08:26 2021 +0200
+++ b/mercurial/dirstateutils/docket.py	Fri Jul 16 16:19:31 2021 +0200
@@ -16,7 +16,7 @@
 
 # Must match the constant of the same name in
 # `rust/hg-core/src/dirstate_tree/on_disk.rs`
-TREE_METADATA_SIZE = 40
+TREE_METADATA_SIZE = 44
 
 # * 12 bytes: format marker
 # * 32 bytes: node ID of the working directory's first parent
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs	Fri Jul 16 14:08:26 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs	Fri Jul 16 16:19:31 2021 +0200
@@ -49,13 +49,13 @@
 
 /// Must match the constant of the same name in
 /// `mercurial/dirstateutils/docket.py`
-const TREE_METADATA_SIZE: usize = 40;
+const TREE_METADATA_SIZE: usize = 44;
 
 /// Make sure that size-affecting changes are made knowingly
 #[allow(unused)]
 fn static_assert_size_of() {
-    let _ = std::mem::transmute::<DocketHeader, [u8; 121]>;
     let _ = std::mem::transmute::<TreeMetadata, [u8; TREE_METADATA_SIZE]>;
+    let _ = std::mem::transmute::<DocketHeader, [u8; TREE_METADATA_SIZE + 81]>;
     let _ = std::mem::transmute::<Node, [u8; 43]>;
 }
 
@@ -90,6 +90,12 @@
     /// How many bytes of this data file are not used anymore
     unreachable_bytes: Size,
 
+    /// Current version always sets these bytes to zero when creating or
+    /// updating a dirstate. Future versions could assign some bits to signal
+    /// for example "the version that last wrote/updated this dirstate did so
+    /// in such and such way that can be relied on by versions that know to."
+    unused: [u8; 4],
+
     /// If non-zero, a hash of ignore files that were used for some previous
     /// run of the `status` algorithm.
     ///
@@ -579,6 +585,7 @@
             .nodes_with_copy_source_count
             .into(),
         unreachable_bytes: dirstate_map.unreachable_bytes.into(),
+        unused: [0; 4],
         ignore_patterns_hash: dirstate_map.ignore_patterns_hash,
     };
     Ok((writer.out, meta.as_bytes().to_vec(), append))