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:2164–2184  ·  view source on GitHub ↗
(&self, prefix: &str)

Source from the content-addressed store, hash-verified

2162 }
2163
2164 fn find_by_git_sha_prefix(&self, prefix: &str) -> PristineResult<Option<NodeId>> {
2165 let table = match self.txn.open_table(GIT_SHA_INDEX) {
2166 Ok(t) => t,
2167 Err(redb::TableError::TableDoesNotExist(_)) => return Ok(None),
2168 Err(e) => return Err(PristineError::from(e)),
2169 };
2170 // Range scan: prefix to prefix + "g" (one past hex range 0-f)
2171 let upper = format!("{}g", prefix);
2172 let mut matches = Vec::new();
2173 for item in table.range(prefix..upper.as_str())? {
2174 let (key, value) = item?;
2175 matches.push((key.value().to_string(), NodeId::new(value.value())));
2176 if matches.len() > 1 {
2177 return Err(PristineError::AmbiguousPrefix {
2178 prefix: prefix.to_string(),
2179 matches: matches.iter().map(|(k, _)| k.clone()).collect(),
2180 });
2181 }
2182 }
2183 Ok(matches.into_iter().next().map(|(_, id)| id))
2184 }
2185}
2186
2187#[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