Skip to content

Commit 5a3155a

Browse files
committed
obtain configuration for index version (with respect for lenient config) (#450)
1 parent d5254c2 commit 5a3155a

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

git-repository/src/open.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Options {
201201
/// If set, default is false, invalid configuration values will cause an error even if these can safely be defaulted.
202202
///
203203
/// This is recommended for all applications that prefer correctness over usability.
204-
/// `git` itself by defaults to strict configuration mode to let you know if configuration is incorrect.
204+
/// `git` itself defaults to strict configuration mode, flagging incorrect configuration immediately.
205205
pub fn strict_config(mut self, toggle: bool) -> Self {
206206
self.lenient_config = !toggle;
207207
self

git-repository/src/remote/connection/fetch.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ mod error {
88
/// The error returned by [`receive()`](super::Prepare::receive()).
99
#[derive(Debug, thiserror::Error)]
1010
#[error("TBD")]
11-
pub enum Error {}
11+
pub enum Error {
12+
#[error("The configured pack.indexVersion is not valid. It must be 1 or 2, with 2 being the default{}", desired.map(|n| format!(" (but got {})", n)).unwrap_or_default())]
13+
PackIndexVersion {
14+
desired: Option<i64>,
15+
source: Option<git_config::value::Error>,
16+
},
17+
}
1218
}
1319
pub use error::Error;
1420

@@ -42,14 +48,59 @@ where
4248
T: Transport,
4349
P: Progress,
4450
{
45-
/// receive the pack and perform the operation as configured by git via `git-config` or overridden by various builder methods.
51+
/// Receive the pack and perform the operation as configured by git via `git-config` or overridden by various builder methods.
52+
///
53+
/// ### Negotiation
54+
///
55+
/// "fetch.negotiationAlgorithm" describes algorithms `git` uses currently, with the default being `consecutive` and `skipping` being
56+
/// experimented with. We currently implement something we could call 'naive' which works for now.
4657
pub fn receive(mut self, _should_interrupt: &AtomicBool) -> Result<(), Error> {
4758
let mut con = self.con.take().expect("receive() can only be called once");
4859
git_protocol::fetch::indicate_end_of_interaction(&mut con.transport).ok();
60+
61+
let repo = con.remote.repo;
62+
let _index_version = config::pack_index_version(repo)?;
63+
// let options = git_pack::bundle::write::Options {
64+
// thread_limit: ctx.thread_limit,
65+
// index_version: git_pack::index::Version::V2,
66+
// iteration_mode: git_pack::data::input::Mode::Verify,
67+
// object_hash: ctx.object_hash,
68+
// };
69+
4970
todo!()
5071
}
5172
}
5273

74+
mod config {
75+
use super::Error;
76+
use crate::Repository;
77+
78+
pub fn pack_index_version(repo: &Repository) -> Result<git_pack::index::Version, Error> {
79+
use git_pack::index::Version;
80+
let lenient_config = repo.options.lenient_config;
81+
Ok(
82+
match repo.config.resolved.integer("pack", None, "indexVersion").transpose() {
83+
Ok(Some(v)) if v == 1 => Version::V1,
84+
Ok(Some(v)) if v == 2 => Version::V2,
85+
Ok(None) => Version::V2,
86+
Ok(Some(_)) | Err(_) if lenient_config => Version::V2,
87+
Ok(Some(v)) => {
88+
return Err(Error::PackIndexVersion {
89+
desired: v.into(),
90+
source: None,
91+
})
92+
}
93+
Err(err) => {
94+
return Err(Error::PackIndexVersion {
95+
desired: None,
96+
source: err.into(),
97+
})
98+
}
99+
},
100+
)
101+
}
102+
}
103+
53104
/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.
54105
#[allow(dead_code)]
55106
pub struct Prepare<'remote, 'repo, T, P>

0 commit comments

Comments
 (0)