[Updated] D9203: dirstate-tree: simplify the control flow in the Node.insert method
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Thu Oct 29 01:59:03 UTC 2020
Closed by commit rHGae2873e92250: dirstate-tree: simplify the control flow in the Node.insert method (authored by marmoute).
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/D9203?vs=23195&id=23334
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D9203/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D9203
AFFECTED FILES
rust/hg-core/src/dirstate/dirstate_tree/node.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/dirstate/dirstate_tree/node.rs b/rust/hg-core/src/dirstate/dirstate_tree/node.rs
--- a/rust/hg-core/src/dirstate/dirstate_tree/node.rs
+++ b/rust/hg-core/src/dirstate/dirstate_tree/node.rs
@@ -60,43 +60,46 @@
// Are we're modifying the current file ? Is the the end of the path ?
let is_current_file = tail.is_empty() && head.is_empty();
- if let NodeKind::File(file) = &mut self.kind {
- if is_current_file {
- let new = Self {
- kind: NodeKind::File(File {
- entry: new_entry,
- ..file.clone()
- }),
- };
- return InsertResult {
- did_insert: false,
- old_entry: Some(std::mem::replace(self, new)),
- };
- } else {
- match file.entry.state {
- // Only replace the current file with a directory if it's
- // marked as `Removed`
- EntryState::Removed => {
- self.kind = NodeKind::Directory(Directory {
- was_file: Some(Box::from(file.clone())),
- children: Default::default(),
- })
- }
- _ => {
- return Node::insert_in_file(
- file, new_entry, head, tail,
- )
- }
+ // Potentially Replace the current file with a directory if it's marked
+ // as `Removed`
+ if !is_current_file {
+ if let NodeKind::File(file) = &mut self.kind {
+ if file.entry.state == EntryState::Removed {
+ self.kind = NodeKind::Directory(Directory {
+ was_file: Some(Box::from(file.clone())),
+ children: Default::default(),
+ })
}
}
}
-
match &mut self.kind {
NodeKind::Directory(directory) => {
Node::insert_in_directory(directory, new_entry, head, tail)
}
- NodeKind::File(_) => {
- unreachable!("The file case has already been handled")
+ NodeKind::File(file) => {
+ if is_current_file {
+ let new = Self {
+ kind: NodeKind::File(File {
+ entry: new_entry,
+ ..file.clone()
+ }),
+ };
+ InsertResult {
+ did_insert: false,
+ old_entry: Some(std::mem::replace(self, new)),
+ }
+ } else {
+ match file.entry.state {
+ EntryState::Removed => {
+ unreachable!("Removed file turning into a directory was dealt with earlier")
+ }
+ _ => {
+ Node::insert_in_file(
+ file, new_entry, head, tail,
+ )
+ }
+ }
+ }
}
}
}
To: marmoute, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20201029/92280774/attachment-0002.html>
More information about the Mercurial-patches
mailing list