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

Function tree_holds_bytes

atomic-cli/src/commands/git/shadow.rs:2095–2114  ·  view source on GitHub ↗

Whether `tree` holds exactly `bytes`: at `path`, or — after a rename of the marker-bearing file — as the same blob anywhere in the tree. A tree or gitlink entry at `path` is not a blob and does not count.

(git: &GitRepository, tree: &git2::Tree<'_>, path: &str, bytes: &[u8])

Source from the content-addressed store, hash-verified

2093/// the marker-bearing file — as the same blob anywhere in the tree. A tree
2094/// or gitlink entry at `path` is not a blob and does not count.
2095fn tree_holds_bytes(git: &GitRepository, tree: &git2::Tree<'_>, path: &str, bytes: &[u8]) -> bool {
2096 let Ok(blob_oid) = git2::Oid::hash_object(git2::ObjectType::Blob, bytes) else {
2097 return false;
2098 };
2099 let at_path = tree.get_path(Path::new(path)).ok().is_some_and(|entry| {
2100 entry.kind() == Some(git2::ObjectType::Blob) && entry.id() == blob_oid
2101 });
2102 if at_path {
2103 return true;
2104 }
2105 let mut found = false;
2106 let _ = tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| {
2107 if entry.kind() == Some(git2::ObjectType::Blob) && entry.id() == blob_oid {
2108 found = true;
2109 return git2::TreeWalkResult::Abort;
2110 }
2111 git2::TreeWalkResult::Ok
2112 });
2113 found
2114}
2115
2116fn write_project_tree(git: &GitRepository, project: &ProjectTree) -> CliResult<git2::Oid> {
2117 if project.git.algorithm != GitHashAlgorithm::Sha1 {

Callers 1

refuse_conflict_markersFunction · 0.85

Calls 5

okMethod · 0.45
get_pathMethod · 0.45
kindMethod · 0.45
idMethod · 0.45
walkMethod · 0.45

Tested by

no test coverage detected