[Updated] D12530: rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node`
Alphare (Raphaël Gomès)
phabricator at mercurial-scm.org
Tue Apr 19 21:56:02 UTC 2022
Closed by commit rHG7276a6007573: rust-dirstatemap: use `get_node_mut` instead or `get_or_insert_node` (authored by Alphare).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12530?vs=33093&id=33284
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12530/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12530
AFFECTED FILES
rust/hg-core/src/dirstate_tree/dirstate_map.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -733,25 +733,45 @@
Ok(new)
}
- /// It is the responsibility of the caller to know that there was an entry
- /// there before. Does not handle the removal of copy source
+ /// Set a node as untracked in the dirstate.
+ ///
+ /// It is the responsibility of the caller to remove the copy source and/or
+ /// the entry itself if appropriate.
+ ///
+ /// # Panics
+ ///
+ /// Panics if the node does not exist.
fn set_untracked(
&mut self,
filename: &HgPath,
old_entry: DirstateEntry,
) -> Result<(), DirstateV2ParseError> {
- let node = self.get_or_insert_node(filename, |ancestor| {
- ancestor.tracked_descendants_count = ancestor
- .tracked_descendants_count
- .checked_sub(1)
- .expect("tracked_descendants_count should be >= 0");
- })?;
+ let node = DirstateMap::get_node_mut(
+ self.on_disk,
+ &mut self.unreachable_bytes,
+ &mut self.root,
+ filename,
+ |ancestor| {
+ ancestor.tracked_descendants_count = ancestor
+ .tracked_descendants_count
+ .checked_sub(1)
+ .expect("tracked_descendants_count should be >= 0");
+ },
+ )?
+ .expect("node should exist");
let mut new_entry = old_entry.clone();
new_entry.set_untracked();
node.data = NodeData::Entry(new_entry);
Ok(())
}
+ /// Set a node as clean in the dirstate.
+ ///
+ /// It is the responsibility of the caller to remove the copy source.
+ ///
+ /// # Panics
+ ///
+ /// Panics if the node does not exist.
fn set_clean(
&mut self,
filename: &HgPath,
@@ -760,22 +780,41 @@
size: u32,
mtime: TruncatedTimestamp,
) -> Result<(), DirstateError> {
- let node = self.get_or_insert_node(filename, |ancestor| {
- if !old_entry.tracked() {
- ancestor.tracked_descendants_count += 1;
- }
- })?;
+ let node = DirstateMap::get_node_mut(
+ self.on_disk,
+ &mut self.unreachable_bytes,
+ &mut self.root,
+ filename,
+ |ancestor| {
+ if !old_entry.tracked() {
+ ancestor.tracked_descendants_count += 1;
+ }
+ },
+ )?
+ .expect("node should exist");
let mut new_entry = old_entry.clone();
new_entry.set_clean(mode, size, mtime);
node.data = NodeData::Entry(new_entry);
Ok(())
}
+ /// Set a node as possibly dirty in the dirstate.
+ ///
+ /// # Panics
+ ///
+ /// Panics if the node does not exist.
fn set_possibly_dirty(
&mut self,
filename: &HgPath,
) -> Result<(), DirstateError> {
- let node = self.get_or_insert_node(filename, |_ancestor| {})?;
+ let node = DirstateMap::get_node_mut(
+ self.on_disk,
+ &mut self.unreachable_bytes,
+ &mut self.root,
+ filename,
+ |_ancestor| {},
+ )?
+ .expect("node should exist");
let entry = node.data.as_entry_mut().expect("entry should exist");
entry.set_possibly_dirty();
node.data = NodeData::Entry(*entry);
To: Alphare, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220419/27f0aa24/attachment-0002.html>
More information about the Mercurial-patches
mailing list