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

Method resolve_hash_prefix

atomic-cli/src/commands/change/command.rs:207–241  ·  view source on GitHub ↗

Resolve a hash prefix to a full hash.

(
        &self,
        repo: &Repository,
        view_name: &str,
        prefix: &str,
    )

Source from the content-addressed store, hash-verified

205
206 /// Resolve a hash prefix to a full hash.
207 fn resolve_hash_prefix(
208 &self,
209 repo: &Repository,
210 view_name: &str,
211 prefix: &str,
212 ) -> CliResult<(Hash, Option<u64>)> {
213 // Search for matching changes
214 let mut matches: Vec<Hash> = Vec::new();
215
216 for result in repo.iter_changes() {
217 let hash = result.map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?;
218 let hash_str = hash.to_base32();
219 if hash_str.starts_with(prefix) {
220 matches.push(hash);
221 }
222 }
223
224 match matches.len() {
225 0 => Err(CliError::ChangeNotFound {
226 hash: prefix.to_string(),
227 }),
228 1 => {
229 let hash = matches[0];
230 let seq = self.find_sequence_for_hash(repo, view_name, &hash)?;
231 Ok((hash, seq))
232 }
233 _ => {
234 // Format the matches for display in the error message
235 let match_list: Vec<String> = matches.iter().map(|h| h.to_base32()).collect();
236 Err(CliError::AmbiguousHash {
237 hash: format!("{} (matches: {})", prefix, match_list.join(", ")),
238 })
239 }
240 }
241 }
242
243 /// Resolve a sequence number to a hash.
244 fn resolve_sequence(&self, repo: &Repository, view_name: &str, seq: u64) -> CliResult<Hash> {

Callers 1

resolve_identifierMethod · 0.80

Calls 6

iter_changesMethod · 0.45
to_base32Method · 0.45
pushMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected