Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/dirstate_tree/status.rs @ 52058:b55f653a0b34
rust-utils: move the `filesystem_now` function to a util
This is going to be useful for an upcoming `hg update` fastpath.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 30 Sep 2024 17:45:10 +0200 |
parents | 3876d4c6c79e |
children | 644c696b6c18 |
comparison
equal
deleted
inserted
replaced
52057:88aa21d654e5 | 52058:b55f653a0b34 |
---|---|
7 use crate::dirstate_tree::dirstate_map::DirstateVersion; | 7 use crate::dirstate_tree::dirstate_map::DirstateVersion; |
8 use crate::dirstate_tree::dirstate_map::NodeRef; | 8 use crate::dirstate_tree::dirstate_map::NodeRef; |
9 use crate::dirstate_tree::on_disk::DirstateV2ParseError; | 9 use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
10 use crate::matchers::get_ignore_function; | 10 use crate::matchers::get_ignore_function; |
11 use crate::matchers::{Matcher, VisitChildrenSet}; | 11 use crate::matchers::{Matcher, VisitChildrenSet}; |
12 use crate::utils::files::filesystem_now; | |
12 use crate::utils::files::get_bytes_from_os_string; | 13 use crate::utils::files::get_bytes_from_os_string; |
13 use crate::utils::files::get_bytes_from_path; | 14 use crate::utils::files::get_bytes_from_path; |
14 use crate::utils::files::get_path_from_bytes; | 15 use crate::utils::files::get_path_from_bytes; |
15 use crate::utils::hg_path::hg_path_to_path_buf; | 16 use crate::utils::hg_path::hg_path_to_path_buf; |
16 use crate::utils::hg_path::HgPath; | 17 use crate::utils::hg_path::HgPath; |
28 use std::io; | 29 use std::io; |
29 use std::os::unix::prelude::FileTypeExt; | 30 use std::os::unix::prelude::FileTypeExt; |
30 use std::path::Path; | 31 use std::path::Path; |
31 use std::path::PathBuf; | 32 use std::path::PathBuf; |
32 use std::sync::Mutex; | 33 use std::sync::Mutex; |
33 use std::time::SystemTime; | |
34 | 34 |
35 /// Returns the status of the working directory compared to its parent | 35 /// Returns the status of the working directory compared to its parent |
36 /// changeset. | 36 /// changeset. |
37 /// | 37 /// |
38 /// This algorithm is based on traversing the filesystem tree (`fs` in function | 38 /// This algorithm is based on traversing the filesystem tree (`fs` in function |
1032 FakeFileType::BadType(ty) => Some(ty), | 1032 FakeFileType::BadType(ty) => Some(ty), |
1033 _ => None, | 1033 _ => None, |
1034 } | 1034 } |
1035 } | 1035 } |
1036 } | 1036 } |
1037 | |
1038 /// Return the `mtime` of a temporary file newly-created in the `.hg` directory | |
1039 /// of the give repository. | |
1040 /// | |
1041 /// This is similar to `SystemTime::now()`, with the result truncated to the | |
1042 /// same time resolution as other files’ modification times. Using `.hg` | |
1043 /// instead of the system’s default temporary directory (such as `/tmp`) makes | |
1044 /// it more likely the temporary file is in the same disk partition as contents | |
1045 /// of the working directory, which can matter since different filesystems may | |
1046 /// store timestamps with different resolutions. | |
1047 /// | |
1048 /// This may fail, typically if we lack write permissions. In that case we | |
1049 /// should continue the `status()` algoritm anyway and consider the current | |
1050 /// date/time to be unknown. | |
1051 fn filesystem_now(repo_root: &Path) -> Result<SystemTime, io::Error> { | |
1052 tempfile::tempfile_in(repo_root.join(".hg"))? | |
1053 .metadata()? | |
1054 .modified() | |
1055 } |