comparison rust/hg-core/src/dirstate_tree/dirstate_map.rs @ 47349:7138c863d0a1

dirstate-v2: Skip readdir in status based on directory mtime When calling `read_dir` during `status` and the directory is found to be eligible for caching (see code comments), write the directory’s mtime to the dirstate. The presence of a directory mtime in the dirstate is meaningful and indicates eligibility. When an eligible directory mtime is found in the dirstate and `stat()` shows that the mtime has not changed, `status` can skip calling `read_dir` again and instead rely on the names of child nodes in the dirstate tree. The `tempfile` crate is used to create a temporary file in order to use its modification time as "current time" with the same truncation as other files and directories would have in their own modification time. Differential Revision: https://phab.mercurial-scm.org/D10826
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 28 May 2021 11:48:59 +0200
parents a4de570e61fa
children 3b9914b28133
comparison
equal deleted inserted replaced
47348:a4de570e61fa 47349:7138c863d0a1
312 match self { 312 match self {
313 NodeRef::InMemory(_path, node) => { 313 NodeRef::InMemory(_path, node) => {
314 Ok(node.data.as_entry().map(|entry| entry.state)) 314 Ok(node.data.as_entry().map(|entry| entry.state))
315 } 315 }
316 NodeRef::OnDisk(node) => node.state(), 316 NodeRef::OnDisk(node) => node.state(),
317 }
318 }
319
320 pub(super) fn cached_directory_mtime(
321 &self,
322 ) -> Option<&on_disk::Timestamp> {
323 match self {
324 NodeRef::InMemory(_path, node) => match &node.data {
325 NodeData::CachedDirectory { mtime } => Some(mtime),
326 _ => None,
327 },
328 NodeRef::OnDisk(node) => node.cached_directory_mtime(),
317 } 329 }
318 } 330 }
319 331
320 pub(super) fn tracked_descendants_count(&self) -> u32 { 332 pub(super) fn tracked_descendants_count(&self) -> u32 {
321 match self { 333 match self {
477 return Ok(None); 489 return Ok(None);
478 } 490 }
479 } 491 }
480 } 492 }
481 493
482 fn get_or_insert_node<'tree, 'path>( 494 pub(super) fn get_or_insert_node<'tree, 'path>(
483 on_disk: &'on_disk [u8], 495 on_disk: &'on_disk [u8],
484 root: &'tree mut ChildNodes<'on_disk>, 496 root: &'tree mut ChildNodes<'on_disk>,
485 path: &'path HgPath, 497 path: &'path HgPath,
486 to_cow: impl Fn( 498 to_cow: impl Fn(
487 WithBasename<&'path HgPath>, 499 WithBasename<&'path HgPath>,