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

Method find_by_hash

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

Find a change by hash prefix.

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

Source from the content-addressed store, hash-verified

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