The deterministic conversion policy for one live Git repository (RFC §6.1–6.2): object format, platform capabilities, exclusion rules.
(git: &GitRepository)
| 408 | /// The deterministic conversion policy for one live Git repository |
| 409 | /// (RFC §6.1–6.2): object format, platform capabilities, exclusion rules. |
| 410 | pub fn conversion_policy_for_git(git: &GitRepository) -> Result<ConversionPolicy, ShimAnchorError> { |
| 411 | let config = git |
| 412 | .config() |
| 413 | .map_err(|error| ShimAnchorError::Git(format!("cannot read Git configuration: {error}")))?; |
| 414 | let object_format = match config.get_string("extensions.objectFormat") { |
| 415 | Ok(value) if value.eq_ignore_ascii_case("sha1") => GitHashAlgorithm::Sha1, |
| 416 | Ok(value) if value.eq_ignore_ascii_case("sha256") => GitHashAlgorithm::Sha256, |
| 417 | Ok(value) => { |
| 418 | return Err(ShimAnchorError::Git(format!( |
| 419 | "unsupported Git object algorithm '{value}'" |
| 420 | ))) |
| 421 | } |
| 422 | Err(error) if error.code() == git2::ErrorCode::NotFound => GitHashAlgorithm::Sha1, |
| 423 | Err(error) => { |
| 424 | return Err(ShimAnchorError::Git(format!( |
| 425 | "cannot read Git object algorithm: {error}" |
| 426 | ))) |
| 427 | } |
| 428 | }; |
| 429 | let mut policy = ConversionPolicy::new(object_format); |
| 430 | policy.platform = PlatformCapabilities { |
| 431 | lossless_unix_paths: cfg!(unix), |
| 432 | symlinks: config.get_bool("core.symlinks").unwrap_or(cfg!(unix)), |
| 433 | executable_bit: config.get_bool("core.filemode").unwrap_or(cfg!(unix)), |
| 434 | case_sensitive: !config.get_bool("core.ignorecase").unwrap_or(false), |
| 435 | unicode_normalizing: config.get_bool("core.precomposeunicode").unwrap_or(false), |
| 436 | }; |
| 437 | // RFC §6.2: `.vault/` is private by default but may be tracked under |
| 438 | // explicit policy. Anchoring must prove equivalence under the same |
| 439 | // policy the import and the verifier resolved, so a colocated |
| 440 | // repository that tracks `.vault/` anchors with the vault included in |
| 441 | // the manifest projection. Fails closed on a corrupt configuration. |
| 442 | policy.exclusions = crate::ExclusionPolicy::resolve_for_git(git).map_err(|error| { |
| 443 | ShimAnchorError::Git(format!("cannot resolve the shim vault policy: {error}")) |
| 444 | })?; |
| 445 | Ok(policy) |
| 446 | } |
| 447 | |
| 448 | fn object_format_for(oid: &git2::Oid) -> Result<GitObjectFormat, ShimAnchorError> { |
| 449 | match oid.as_bytes().len() { |