Skip to content

Commit b5c36b8

Browse files
committed
feat: add clone::PrepareFetch::with_in_memory_config_overrides().
With it one can affect the repository configuration right before fetching.
1 parent 9833b45 commit b5c36b8

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

gix/src/clone/access.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl PrepareFetch {
1010
/// _all changes done in `f()` will be persisted_.
1111
///
1212
/// It can also be used to configure additional options, like those for fetching tags. Note that
13-
/// [`with_fetch_tags()`][crate::Remote::with_fetch_tags()] should be called here to configure the clone as desired.
13+
/// [`with_fetch_tags()`](crate::Remote::with_fetch_tags()) should be called here to configure the clone as desired.
1414
/// Otherwise a clone is configured to be complete and fetches all tags, not only those reachable from all branches.
1515
pub fn configure_remote(
1616
mut self,
@@ -21,7 +21,7 @@ impl PrepareFetch {
2121
}
2222

2323
/// Set the remote's name to the given value after it was configured using the function provided via
24-
/// [`configure_remote()`][Self::configure_remote()].
24+
/// [`configure_remote()`](Self::configure_remote()).
2525
///
2626
/// If not set here, it defaults to `origin` or the value of `clone.defaultRemoteName`.
2727
pub fn with_remote_name(mut self, name: impl Into<BString>) -> Result<Self, crate::remote::name::Error> {
@@ -35,10 +35,11 @@ impl PrepareFetch {
3535
self
3636
}
3737

38-
/// Apply the given configuration `values` early to allow affecting the repository instantiation phase.
39-
/// The configuration is marked with [source API][gix_config::Source::Api].
40-
pub fn config_overrides(mut self, values: impl IntoIterator<Item = impl Into<BString>>) -> Self {
41-
self.api_config_overrides = values.into_iter().map(Into::into).collect();
38+
/// Apply the given configuration `values` right before readying the actual fetch from the remote.
39+
/// The configuration is marked with [source API](gix_config::Source::Api), and will not be written back, it's
40+
/// retained only in memory.
41+
pub fn with_in_memory_config_overrides(mut self, values: impl IntoIterator<Item = impl Into<BString>>) -> Self {
42+
self.config_overrides = values.into_iter().map(Into::into).collect();
4243
self
4344
}
4445
}

gix/src/clone/fetch/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ impl PrepareFetch {
7979
.as_mut()
8080
.expect("user error: multiple calls are allowed only until it succeeds");
8181

82-
let mut snapshot = repo.config_snapshot_mut();
83-
snapshot.append_config(self.api_config_overrides.as_slice(), gix_config::Source::Api)?;
84-
snapshot.commit()?;
82+
if !self.config_overrides.is_empty() {
83+
let mut snapshot = repo.config_snapshot_mut();
84+
snapshot.append_config(&self.config_overrides, gix_config::Source::Api)?;
85+
snapshot.commit()?;
86+
}
8587

8688
let remote_name = match self.remote_name.as_ref() {
8789
Some(name) => name.to_owned(),

gix/src/clone/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct PrepareFetch {
2121
/// The name of the remote, which defaults to `origin` if not overridden.
2222
remote_name: Option<BString>,
2323
/// Additional config `values` that are applied in-memory before starting the fetch process.
24-
api_config_overrides: Vec<BString>,
24+
config_overrides: Vec<BString>,
2525
/// A function to configure a remote prior to fetching a pack.
2626
configure_remote: Option<ConfigureRemoteFn>,
2727
/// A function to configure a connection before using it.
@@ -128,7 +128,7 @@ impl PrepareFetch {
128128
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
129129
fetch_options: Default::default(),
130130
repo: Some(repo),
131-
api_config_overrides: Vec::new(),
131+
config_overrides: Vec::new(),
132132
remote_name: None,
133133
configure_remote: None,
134134
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
@@ -147,8 +147,6 @@ pub struct PrepareCheckout {
147147
pub(self) repo: Option<crate::Repository>,
148148
}
149149

150-
mod access;
151-
152150
// This module encapsulates functionality that works with both feature toggles. Can be combined with `fetch`
153151
// once async and clone are a thing.
154152
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
@@ -184,6 +182,8 @@ mod access_feat {
184182
#[cfg(any(feature = "async-network-client-async-std", feature = "blocking-network-client"))]
185183
pub mod fetch;
186184

185+
mod access;
186+
187187
///
188188
#[cfg(feature = "worktree-mutation")]
189189
pub mod checkout;

gix/tests/clone/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod blocking_io {
109109
fn from_shallow_allowed_by_default() -> crate::Result {
110110
let tmp = gix_testtools::tempfile::TempDir::new()?;
111111
let (repo, _change) = gix::prepare_clone_bare(remote::repo("base.shallow").path(), tmp.path())?
112+
.with_in_memory_config_overrides(Some("my.marker=1"))
112113
.fetch_only(gix::progress::Discard, &std::sync::atomic::AtomicBool::default())?;
113114
assert_eq!(
114115
repo.shallow_commits()?.expect("present").as_slice(),
@@ -118,6 +119,18 @@ mod blocking_io {
118119
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552"),
119120
]
120121
);
122+
assert_eq!(
123+
repo.config_snapshot().boolean("my.marker"),
124+
Some(true),
125+
"configuration overrides are set in time"
126+
);
127+
assert_eq!(
128+
gix::open_opts(repo.git_dir(), gix::open::Options::isolated())?
129+
.config_snapshot()
130+
.boolean("my.marker"),
131+
None,
132+
"these options are not persisted"
133+
);
121134
Ok(())
122135
}
123136

0 commit comments

Comments
 (0)