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

Method from_git_object_id

atomic-repository/src/git_binding/codec.rs:87–102  ·  view source on GitHub ↗

Convert from the algorithm-tagged core type.

(object_id: &GitObjectId)

Source from the content-addressed store, hash-verified

85impl GitOid {
86 /// Convert from the algorithm-tagged core type.
87 pub fn from_git_object_id(object_id: &GitObjectId) -> Result<Self, BindingEncodeError> {
88 match object_id.algorithm() {
89 GitHashAlgorithm::Sha1 => {
90 let bytes: [u8; 20] = object_id.as_bytes().try_into().map_err(|_| {
91 BindingEncodeError::OidWidth("sha1", object_id.as_bytes().len())
92 })?;
93 Ok(GitOid::Sha1(bytes))
94 }
95 GitHashAlgorithm::Sha256 => {
96 let bytes: [u8; 32] = object_id.as_bytes().try_into().map_err(|_| {
97 BindingEncodeError::OidWidth("sha256", object_id.as_bytes().len())
98 })?;
99 Ok(GitOid::Sha256(bytes))
100 }
101 }
102 }
103
104 /// Convert into the algorithm-tagged core type for Git interop.
105 pub fn to_git_object_id(&self) -> Result<GitObjectId, BindingEncodeError> {

Callers

nothing calls this directly

Calls 3

algorithmMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected