MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / resolve_by_prefix

Function resolve_by_prefix

atomic-cli/src/commands/git/binding.rs:630–660  ·  view source on GitHub ↗
(repo: &Repository, prefix: &str)

Source from the content-addressed store, hash-verified

628}
629
630fn resolve_by_prefix(repo: &Repository, prefix: &str) -> CliResult<GitStateBinding> {
631 let lower = prefix.to_ascii_lowercase();
632 let ids = repo.binding_ids().map_err(CliError::from)?;
633 let matches: Vec<_> = ids
634 .iter()
635 .filter(|id| id.to_hex().starts_with(&lower))
636 .collect();
637 match matches.as_slice() {
638 [id] => repo
639 .load_binding(id)
640 .map_err(CliError::from)?
641 .ok_or_else(|| {
642 CliError::Repository(atomic_repository::RepositoryError::InvalidOperation {
643 message: format!("binding {prefix} is not stored locally"),
644 })
645 }),
646 [] => Err(CliError::Repository(
647 atomic_repository::RepositoryError::InvalidOperation {
648 message: format!("binding prefix {prefix} matches nothing"),
649 },
650 )),
651 many => Err(CliError::Repository(
652 atomic_repository::RepositoryError::InvalidOperation {
653 message: format!(
654 "binding prefix {prefix} is ambiguous: {} matches",
655 matches.len()
656 ),
657 },
658 )),
659 }
660}
661
662fn git_map(error: impl std::fmt::Display) -> CliError {
663 CliError::Repository(atomic_repository::RepositoryError::InvalidOperation {

Callers 1

verifyFunction · 0.85

Calls 7

RepositoryClass · 0.85
binding_idsMethod · 0.80
load_bindingMethod · 0.80
collectMethod · 0.45
iterMethod · 0.45
to_hexMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected