Skip to content

Commit a8333f1

Browse files
committed
feat: add Repository::stat_options() to learn how an index would compare filesystem stats.
1 parent 959dc17 commit a8333f1

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

gix/src/config/cache/access.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Cache {
137137

138138
let install_dir = crate::path::install_dir().ok();
139139
let home = self.home_dir();
140-
let ctx = crate::config::cache::interpolate_context(install_dir.as_deref(), home.as_deref());
140+
let ctx = config::cache::interpolate_context(install_dir.as_deref(), home.as_deref());
141141
Some(path.interpolate(ctx))
142142
}
143143

@@ -154,6 +154,23 @@ impl Cache {
154154
})
155155
}
156156

157+
#[cfg(feature = "index")]
158+
pub(crate) fn stat_options(&self) -> Result<gix_index::entry::stat::Options, config::stat_options::Error> {
159+
use crate::config::tree::gitoxide;
160+
Ok(gix_index::entry::stat::Options {
161+
trust_ctime: boolean(self, "core.trustCTime", &Core::TRUST_C_TIME, true)?,
162+
use_nsec: boolean(self, "gitoxide.core.useNsec", &gitoxide::Core::USE_NSEC, false)?,
163+
use_stdev: boolean(self, "gitoxide.core.useStdev", &gitoxide::Core::USE_STDEV, false)?,
164+
check_stat: self
165+
.apply_leniency(
166+
self.resolved
167+
.string("core", None, "checkStat")
168+
.map(|v| Core::CHECK_STAT.try_into_checkstat(v)),
169+
)?
170+
.unwrap_or(true),
171+
})
172+
}
173+
157174
/// Collect everything needed to checkout files into a worktree.
158175
/// Note that some of the options being returned will be defaulted so safe settings, the caller might have to override them
159176
/// depending on the use-case.
@@ -162,7 +179,7 @@ impl Cache {
162179
&self,
163180
repo: &crate::Repository,
164181
attributes_source: gix_worktree::stack::state::attributes::Source,
165-
) -> Result<gix_worktree_state::checkout::Options, crate::config::checkout_options::Error> {
182+
) -> Result<gix_worktree_state::checkout::Options, config::checkout_options::Error> {
166183
use crate::config::tree::gitoxide;
167184
let git_dir = repo.git_dir();
168185
let thread_limit = self.apply_leniency(
@@ -202,18 +219,12 @@ impl Cache {
202219
destination_is_initially_empty: false,
203220
overwrite_existing: false,
204221
keep_going: false,
205-
stat_options: gix_index::entry::stat::Options {
206-
trust_ctime: boolean(self, "core.trustCTime", &Core::TRUST_C_TIME, true)?,
207-
use_nsec: boolean(self, "gitoxide.core.useNsec", &gitoxide::Core::USE_NSEC, false)?,
208-
use_stdev: boolean(self, "gitoxide.core.useStdev", &gitoxide::Core::USE_STDEV, false)?,
209-
check_stat: self
210-
.apply_leniency(
211-
self.resolved
212-
.string("core", None, "checkStat")
213-
.map(|v| Core::CHECK_STAT.try_into_checkstat(v)),
214-
)?
215-
.unwrap_or(true),
216-
},
222+
stat_options: self.stat_options().map_err(|err| match err {
223+
config::stat_options::Error::ConfigCheckStat(err) => {
224+
config::checkout_options::Error::ConfigCheckStat(err)
225+
}
226+
config::stat_options::Error::ConfigBoolean(err) => config::checkout_options::Error::ConfigBoolean(err),
227+
})?,
217228
})
218229
}
219230

gix/src/config/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ pub mod diff {
119119
}
120120
}
121121

122+
///
123+
pub mod stat_options {
124+
/// The error produced when collecting stat information, and returned by [Repository::stat_options()](crate::Repository::stat_options()).
125+
#[derive(Debug, thiserror::Error)]
126+
#[allow(missing_docs)]
127+
pub enum Error {
128+
#[error(transparent)]
129+
ConfigCheckStat(#[from] super::key::GenericErrorWithValue),
130+
#[error(transparent)]
131+
ConfigBoolean(#[from] super::boolean::Error),
132+
}
133+
}
134+
122135
///
123136
#[cfg(feature = "attributes")]
124137
pub mod checkout_options {

gix/src/repository/config/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ impl crate::Repository {
2929
self.config.fs_capabilities()
3030
}
3131

32+
/// Return filesystem options on how to perform stat-checks, typically in relation to the index.
33+
///
34+
/// Note that these values have not been [probed](gix_fs::Capabilities::probe()).
35+
#[cfg(feature = "index")]
36+
pub fn stat_options(&self) -> Result<gix_index::entry::stat::Options, config::stat_options::Error> {
37+
self.config.stat_options()
38+
}
39+
3240
/// The options used to open the repository.
3341
pub fn open_options(&self) -> &crate::open::Options {
3442
&self.options

0 commit comments

Comments
 (0)