(
repo_root: &Path,
git_repo: &GitRepository,
)
| 384 | } |
| 385 | |
| 386 | fn current_conversion_policy( |
| 387 | repo_root: &Path, |
| 388 | git_repo: &GitRepository, |
| 389 | ) -> CliResult<(ConversionPolicy, ContentFilterConfig)> { |
| 390 | let config = git_repo |
| 391 | .config() |
| 392 | .map_err(|error| git_error(format!("cannot read Git configuration: {error}")))?; |
| 393 | let object_format = match config.get_string("extensions.objectFormat") { |
| 394 | Ok(value) if value.eq_ignore_ascii_case("sha1") => GitHashAlgorithm::Sha1, |
| 395 | Ok(value) if value.eq_ignore_ascii_case("sha256") => GitHashAlgorithm::Sha256, |
| 396 | Ok(value) => { |
| 397 | return Err(git_error(format!( |
| 398 | "unsupported Git object algorithm '{value}'" |
| 399 | ))) |
| 400 | } |
| 401 | Err(error) if error.code() == git2::ErrorCode::NotFound => GitHashAlgorithm::Sha1, |
| 402 | Err(error) => { |
| 403 | return Err(git_error(format!( |
| 404 | "cannot read Git object algorithm: {error}" |
| 405 | ))) |
| 406 | } |
| 407 | }; |
| 408 | let mut policy = ConversionPolicy::new(object_format); |
| 409 | policy.platform.executable_bit = config.get_bool("core.filemode").unwrap_or(cfg!(unix)); |
| 410 | policy.platform.symlinks = config.get_bool("core.symlinks").unwrap_or(cfg!(unix)); |
| 411 | policy.platform.case_sensitive = !config.get_bool("core.ignorecase").unwrap_or(false); |
| 412 | policy.platform.unicode_normalizing = |
| 413 | config.get_bool("core.precomposeunicode").unwrap_or(false); |
| 414 | |
| 415 | let repo_config = atomic_config::RepoConfig::load(&repo_root.join(".atomic/config.toml")) |
| 416 | .map_err(|error| git_error(format!("cannot load Atomic content-filter policy: {error}")))?; |
| 417 | let mut relevant = Vec::new(); |
| 418 | relevant.extend_from_slice(format!("object={object_format:?}\n").as_bytes()); |
| 419 | relevant.extend_from_slice( |
| 420 | format!( |
| 421 | "filemode={}\nsymlinks={}\nignorecase={}\nprecomposeunicode={}\ntimeout={}\nmax-output={}\n", |
| 422 | policy.platform.executable_bit, |
| 423 | policy.platform.symlinks, |
| 424 | !policy.platform.case_sensitive, |
| 425 | policy.platform.unicode_normalizing, |
| 426 | repo_config.filters.timeout_ms, |
| 427 | repo_config.filters.max_output_bytes |
| 428 | ) |
| 429 | .as_bytes(), |
| 430 | ); |
| 431 | policy.relevant_git_config = content_key(&relevant); |
| 432 | policy.filter_driver_versions = repo_config |
| 433 | .filters |
| 434 | .drivers |
| 435 | .iter() |
| 436 | .map(|(name, driver)| { |
| 437 | content_key( |
| 438 | format!( |
| 439 | "{name}\0{}\0{}\0{}", |
| 440 | driver.clean.as_deref().unwrap_or(""), |
| 441 | driver.smudge.as_deref().unwrap_or(""), |
| 442 | driver.required |
| 443 | ) |
no test coverage detected