Skip to content

Commit 8d17dc6

Browse files
committed
also extract index threads (#450)
1 parent 5a3155a commit 8d17dc6

File tree

2 files changed

+71
-31
lines changed

2 files changed

+71
-31
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use super::Error;
2+
use crate::Repository;
3+
use std::convert::TryInto;
4+
5+
pub fn index_threads(repo: &Repository) -> Result<Option<usize>, Error> {
6+
let lenient_config = repo.options.lenient_config;
7+
let message = "The configured pack.threads is invalid. It must be 0 or greater, with 0 turning it off";
8+
Ok(
9+
match repo
10+
.config
11+
.resolved
12+
.integer_filter("pack", None, "threads", &mut repo.filter_config_section())
13+
.transpose()
14+
{
15+
Ok(Some(0)) => Some(1),
16+
Ok(Some(n)) => match n.try_into() {
17+
Ok(n) => Some(n),
18+
Err(_) if lenient_config => None,
19+
Err(_) => {
20+
return Err(Error::Configuration {
21+
message: "The value for pack.threads is out of range",
22+
desired: n.into(),
23+
source: None,
24+
})
25+
}
26+
},
27+
Ok(None) => None,
28+
Err(_) if lenient_config => None,
29+
Err(err) => {
30+
return Err(Error::Configuration {
31+
message,
32+
desired: None,
33+
source: err.into(),
34+
})
35+
}
36+
},
37+
)
38+
}
39+
40+
pub fn pack_index_version(repo: &Repository) -> Result<git_pack::index::Version, Error> {
41+
use git_pack::index::Version;
42+
let lenient_config = repo.options.lenient_config;
43+
let message = "The configured pack.indexVersion is invalid. It must be 1 or 2, with 2 being the default";
44+
Ok(
45+
match repo.config.resolved.integer("pack", None, "indexVersion").transpose() {
46+
Ok(Some(v)) if v == 1 => Version::V1,
47+
Ok(Some(v)) if v == 2 => Version::V2,
48+
Ok(None) => Version::V2,
49+
Ok(Some(_)) | Err(_) if lenient_config => Version::V2,
50+
Ok(Some(v)) => {
51+
return Err(Error::Configuration {
52+
message,
53+
desired: v.into(),
54+
source: None,
55+
})
56+
}
57+
Err(err) => {
58+
return Err(Error::Configuration {
59+
message,
60+
desired: None,
61+
source: err.into(),
62+
})
63+
}
64+
},
65+
)
66+
}

git-repository/src/remote/connection/fetch.rs renamed to git-repository/src/remote/connection/fetch/mod.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ mod error {
99
#[derive(Debug, thiserror::Error)]
1010
#[error("TBD")]
1111
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 {
12+
#[error("{message}{}", desired.map(|n| format!(" (got {})", n)).unwrap_or_default())]
13+
Configuration {
14+
message: &'static str,
1415
desired: Option<i64>,
1516
source: Option<git_config::value::Error>,
1617
},
@@ -60,6 +61,7 @@ where
6061

6162
let repo = con.remote.repo;
6263
let _index_version = config::pack_index_version(repo)?;
64+
let _thread_limit = config::index_threads(repo)?;
6365
// let options = git_pack::bundle::write::Options {
6466
// thread_limit: ctx.thread_limit,
6567
// index_version: git_pack::index::Version::V2,
@@ -71,35 +73,7 @@ where
7173
}
7274
}
7375

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-
}
76+
mod config;
10377

10478
/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.
10579
#[allow(dead_code)]

0 commit comments

Comments
 (0)