History

also extract index threads (#450)

Sebastian Thiel committed 4 years ago

Commit 8d17dc61 parent 5a3155a2 files · +71 −31Browse files

Unified · Split

2 files
  1. git-repository/src/remote/connection/fetch/config.rs +66 −0
  2. git-repository/src/remote/connection/fetch/mod.rs +5 −31
git-repository/src/remote/connection/fetch/config.rs+66−0
@@ -0,0 +1,66 @@
1use super::Error;
2use crate::Repository;
3use std::convert::TryInto;
4
5pub 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
40pub 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/mod.rsrenamed from git-repository/src/remote/connection/fetch.rs+5−31
@@ -9,8 +9,9 @@ mod error { · 8 unmodified lines
9 #[derive(Debug, thiserror::Error)]9 #[derive(Debug, thiserror::Error)]
10 #[error("TBD")]10 #[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())]12 #[error("{message}{}", desired.map(|n| format!(" (got {})", n)).unwrap_or_default())]
13 PackIndexVersion {13 Configuration {
14 message: &'static str,
14 desired: Option<i64>,15 desired: Option<i64>,
15 source: Option<git_config::value::Error>,16 source: Option<git_config::value::Error>,
16 },17 },
@@ -60,6 +61,7 @@ where · 43 unmodified lines
60 61
61 let repo = con.remote.repo;62 let repo = con.remote.repo;
62 let _index_version = config::pack_index_version(repo)?;63 let _index_version = config::pack_index_version(repo)?;
64 let _thread_limit = config::index_threads(repo)?;
63 // let options = git_pack::bundle::write::Options {65 // let options = git_pack::bundle::write::Options {
64 // thread_limit: ctx.thread_limit,66 // thread_limit: ctx.thread_limit,
65 // index_version: git_pack::index::Version::V2,67 // index_version: git_pack::index::Version::V2,
@@ -71,35 +73,7 @@ where · 5 unmodified lines
71 }73 }
72}74}
73 75
74mod config {76mod 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 77
104/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.78/// A structure to hold the result of the handshake with the remote and configure the upcoming fetch operation.
105#[allow(dead_code)]79#[allow(dead_code)]