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

Method find_by_hash

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

Find a change by hash prefix.

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

Source from the content-addressed store, hash-verified

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