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

Function parse_gitlink_bytes

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

Source from the content-addressed store, hash-verified

1549}
1550
1551fn parse_gitlink_bytes(
1552 algorithm: GitHashAlgorithm,
1553 bytes: &[u8],
1554) -> Result<GitObjectId, ProjectTreeError> {
1555 let expected = match algorithm {
1556 GitHashAlgorithm::Sha1 => 40,
1557 GitHashAlgorithm::Sha256 => 64,
1558 };
1559 if bytes.len() != expected || !bytes.iter().all(u8::is_ascii_hexdigit) {
1560 return Err(ProjectTreeError::InvalidGitlink(format!(
1561 "expected {expected} hexadecimal bytes"
1562 )));
1563 }
1564 let mut decoded = Vec::with_capacity(expected / 2);
1565 for pair in bytes.as_chunks::<2>().0 {
1566 let text = std::str::from_utf8(pair).expect("ASCII hex checked");
1567 decoded.push(u8::from_str_radix(text, 16).expect("hex checked"));
1568 }
1569 GitObjectId::new(algorithm, decoded)
1570 .map_err(|error| ProjectTreeError::GitObjectId(error.to_string()))
1571}
1572
1573fn repo_error(error: impl fmt::Display) -> ProjectTreeError {
1574 ProjectTreeError::Repository(error.to_string())

Calls 5

GitObjectIdClass · 0.85
lenMethod · 0.45
allMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected