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

Method find_by_hash

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

Find a change by hash prefix.

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

Source from the content-addressed store, hash-verified

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

Callers 1

resolve_referenceMethod · 0.45

Calls 3

logMethod · 0.45
viewMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected