##// END OF EJS Templates
dirstate-tree: simplify the control flow in the Node.insert method...
marmoute -
r46365:ae2873e9 default
parent child Browse files
Show More
@@ -60,7 +60,23 b' impl Node {'
60 // Are we're modifying the current file ? Is the the end of the path ?
60 // Are we're modifying the current file ? Is the the end of the path ?
61 let is_current_file = tail.is_empty() && head.is_empty();
61 let is_current_file = tail.is_empty() && head.is_empty();
62
62
63 // Potentially Replace the current file with a directory if it's marked
64 // as `Removed`
65 if !is_current_file {
63 if let NodeKind::File(file) = &mut self.kind {
66 if let NodeKind::File(file) = &mut self.kind {
67 if file.entry.state == EntryState::Removed {
68 self.kind = NodeKind::Directory(Directory {
69 was_file: Some(Box::from(file.clone())),
70 children: Default::default(),
71 })
72 }
73 }
74 }
75 match &mut self.kind {
76 NodeKind::Directory(directory) => {
77 Node::insert_in_directory(directory, new_entry, head, tail)
78 }
79 NodeKind::File(file) => {
64 if is_current_file {
80 if is_current_file {
65 let new = Self {
81 let new = Self {
66 kind: NodeKind::File(File {
82 kind: NodeKind::File(File {
@@ -68,36 +84,23 b' impl Node {'
68 ..file.clone()
84 ..file.clone()
69 }),
85 }),
70 };
86 };
71 return InsertResult {
87 InsertResult {
72 did_insert: false,
88 did_insert: false,
73 old_entry: Some(std::mem::replace(self, new)),
89 old_entry: Some(std::mem::replace(self, new)),
74 };
90 }
75 } else {
91 } else {
76 match file.entry.state {
92 match file.entry.state {
77 // Only replace the current file with a directory if it's
78 // marked as `Removed`
79 EntryState::Removed => {
93 EntryState::Removed => {
80 self.kind = NodeKind::Directory(Directory {
94 unreachable!("Removed file turning into a directory was dealt with earlier")
81 was_file: Some(Box::from(file.clone())),
82 children: Default::default(),
83 })
84 }
95 }
85 _ => {
96 _ => {
86 return Node::insert_in_file(
97 Node::insert_in_file(
87 file, new_entry, head, tail,
98 file, new_entry, head, tail,
88 )
99 )
89 }
100 }
90 }
101 }
91 }
102 }
92 }
103 }
93
94 match &mut self.kind {
95 NodeKind::Directory(directory) => {
96 Node::insert_in_directory(directory, new_entry, head, tail)
97 }
98 NodeKind::File(_) => {
99 unreachable!("The file case has already been handled")
100 }
101 }
104 }
102 }
105 }
103
106
General Comments 0
You need to be logged in to leave comments. Login now