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

Function git_object_id

atomic-repository/src/repository/project_tree.rs:1180–1206  ·  view source on GitHub ↗
(
    algorithm: GitHashAlgorithm,
    kind: GitObjectKind,
    bytes: &[u8],
)

Source from the content-addressed store, hash-verified

1178}
1179
1180pub(super) fn git_object_id(
1181 algorithm: GitHashAlgorithm,
1182 kind: GitObjectKind,
1183 bytes: &[u8],
1184) -> Result<GitObjectId, ProjectTreeError> {
1185 let kind = match kind {
1186 GitObjectKind::Blob => "blob",
1187 GitObjectKind::Tree => "tree",
1188 };
1189 let header = format!("{kind} {}\0", bytes.len());
1190 let digest = match algorithm {
1191 GitHashAlgorithm::Sha1 => {
1192 let mut hasher = sha1::Sha1::new();
1193 hasher.update(header.as_bytes());
1194 hasher.update(bytes);
1195 hasher.finalize().to_vec()
1196 }
1197 GitHashAlgorithm::Sha256 => {
1198 let mut hasher = sha2::Sha256::new();
1199 hasher.update(header.as_bytes());
1200 hasher.update(bytes);
1201 hasher.finalize().to_vec()
1202 }
1203 };
1204 GitObjectId::new(algorithm, digest)
1205 .map_err(|error| ProjectTreeError::GitObjectId(error.to_string()))
1206}
1207
1208impl Repository {
1209 /// Build the canonical repository manifest and Git tree from recorded view state.

Callers 7

expected_git_oidFunction · 0.70
hash_index_directoryFunction · 0.70
insert_objectMethod · 0.70
insert_sharedMethod · 0.70
parse_treeMethod · 0.70
verified_blobMethod · 0.70

Calls 4

GitObjectIdClass · 0.85
updateMethod · 0.45
as_bytesMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected