comparison rust/hg-core/src/dirstate_tree/status.rs @ 48218:15dedc0c5c35

status: Extract TruncatedTimestamp from fs::Metadata without SystemTime On Unix, the Rust standard library exposes `mtime` and `mtime_nsec` methods for `std::fs::Metada` whih is exactly what we need to construct a `TruncatedTimestamp`. This skips the computation in the conversion through `SystemTime` and `Result<Duration, Duration>`. Differential Revision: https://phab.mercurial-scm.org/D11654
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 13 Oct 2021 16:21:39 +0200
parents 320de901896a
children f45d35950db6
comparison
equal deleted inserted replaced
48217:e10f5dc7f5bf 48218:15dedc0c5c35
197 if let Some(cached_mtime) = cached_directory_mtime { 197 if let Some(cached_mtime) = cached_directory_mtime {
198 // The dirstate contains a cached mtime for this directory, set 198 // The dirstate contains a cached mtime for this directory, set
199 // by a previous run of the `status` algorithm which found this 199 // by a previous run of the `status` algorithm which found this
200 // directory eligible for `read_dir` caching. 200 // directory eligible for `read_dir` caching.
201 if let Some(meta) = directory_metadata { 201 if let Some(meta) = directory_metadata {
202 if let Ok(current_mtime) = meta.modified() { 202 if cached_mtime
203 let truncated = 203 .very_likely_equal_to_mtime_of(meta)
204 TruncatedTimestamp::from(current_mtime); 204 .unwrap_or(false)
205 if truncated.very_likely_equal(&cached_mtime) { 205 {
206 // The mtime of that directory has not changed 206 // The mtime of that directory has not changed
207 // since then, which means that the results of 207 // since then, which means that the results of
208 // `read_dir` should also be unchanged. 208 // `read_dir` should also be unchanged.
209 return true; 209 return true;
210 }
211 } 210 }
212 } 211 }
213 } 212 }
214 } 213 }
215 false 214 false
470 // unlikely enough in practice. 469 // unlikely enough in practice.
471 let truncated = TruncatedTimestamp::from(directory_mtime); 470 let truncated = TruncatedTimestamp::from(directory_mtime);
472 let is_up_to_date = if let Some(cached) = 471 let is_up_to_date = if let Some(cached) =
473 dirstate_node.cached_directory_mtime()? 472 dirstate_node.cached_directory_mtime()?
474 { 473 {
475 cached.very_likely_equal(&truncated) 474 cached.very_likely_equal(truncated)
476 } else { 475 } else {
477 false 476 false
478 }; 477 };
479 if !is_up_to_date { 478 if !is_up_to_date {
480 let hg_path = dirstate_node 479 let hg_path = dirstate_node