D11101: dirstate-v2: Reserve a few bytes of space for future extensions

SimonSapin phabricator at mercurial-scm.org
Fri Jul 16 15:19:14 UTC 2021


SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  See doc-comment

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11101

AFFECTED FILES
  mercurial/dirstateutils/docket.py
  rust/hg-core/src/dirstate_tree/on_disk.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/on_disk.rs b/rust/hg-core/src/dirstate_tree/on_disk.rs
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs
@@ -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))
diff --git a/mercurial/dirstateutils/docket.py b/mercurial/dirstateutils/docket.py
--- a/mercurial/dirstateutils/docket.py
+++ b/mercurial/dirstateutils/docket.py
@@ -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



To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list