# HG changeset patch # User Raphaël Gomès # Date 1729091978 -7200 # Node ID 0529e1a468dd3746f74f3c98885d5919104c8871 # Parent ea0467ed76aac6922a822bb5b05d8eec086e3892 rust-dirstate: make the reliable timestamp comparison more usable from outside This is going to be used with pre-computed times unlike in status. diff -r ea0467ed76aa -r 0529e1a468dd rust/hg-core/src/dirstate/entry.rs --- a/rust/hg-core/src/dirstate/entry.rs Thu Oct 03 16:35:31 2024 +0200 +++ b/rust/hg-core/src/dirstate/entry.rs Wed Oct 16 17:19:38 2024 +0200 @@ -116,7 +116,12 @@ metadata: &fs::Metadata, boundary: &Self, ) -> io::Result> { - let mut mtime = Self::for_mtime_of(metadata)?; + Ok(Self::for_mtime_of(metadata)?.for_reliable_mtime_of_self(boundary)) + } + + /// See [`Self::for_reliable_mtime_of`] + pub fn for_reliable_mtime_of_self(&self, boundary: &Self) -> Option { + let mut new = *self; // If the mtime of the ambiguous file is younger (or equal) to the // starting point of the `status` walk, we cannot garantee that // another, racy, write will not happen right after with the same mtime @@ -126,23 +131,23 @@ // mismatch between the current clock and previous file system // operation. So mtime more than one days in the future are considered // fine. - let reliable = if mtime.truncated_seconds == boundary.truncated_seconds + let reliable = if self.truncated_seconds == boundary.truncated_seconds { - mtime.second_ambiguous = true; - mtime.nanoseconds != 0 + new.second_ambiguous = true; + self.nanoseconds != 0 && boundary.nanoseconds != 0 - && mtime.nanoseconds < boundary.nanoseconds + && self.nanoseconds < boundary.nanoseconds } else { // `truncated_seconds` is less than 2**31, // so this does not overflow `u32`: let one_day_later = boundary.truncated_seconds + 24 * 3600; - mtime.truncated_seconds < boundary.truncated_seconds - || mtime.truncated_seconds > one_day_later + self.truncated_seconds < boundary.truncated_seconds + || self.truncated_seconds > one_day_later }; if reliable { - Ok(Some(mtime)) + Some(new) } else { - Ok(None) + None } }