rust-repo: add a method to set the current parents
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 30 Sep 2024 17:46:52 +0200
changeset 52036 d7bc6e482033
parent 52035 babfa9ddca0e
child 52037 0ea323b7e3b1
rust-repo: add a method to set the current parents This will be useful when we start writing an `hg update` fastpath.
rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs	Mon Sep 30 17:46:24 2024 +0200
+++ b/rust/hg-core/src/repo.rs	Mon Sep 30 17:46:52 2024 +0200
@@ -803,6 +803,24 @@
             .ok()
             .and_then(|c| c.node_from_rev(rev).copied())
     }
+
+    /// Change the current working directory parents cached in the repo.
+    ///
+    /// TODO
+    /// This does *not* do a lot of what it expected from a full `set_parents`:
+    ///     - parents should probably be stored in the dirstate
+    ///     - dirstate should have a "changing parents" context
+    ///     - dirstate should return copies if out of a merge context to be
+    ///       discarded within the repo context
+    /// See `setparents` in `context.py`.
+    pub fn manually_set_parents(
+        &self,
+        new_parents: DirstateParents,
+    ) -> Result<(), HgError> {
+        let mut parents = self.dirstate_parents.value.borrow_mut();
+        *parents = Some(new_parents);
+        Ok(())
+    }
 }
 
 /// Lazily-initialized component of `Repo` with interior mutability