|
| 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 | +} |
0 commit comments