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

Function resolve_change

atomic-cli/src/commands/unrecord.rs:155–182  ·  view source on GitHub ↗
(repo: &Repository, prefix: &str)

Source from the content-addressed store, hash-verified

153}
154
155fn resolve_change(repo: &Repository, prefix: &str) -> CliResult<Hash> {
156 // Validate input shape first for a precise error — the shared resolver
157 // treats malformed input as "no match".
158 let prefix = prefix.to_ascii_uppercase();
159 if prefix.is_empty()
160 || prefix.len() > 52
161 || !prefix
162 .bytes()
163 .all(|b| b.is_ascii_uppercase() || (b'2'..=b'7').contains(&b))
164 {
165 return Err(CliError::InvalidArgument {
166 message: "Expected a Base32 change hash or a non-empty unique prefix".into(),
167 });
168 }
169
170 // The repository's shared, case-insensitive prefix resolver (the same
171 // one `atomic insert` uses) matches against the whole change store, so a
172 // hash that exists only on another view still resolves here and then
173 // hits the repository's explicit membership guard in `unrecord`.
174 match repo.find_change_by_prefix(&prefix) {
175 Ok(Some(hash)) => Ok(hash),
176 Ok(None) => Err(CliError::ChangeNotFound { hash: prefix }),
177 Err(RepositoryError::AmbiguousHash { prefix, matches }) => Err(CliError::AmbiguousHash {
178 hash: format!("{prefix} (matches: {})", matches.join(", ")),
179 }),
180 Err(e) => Err(CliError::Internal(anyhow::anyhow!("{e}"))),
181 }
182}
183
184#[cfg(test)]
185mod tests {

Callers 1

runMethod · 0.85

Calls 6

find_change_by_prefixMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected