Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/dirstate_tree/dispatch.rs @ 47683:284a20269a97
dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
`dirstatemap.dirfoldmap` was recently changed to re-use a Rust iterator
that was added for the `hg debugdirstate` command.
That iterator was based on all nodes in the tree dirstate without an entry
only existing to hold child nodes, and therefore being directories.
However to optimize status further we may want to store additional nodes
for unknown or ignored files and directories. At that point the two users
of this iterator will want different things, so let?s make two iterators
instead.
See doc-comments in `dispatch.rs`.
Differential Revision: https://phab.mercurial-scm.org/D11099
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 16 Jul 2021 14:08:26 +0200 |
parents | 78f7f0d490ee |
children | e5fb14a07866 |
comparison
equal
deleted
inserted
replaced
47682:78f7f0d490ee | 47683:284a20269a97 |
---|---|
257 /// | 257 /// |
258 /// Because parse errors can happen during iteration, the iterated items | 258 /// Because parse errors can happen during iteration, the iterated items |
259 /// are `Result`s. | 259 /// are `Result`s. |
260 fn iter(&self) -> StateMapIter<'_>; | 260 fn iter(&self) -> StateMapIter<'_>; |
261 | 261 |
262 /// In the tree dirstate, return an iterator of "directory" (entry-less) | 262 /// Returns an iterator of tracked directories. |
263 /// nodes with the data stored for them. This is for `hg debugdirstate | 263 /// |
264 /// --dirs`. | 264 /// This is the paths for which `has_tracked_dir` would return true. |
265 /// | 265 /// Or, in other words, the union of ancestor paths of all paths that have |
266 /// In the flat dirstate, returns an empty iterator. | 266 /// an associated entry in a "tracked" state in this dirstate map. |
267 /// | 267 /// |
268 /// Because parse errors can happen during iteration, the iterated items | 268 /// Because parse errors can happen during iteration, the iterated items |
269 /// are `Result`s. | 269 /// are `Result`s. |
270 fn iter_directories( | 270 fn iter_tracked_dirs( |
271 &mut self, | |
272 ) -> Result< | |
273 Box< | |
274 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> | |
275 + Send | |
276 + '_, | |
277 >, | |
278 DirstateError, | |
279 >; | |
280 | |
281 /// Return an iterator of `(path, (state, mode, size, mtime))` for every | |
282 /// node stored in this dirstate map, for the purpose of the `hg | |
283 /// debugdirstate` command. | |
284 /// | |
285 /// For nodes that don’t have an entry, `state` is the ASCII space. | |
286 /// An `mtime` may still be present. It is used to optimize `status`. | |
287 /// | |
288 /// Because parse errors can happen during iteration, the iterated items | |
289 /// are `Result`s. | |
290 fn debug_iter( | |
271 &self, | 291 &self, |
272 ) -> Box< | 292 ) -> Box< |
273 dyn Iterator< | 293 dyn Iterator< |
274 Item = Result< | 294 Item = Result< |
275 (&HgPath, Option<Timestamp>), | 295 (&HgPath, (u8, i32, i32, i32)), |
276 DirstateV2ParseError, | 296 DirstateV2ParseError, |
277 >, | 297 >, |
278 > + Send | 298 > + Send |
279 + '_, | 299 + '_, |
280 >; | 300 >; |
474 | 494 |
475 fn iter(&self) -> StateMapIter<'_> { | 495 fn iter(&self) -> StateMapIter<'_> { |
476 Box::new((&**self).iter().map(|(key, value)| Ok((&**key, *value)))) | 496 Box::new((&**self).iter().map(|(key, value)| Ok((&**key, *value)))) |
477 } | 497 } |
478 | 498 |
479 fn iter_directories( | 499 fn iter_tracked_dirs( |
500 &mut self, | |
501 ) -> Result< | |
502 Box< | |
503 dyn Iterator<Item = Result<&HgPath, DirstateV2ParseError>> | |
504 + Send | |
505 + '_, | |
506 >, | |
507 DirstateError, | |
508 > { | |
509 self.set_all_dirs()?; | |
510 Ok(Box::new( | |
511 self.all_dirs | |
512 .as_ref() | |
513 .unwrap() | |
514 .iter() | |
515 .map(|path| Ok(&**path)), | |
516 )) | |
517 } | |
518 | |
519 fn debug_iter( | |
480 &self, | 520 &self, |
481 ) -> Box< | 521 ) -> Box< |
482 dyn Iterator< | 522 dyn Iterator< |
483 Item = Result< | 523 Item = Result< |
484 (&HgPath, Option<Timestamp>), | 524 (&HgPath, (u8, i32, i32, i32)), |
485 DirstateV2ParseError, | 525 DirstateV2ParseError, |
486 >, | 526 >, |
487 > + Send | 527 > + Send |
488 + '_, | 528 + '_, |
489 > { | 529 > { |
490 Box::new(std::iter::empty()) | 530 Box::new( |
531 (&**self) | |
532 .iter() | |
533 .map(|(path, entry)| Ok((&**path, entry.debug_tuple()))), | |
534 ) | |
491 } | 535 } |
492 } | 536 } |