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

Function git_object_id

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

Source from the content-addressed store, hash-verified

1156}
1157
1158pub(super) fn git_object_id(
1159 algorithm: GitHashAlgorithm,
1160 kind: GitObjectKind,
1161 bytes: &[u8],
1162) -> Result<GitObjectId, ProjectTreeError> {
1163 let kind = match kind {
1164 GitObjectKind::Blob => "blob",
1165 GitObjectKind::Tree => "tree",
1166 };
1167 let header = format!("{kind} {}\0", bytes.len());
1168 let digest = match algorithm {
1169 GitHashAlgorithm::Sha1 => {
1170 let mut hasher = sha1::Sha1::new();
1171 hasher.update(header.as_bytes());
1172 hasher.update(bytes);
1173 hasher.finalize().to_vec()
1174 }
1175 GitHashAlgorithm::Sha256 => {
1176 let mut hasher = sha2::Sha256::new();
1177 hasher.update(header.as_bytes());
1178 hasher.update(bytes);
1179 hasher.finalize().to_vec()
1180 }
1181 };
1182 GitObjectId::new(algorithm, digest)
1183 .map_err(|error| ProjectTreeError::GitObjectId(error.to_string()))
1184}
1185
1186impl Repository {
1187 /// 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