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

Function hex_decode_bytes

atomic-repository/src/repository/adoption.rs:3211–3235  ·  view source on GitHub ↗
(hex: &str)

Source from the content-addressed store, hash-verified

3209}
3210
3211fn hex_decode_bytes(hex: &str) -> Result<Vec<u8>, RepositoryError> {
3212 if !hex.len().is_multiple_of(2) || !hex.bytes().all(|byte| byte.is_ascii_hexdigit()) {
3213 return Err(RepositoryError::InvalidRepository {
3214 reason: format!("'{hex}' is not a hex Git object id"),
3215 });
3216 }
3217 let mut bytes = Vec::with_capacity(hex.len() / 2);
3218 let byte_values = hex.as_bytes();
3219 for pair in byte_values.chunks(2) {
3220 let high =
3221 (pair[0] as char)
3222 .to_digit(16)
3223 .ok_or_else(|| RepositoryError::InvalidRepository {
3224 reason: format!("'{hex}' is not a hex Git object id"),
3225 })?;
3226 let low =
3227 (pair[1] as char)
3228 .to_digit(16)
3229 .ok_or_else(|| RepositoryError::InvalidRepository {
3230 reason: format!("'{hex}' is not a hex Git object id"),
3231 })?;
3232 bytes.push(((high << 4) | low) as u8);
3233 }
3234 Ok(bytes)
3235}
3236
3237fn walk_unexplained_worktree(
3238 root: &std::path::Path,

Callers 3

checkpoint_facts_bytesFunction · 0.85
git_object_id_from_hexFunction · 0.85

Calls 5

lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45
as_bytesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected