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

Method find_by_hash

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

Find a change by hash prefix.

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

Source from the content-addressed store, hash-verified

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