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

Method find_change_by_prefix

atomic-repository/src/repository/changes.rs:1311–1331  ·  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

1309 /// }
1310 /// ```
1311 pub fn find_change_by_prefix(&self, prefix: &str) -> Result<Option<Hash>, RepositoryError> {
1312 let prefix_upper = prefix.to_uppercase();
1313 let mut matches = Vec::new();
1314
1315 for result in self.iter_changes() {
1316 let hash = result?;
1317 let hash_str = hash.to_base32();
1318 if hash_str.starts_with(&prefix_upper) {
1319 matches.push(hash);
1320 // If we find more than one, it's ambiguous
1321 if matches.len() > 1 {
1322 return Err(RepositoryError::AmbiguousHash {
1323 prefix: prefix.to_string(),
1324 matches: matches.iter().map(|h| h.to_base32()).collect(),
1325 });
1326 }
1327 }
1328 }
1329
1330 Ok(matches.into_iter().next())
1331 }
1332
1333 // =========================================================================
1334 // Provenance Graph Operations

Callers 9

parse_change_hashFunction · 0.80
resolve_changeFunction · 0.80
resolve_changesMethod · 0.80
resolve_hash_prefixMethod · 0.80
get_change_implFunction · 0.80
preview_mutationMethod · 0.80
resolve_change_referenceFunction · 0.80
reviseMethod · 0.80
unrecordMethod · 0.80

Calls 8

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

Tested by

no test coverage detected