Mercurial > hg-stable
comparison rust/hg-core/src/dirstate/dirstate_tree/tree.rs @ 45591:c35db907363d
rust: format with rustfmt
I suppose I ran the formatter on the tip but not on every patch.
Differential Revision: https://phab.mercurial-scm.org/D9093
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 28 Sep 2020 11:16:12 +0200 |
parents | b51167d70f5a |
children | 91fafafd5a68 |
comparison
equal
deleted
inserted
replaced
45590:768412472663 | 45591:c35db907363d |
---|---|
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 /// Low-level insertion method that returns the previous node (directories | 137 /// Low-level insertion method that returns the previous node (directories |
138 /// included). | 138 /// included). |
139 fn insert_node(&mut self, path: impl AsRef<HgPath>, kind: DirstateEntry) -> Option<Node> { | 139 fn insert_node( |
140 &mut self, | |
141 path: impl AsRef<HgPath>, | |
142 kind: DirstateEntry, | |
143 ) -> Option<Node> { | |
140 let InsertResult { | 144 let InsertResult { |
141 did_insert, | 145 did_insert, |
142 old_entry, | 146 old_entry, |
143 } = self.root.insert(path.as_ref().as_bytes(), kind); | 147 } = self.root.insert(path.as_ref().as_bytes(), kind); |
144 self.files_count += if did_insert { 1 } else { 0 }; | 148 self.files_count += if did_insert { 1 } else { 0 }; |
152 | 156 |
153 /// Returns a reference to the entry corresponding to `path` if it exists. | 157 /// Returns a reference to the entry corresponding to `path` if it exists. |
154 pub fn get(&self, path: impl AsRef<HgPath>) -> Option<&DirstateEntry> { | 158 pub fn get(&self, path: impl AsRef<HgPath>) -> Option<&DirstateEntry> { |
155 if let Some(node) = self.get_node(&path) { | 159 if let Some(node) = self.get_node(&path) { |
156 return match &node.kind { | 160 return match &node.kind { |
157 NodeKind::Directory(d) => d.was_file.as_ref().map(|f| &f.entry), | 161 NodeKind::Directory(d) => { |
162 d.was_file.as_ref().map(|f| &f.entry) | |
163 } | |
158 NodeKind::File(f) => Some(&f.entry), | 164 NodeKind::File(f) => Some(&f.entry), |
159 }; | 165 }; |
160 } | 166 } |
161 None | 167 None |
162 } | 168 } |
166 self.get(path).is_some() | 172 self.get(path).is_some() |
167 } | 173 } |
168 | 174 |
169 /// Returns a mutable reference to the entry corresponding to `path` if it | 175 /// Returns a mutable reference to the entry corresponding to `path` if it |
170 /// exists. | 176 /// exists. |
171 pub fn get_mut(&mut self, path: impl AsRef<HgPath>) -> Option<&mut DirstateEntry> { | 177 pub fn get_mut( |
178 &mut self, | |
179 path: impl AsRef<HgPath>, | |
180 ) -> Option<&mut DirstateEntry> { | |
172 if let Some(kind) = self.root.get_mut(path.as_ref().as_bytes()) { | 181 if let Some(kind) = self.root.get_mut(path.as_ref().as_bytes()) { |
173 return match kind { | 182 return match kind { |
174 NodeKind::Directory(d) => d.was_file.as_mut().map(|f| &mut f.entry), | 183 NodeKind::Directory(d) => { |
184 d.was_file.as_mut().map(|f| &mut f.entry) | |
185 } | |
175 NodeKind::File(f) => Some(&mut f.entry), | 186 NodeKind::File(f) => Some(&mut f.entry), |
176 }; | 187 }; |
177 } | 188 } |
178 None | 189 None |
179 } | 190 } |
190 pub fn fs_iter(&self, root_dir: PathBuf) -> FsIter { | 201 pub fn fs_iter(&self, root_dir: PathBuf) -> FsIter { |
191 FsIter::new(&self.root, root_dir) | 202 FsIter::new(&self.root, root_dir) |
192 } | 203 } |
193 | 204 |
194 /// Remove the entry at `path` and returns it, if it exists. | 205 /// Remove the entry at `path` and returns it, if it exists. |
195 pub fn remove(&mut self, path: impl AsRef<HgPath>) -> Option<DirstateEntry> { | 206 pub fn remove( |
196 let RemoveResult { old_entry, .. } = self.root.remove(path.as_ref().as_bytes()); | 207 &mut self, |
208 path: impl AsRef<HgPath>, | |
209 ) -> Option<DirstateEntry> { | |
210 let RemoveResult { old_entry, .. } = | |
211 self.root.remove(path.as_ref().as_bytes()); | |
197 self.files_count = self | 212 self.files_count = self |
198 .files_count | 213 .files_count |
199 .checked_sub(if old_entry.is_some() { 1 } else { 0 }) | 214 .checked_sub(if old_entry.is_some() { 1 } else { 0 }) |
200 .expect("removed too many files"); | 215 .expect("removed too many files"); |
201 old_entry | 216 old_entry |
342 mode: 10, | 357 mode: 10, |
343 mtime: 20, | 358 mtime: 20, |
344 size: 30, | 359 size: 30, |
345 }; | 360 }; |
346 assert_eq!(tree.insert_node(HgPath::new(b"foo"), entry), None); | 361 assert_eq!(tree.insert_node(HgPath::new(b"foo"), entry), None); |
347 assert_eq!(tree.insert_node(HgPath::new(b"foo/a"), removed_entry), None); | 362 assert_eq!( |
363 tree.insert_node(HgPath::new(b"foo/a"), removed_entry), | |
364 None | |
365 ); | |
348 // The insert should not turn `foo` into a directory as `foo` is not | 366 // The insert should not turn `foo` into a directory as `foo` is not |
349 // `Removed`. | 367 // `Removed`. |
350 match tree.get_node(HgPath::new(b"foo")).unwrap().kind { | 368 match tree.get_node(HgPath::new(b"foo")).unwrap().kind { |
351 NodeKind::Directory(_) => panic!("should be a file"), | 369 NodeKind::Directory(_) => panic!("should be a file"), |
352 NodeKind::File(_) => {} | 370 NodeKind::File(_) => {} |
514 let removed_entry = DirstateEntry { | 532 let removed_entry = DirstateEntry { |
515 state: EntryState::Removed, | 533 state: EntryState::Removed, |
516 ..entry | 534 ..entry |
517 }; | 535 }; |
518 assert_eq!(tree.insert(HgPath::new(b"a"), entry), None); | 536 assert_eq!(tree.insert(HgPath::new(b"a"), entry), None); |
519 assert_eq!(tree.insert_node(HgPath::new(b"a/b/x"), removed_entry), None); | 537 assert_eq!( |
538 tree.insert_node(HgPath::new(b"a/b/x"), removed_entry), | |
539 None | |
540 ); | |
520 assert_eq!(tree.files_count, 2); | 541 assert_eq!(tree.files_count, 2); |
521 dbg!(&tree); | 542 dbg!(&tree); |
522 assert_eq!(tree.remove(HgPath::new(b"a")), Some(entry)); | 543 assert_eq!(tree.remove(HgPath::new(b"a")), Some(entry)); |
523 assert_eq!(tree.files_count, 1); | 544 assert_eq!(tree.files_count, 1); |
524 dbg!(&tree); | 545 dbg!(&tree); |