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

Source from the content-addressed store, hash-verified

3117 }
3118
3119 fn find_by_git_sha_prefix(&self, prefix: &str) -> PristineResult<Option<NodeId>> {
3120 let table = match self.txn.open_table(GIT_SHA_INDEX) {
3121 Ok(t) => t,
3122 Err(redb::TableError::TableDoesNotExist(_)) => return Ok(None),
3123 Err(e) => return Err(PristineError::from(e)),
3124 };
3125 // Range scan: prefix to prefix + "g" (one past hex range 0-f)
3126 let upper = format!("{}g", prefix);
3127 let mut matches = Vec::new();
3128 for item in table.range(prefix..upper.as_str())? {
3129 let (key, value) = item?;
3130 matches.push((key.value().to_string(), NodeId::new(value.value())));
3131 if matches.len() > 1 {
3132 return Err(PristineError::AmbiguousPrefix {
3133 prefix: prefix.to_string(),
3134 matches: matches.iter().map(|(k, _)| k.clone()).collect(),
3135 });
3136 }
3137 }
3138 Ok(matches.into_iter().next().map(|(_, id)| id))
3139 }
3140}
3141
3142#[cfg(test)]

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected