rust-dirstate: actually remember the identity
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 30 Sep 2024 17:43:51 +0200
changeset 52033 88aa21d654e5
parent 52032 09a54892b7ee
child 52034 b55f653a0b34
rust-dirstate: actually remember the identity This was an oversight that likely had no influence on anything since we have only been writing the dirstate for status. We will start writing the dirstate for more operations now, so we'll need this fixed.
rust/hg-core/src/dirstate_tree/dirstate_map.rs
rust/hg-core/src/dirstate_tree/on_disk.rs
rust/hg-core/src/dirstate_tree/owning.rs
rust/hg-core/src/repo.rs
rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Wed Aug 21 09:48:14 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon Sep 30 17:43:51 2024 +0200
@@ -495,6 +495,8 @@
         identity: Option<u64>,
     ) -> Result<(Self, Option<DirstateParents>), DirstateError> {
         let mut map = Self::empty(on_disk);
+        map.identity = identity;
+
         if map.on_disk.is_empty() {
             return Ok((map, None));
         }
@@ -534,7 +536,6 @@
             },
         )?;
         let parents = Some(*parents);
-        map.identity = identity;
 
         Ok((map, parents))
     }
@@ -1555,7 +1556,7 @@
     /// Test the very simple case a single tracked file
     #[test]
     fn test_tracked_descendants_simple() -> Result<(), DirstateError> {
-        let mut map = OwningDirstateMap::new_empty(vec![]);
+        let mut map = OwningDirstateMap::new_empty(vec![], None);
         assert_eq!(map.len(), 0);
 
         map.set_tracked(p(b"some/nested/path"))?;
@@ -1575,7 +1576,7 @@
     /// Test the simple case of all tracked, but multiple files
     #[test]
     fn test_tracked_descendants_multiple() -> Result<(), DirstateError> {
-        let mut map = OwningDirstateMap::new_empty(vec![]);
+        let mut map = OwningDirstateMap::new_empty(vec![], None);
 
         map.set_tracked(p(b"some/nested/path"))?;
         map.set_tracked(p(b"some/nested/file"))?;
@@ -1637,7 +1638,7 @@
     /// Check with a mix of tracked and non-tracked items
     #[test]
     fn test_tracked_descendants_different() -> Result<(), DirstateError> {
-        let mut map = OwningDirstateMap::new_empty(vec![]);
+        let mut map = OwningDirstateMap::new_empty(vec![], None);
 
         // A file that was just added
         map.set_tracked(p(b"some/nested/path"))?;
@@ -1734,7 +1735,7 @@
     /// Check that copies counter is correctly updated
     #[test]
     fn test_copy_source() -> Result<(), DirstateError> {
-        let mut map = OwningDirstateMap::new_empty(vec![]);
+        let mut map = OwningDirstateMap::new_empty(vec![], None);
 
         // Clean file
         map.reset_state(p(b"files/clean"), true, true, false, false, None)?;
@@ -1791,7 +1792,7 @@
     #[test]
     fn test_on_disk() -> Result<(), DirstateError> {
         // First let's create some data to put "on disk"
-        let mut map = OwningDirstateMap::new_empty(vec![]);
+        let mut map = OwningDirstateMap::new_empty(vec![], None);
 
         // A file that was just added
         map.set_tracked(p(b"some/nested/added"))?;
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs	Wed Aug 21 09:48:14 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs	Mon Sep 30 17:43:51 2024 +0200
@@ -292,6 +292,8 @@
 ) -> Result<DirstateMap<'on_disk>, DirstateV2ParseError> {
     if on_disk.is_empty() {
         let mut map = DirstateMap::empty(on_disk);
+        map.identity = identity;
+        map.old_uuid = Some(uuid);
         map.dirstate_version = DirstateVersion::V2;
         return Ok(map);
     }
--- a/rust/hg-core/src/dirstate_tree/owning.rs	Wed Aug 21 09:48:14 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/owning.rs	Mon Sep 30 17:43:51 2024 +0200
@@ -15,13 +15,17 @@
 );
 
 impl OwningDirstateMap {
-    pub fn new_empty<OnDisk>(on_disk: OnDisk) -> Self
+    pub fn new_empty<OnDisk>(on_disk: OnDisk, identity: Option<u64>) -> Self
     where
         OnDisk: Deref<Target = [u8]> + Send + 'static,
     {
         let on_disk = Box::new(on_disk);
 
-        OwningDirstateMap::new(on_disk, |bytes| DirstateMap::empty(bytes))
+        OwningDirstateMap::new(on_disk, |bytes| {
+            let mut empty = DirstateMap::empty(bytes);
+            empty.identity = identity;
+            empty
+        })
     }
 
     pub fn new_v1<OnDisk>(
--- a/rust/hg-core/src/repo.rs	Wed Aug 21 09:48:14 2024 +0200
+++ b/rust/hg-core/src/repo.rs	Mon Sep 30 17:43:51 2024 +0200
@@ -342,7 +342,6 @@
         let identity = self.dirstate_identity()?;
         let dirstate = self.dirstate_file_contents()?;
         if dirstate.is_empty() {
-            self.dirstate_parents.set(DirstateParents::NULL);
             Ok((identity, None, 0))
         } else {
             let docket_res =
@@ -427,7 +426,7 @@
         let dirstate_file_contents = self.dirstate_file_contents()?;
         if dirstate_file_contents.is_empty() {
             self.dirstate_parents.set(DirstateParents::NULL);
-            Ok(OwningDirstateMap::new_empty(Vec::new()))
+            Ok(OwningDirstateMap::new_empty(Vec::new(), identity))
         } else {
             let (map, parents) =
                 OwningDirstateMap::new_v1(dirstate_file_contents, identity)?;
@@ -443,8 +442,7 @@
         let dirstate_file_contents = self.dirstate_file_contents()?;
         let identity = self.dirstate_identity()?;
         if dirstate_file_contents.is_empty() {
-            self.dirstate_parents.set(DirstateParents::NULL);
-            return Ok(OwningDirstateMap::new_empty(Vec::new()));
+            return Ok(OwningDirstateMap::new_empty(Vec::new(), identity));
         }
         let docket = crate::dirstate_tree::on_disk::read_docket(
             &dirstate_file_contents,
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Wed Aug 21 09:48:14 2024 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Mon Sep 30 17:43:51 2024 +0200
@@ -88,7 +88,7 @@
     /// Returns an empty DirstateMap. Only used for a new dirstate.
     @staticmethod
     def new_empty() -> PyResult<PyObject> {
-        let map = OwningDirstateMap::new_empty(vec![]);
+        let map = OwningDirstateMap::new_empty(vec![], None);
         let map = Self::create_instance(py, map)?;
         Ok(map.into_object())
     }