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

Function git_object_id_from_hex

atomic-repository/src/repository/adoption.rs:3195–3209  ·  view source on GitHub ↗

A Git object id parsed from its hex form, algorithm-tagged by width.

(hex: &str)

Source from the content-addressed store, hash-verified

3193
3194/// A Git object id parsed from its hex form, algorithm-tagged by width.
3195fn git_object_id_from_hex(hex: &str) -> Result<GitObjectId, RepositoryError> {
3196 let bytes = hex_decode_bytes(hex)?;
3197 let algorithm = match bytes.len() {
3198 20 => atomic_core::operation::GitHashAlgorithm::Sha1,
3199 32 => atomic_core::operation::GitHashAlgorithm::Sha256,
3200 other => {
3201 return Err(RepositoryError::InvalidRepository {
3202 reason: format!("unexpected Git OID width {other} in '{hex}'"),
3203 })
3204 }
3205 };
3206 GitObjectId::new(algorithm, bytes).map_err(|error| RepositoryError::InvalidRepository {
3207 reason: error.to_string(),
3208 })
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()) {

Callers 1

checkpoint_git_stateFunction · 0.85

Calls 2

hex_decode_bytesFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected