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

Function parse_git_oid_hex

atomic-core/src/operation/mod.rs:606–621  ·  view source on GitHub ↗

Decode one full-length hex Git object id (40-char SHA-1 or 64-char SHA-256) into its tagged object id (review D3). The hex decoding is strict: the token must be entirely hex digits of exactly one supported length.

(token: &str)

Source from the content-addressed store, hash-verified

604/// strict: the token must be entirely hex digits of exactly one supported
605/// length.
606pub fn parse_git_oid_hex(token: &str) -> Option<GitObjectId> {
607 let (algorithm, width) = match token.len() {
608 40 => (GitHashAlgorithm::Sha1, 20usize),
609 64 => (GitHashAlgorithm::Sha256, 32usize),
610 _ => return None,
611 };
612 if !token.bytes().all(|byte| byte.is_ascii_hexdigit()) {
613 return None;
614 }
615 let mut bytes = Vec::with_capacity(width);
616 for index in 0..width {
617 let byte = u8::from_str_radix(&token[index * 2..index * 2 + 2], 16).ok()?;
618 bytes.push(byte);
619 }
620 GitObjectId::new(algorithm, bytes).ok()
621}
622
623/// Parse a post-rewrite event's `<old> <new>` full-OID pair (review D3).
624///

Callers 2

parse_post_rewrite_pairFunction · 0.70
post_rewrite_event_pairsFunction · 0.70

Calls 5

lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45
okMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected