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

Function parse_change_hash

atomic-cli/src/commands/insert.rs:631–655  ·  view source on GitHub ↗

Parse a change hash from a string (full or abbreviated).

(repo: &Repository, hash_str: &str)

Source from the content-addressed store, hash-verified

629
630/// Parse a change hash from a string (full or abbreviated).
631fn parse_change_hash(repo: &Repository, hash_str: &str) -> CliResult<Hash> {
632 // Try to parse as full hash first
633 if let Some(hash) = Hash::from_base32(hash_str.as_bytes()) {
634 return Ok(hash);
635 }
636
637 // Try to find by prefix
638 if hash_str.len() >= 2 {
639 // Look through recent changes to find a match
640 match repo.find_change_by_prefix(hash_str) {
641 Ok(Some(hash)) => return Ok(hash),
642 Ok(None) => {}
643 Err(_e) => {
644 // Check if it's an ambiguous hash error
645 return Err(CliError::AmbiguousHash {
646 hash: hash_str.to_string(),
647 });
648 }
649 }
650 }
651
652 Err(CliError::ChangeNotFound {
653 hash: hash_str.to_string(),
654 })
655}
656
657/// Print the outcome of a single insert operation.
658fn print_insert_outcome(

Callers 2

run_single_insertFunction · 0.70
run_change_insertFunction · 0.70

Calls 3

find_change_by_prefixMethod · 0.80
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected