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

Function parse_change_hash

atomic-cli/src/commands/insert.rs:487–511  ·  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

485
486/// Parse a change hash from a string (full or abbreviated).
487fn parse_change_hash(repo: &Repository, hash_str: &str) -> CliResult<Hash> {
488 // Try to parse as full hash first
489 if let Some(hash) = Hash::from_base32(hash_str.as_bytes()) {
490 return Ok(hash);
491 }
492
493 // Try to find by prefix
494 if hash_str.len() >= 2 {
495 // Look through recent changes to find a match
496 match repo.find_change_by_prefix(hash_str) {
497 Ok(Some(hash)) => return Ok(hash),
498 Ok(None) => {}
499 Err(_e) => {
500 // Check if it's an ambiguous hash error
501 return Err(CliError::AmbiguousHash {
502 hash: hash_str.to_string(),
503 });
504 }
505 }
506 }
507
508 Err(CliError::ChangeNotFound {
509 hash: hash_str.to_string(),
510 })
511}
512
513/// Print the outcome of a single insert operation.
514fn print_insert_outcome(

Callers 2

run_single_insertFunction · 0.85
run_pickFunction · 0.85

Calls 3

find_change_by_prefixMethod · 0.80
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected