diff rust/hg-core/src/dirstate_tree/owning.rs @ 50245:dbe09fb038fc stable

rhg: remember the inode of .hg/dirstate This allows us to detect changes of `.hg/dirstate`, which is either the full dirstate (in dirstate-v1) or the docket file (v2) without relying on data inside the file. It only works on UNIX systems. This fixes a race condition for dirstate-v1 (as demonstrated by the test changes) and adds a confortable layer of sanity for dirstate-v2.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 01 Mar 2023 16:48:09 +0100
parents 6cce0afc1454
children a6b8b1ab9116
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/owning.rs	Tue Feb 28 17:58:15 2023 +0100
+++ b/rust/hg-core/src/dirstate_tree/owning.rs	Wed Mar 01 16:48:09 2023 +0100
@@ -31,6 +31,7 @@
 
     pub fn new_v1<OnDisk>(
         on_disk: OnDisk,
+        identity: Option<u64>,
     ) -> Result<(Self, DirstateParents), DirstateError>
     where
         OnDisk: Deref<Target = [u8]> + Send + 'static,
@@ -42,7 +43,7 @@
             OwningDirstateMapTryBuilder {
                 on_disk,
                 map_builder: |bytes| {
-                    DirstateMap::new_v1(&bytes).map(|(dmap, p)| {
+                    DirstateMap::new_v1(&bytes, identity).map(|(dmap, p)| {
                         parents = p.unwrap_or(DirstateParents::NULL);
                         dmap
                     })
@@ -58,6 +59,7 @@
         data_size: usize,
         metadata: &[u8],
         uuid: Vec<u8>,
+        identity: Option<u64>,
     ) -> Result<Self, DirstateError>
     where
         OnDisk: Deref<Target = [u8]> + Send + 'static,
@@ -67,7 +69,9 @@
         OwningDirstateMapTryBuilder {
             on_disk,
             map_builder: |bytes| {
-                DirstateMap::new_v2(&bytes, data_size, metadata, uuid)
+                DirstateMap::new_v2(
+                    &bytes, data_size, metadata, uuid, identity,
+                )
             },
         }
         .try_build()
@@ -92,6 +96,10 @@
         self.get_map().old_uuid.as_deref()
     }
 
+    pub fn old_identity(&self) -> Option<u64> {
+        self.get_map().identity
+    }
+
     pub fn old_data_size(&self) -> usize {
         self.get_map().old_data_size
     }