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

Method find_change_by_prefix

atomic-repository/src/repository/changes.rs:601–621  ·  view source on GitHub ↗

Find a change by hash prefix. This searches through all stored changes to find one whose hash starts with the given prefix. Useful for CLI commands that allow abbreviated hashes. # Arguments `prefix` - The hash prefix (case-insensitive, at least 2 characters) # Returns `Ok(Some(hash))` - Found a unique matching change `Ok(None)` - No change matched the prefix `Err(_)` - Multiple changes match

(&self, prefix: &str)

Source from the content-addressed store, hash-verified

599 /// }
600 /// ```
601 pub fn find_change_by_prefix(&self, prefix: &str) -> Result<Option<Hash>, RepositoryError> {
602 let prefix_upper = prefix.to_uppercase();
603 let mut matches = Vec::new();
604
605 for result in self.iter_changes() {
606 let hash = result?;
607 let hash_str = hash.to_base32();
608 if hash_str.starts_with(&prefix_upper) {
609 matches.push(hash);
610 // If we find more than one, it's ambiguous
611 if matches.len() > 1 {
612 return Err(RepositoryError::AmbiguousHash {
613 prefix: prefix.to_string(),
614 matches: matches.iter().map(|h| h.to_base32()).collect(),
615 });
616 }
617 }
618 }
619
620 Ok(matches.into_iter().next())
621 }
622
623 // =========================================================================
624 // Provenance Graph Operations

Callers 1

parse_change_hashFunction · 0.80

Calls 7

iter_changesMethod · 0.45
to_base32Method · 0.45
pushMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected