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

Method find_by_hash

atomic-cli/src/commands/revise.rs:329–353  ·  view source on GitHub ↗

Find a change by hash prefix.

(&self, repo: &Repository, hash_str: &str)

Source from the content-addressed store, hash-verified

327
328 /// Find a change by hash prefix.
329 fn find_by_hash(&self, repo: &Repository, hash_str: &str) -> CliResult<u64> {
330 // Get history and search for matching hash
331 let history = repo
332 .log(HistoryOptions::default())
333 .map_err(CliError::Repository)?;
334
335 let hash_lower = hash_str.to_lowercase();
336 let mut found: Option<u64> = None;
337
338 for entry in history {
339 let entry_hash = entry.hash.to_base32().to_lowercase();
340 if entry_hash.starts_with(&hash_lower) {
341 if found.is_some() {
342 return Err(CliError::AmbiguousHash {
343 hash: hash_str.to_string(),
344 });
345 }
346 found = Some(entry.sequence);
347 }
348 }
349
350 found.ok_or_else(|| CliError::ChangeNotFound {
351 hash: hash_str.to_string(),
352 })
353 }
354
355 /// Get the message for the revised change.
356 fn get_message(&self, original_message: &str) -> CliResult<String> {

Callers 1

resolve_referenceMethod · 0.45

Calls 2

logMethod · 0.80
to_base32Method · 0.45

Tested by

no test coverage detected