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

Function tree_holds_bytes

atomic-cli/src/commands/git/shadow.rs:2283–2302  ·  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

2281/// the marker-bearing file — as the same blob anywhere in the tree. A tree
2282/// or gitlink entry at `path` is not a blob and does not count.
2283fn tree_holds_bytes(git: &GitRepository, tree: &git2::Tree<'_>, path: &str, bytes: &[u8]) -> bool {
2284 let Ok(blob_oid) = git2::Oid::hash_object(git2::ObjectType::Blob, bytes) else {
2285 return false;
2286 };
2287 let at_path = tree.get_path(Path::new(path)).ok().is_some_and(|entry| {
2288 entry.kind() == Some(git2::ObjectType::Blob) && entry.id() == blob_oid
2289 });
2290 if at_path {
2291 return true;
2292 }
2293 let mut found = false;
2294 let _ = tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| {
2295 if entry.kind() == Some(git2::ObjectType::Blob) && entry.id() == blob_oid {
2296 found = true;
2297 return git2::TreeWalkResult::Abort;
2298 }
2299 git2::TreeWalkResult::Ok
2300 });
2301 found
2302}
2303
2304fn write_project_tree(git: &GitRepository, project: &ProjectTree) -> CliResult<git2::Oid> {
2305 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