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