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

Method find_by_git_sha_prefix

atomic-core/src/pristine/txn/read.rs:2275–2295  ·  view source on GitHub ↗
(&self, prefix: &str)

Source from the content-addressed store, hash-verified

2273 }
2274
2275 fn find_by_git_sha_prefix(&self, prefix: &str) -> PristineResult<Option<NodeId>> {
2276 let table = match self.txn.open_table(GIT_SHA_INDEX) {
2277 Ok(t) => t,
2278 Err(redb::TableError::TableDoesNotExist(_)) => return Ok(None),
2279 Err(e) => return Err(PristineError::from(e)),
2280 };
2281 // Range scan: prefix to prefix + "g" (one past hex range 0-f)
2282 let upper = format!("{}g", prefix);
2283 let mut matches = Vec::new();
2284 for item in table.range(prefix..upper.as_str())? {
2285 let (key, value) = item?;
2286 matches.push((key.value().to_string(), NodeId::new(value.value())));
2287 if matches.len() > 1 {
2288 return Err(PristineError::AmbiguousPrefix {
2289 prefix: prefix.to_string(),
2290 matches: matches.iter().map(|(k, _)| k.clone()).collect(),
2291 });
2292 }
2293 }
2294 Ok(matches.into_iter().next().map(|(_, id)| id))
2295 }
2296}
2297
2298#[cfg(test)]

Callers

nothing calls this directly

Calls 8

rangeMethod · 0.80
as_strMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected