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

Function git_tree_entry

atomic-cli/src/commands/git/parallel.rs:9628–9654  ·  view source on GitHub ↗

Look up raw Git path components without routing them through host paths. Git trees can contain names (including non-UTF-8 bytes) that the host filesystem cannot represent. Their repository identities must still be decoded exactly for blob, gitlink, existence, and mode lookups.

(
    git_repo: &GitRepository,
    tree: &Tree<'_>,
    path: &str,
)

Source from the content-addressed store, hash-verified

9626/// filesystem cannot represent. Their repository identities must still be
9627/// decoded exactly for blob, gitlink, existence, and mode lookups.
9628fn git_tree_entry(
9629 git_repo: &GitRepository,
9630 tree: &Tree<'_>,
9631 path: &str,
9632) -> CliResult<git2::TreeEntry<'static>> {
9633 let raw = atomic_repository::unescape_repo_path(path)
9634 .map_err(|error| git_error(format!("invalid encoded Git path '{path}': {error}")))?;
9635 let mut components = raw.split(|byte| *byte == b'/').peekable();
9636 let mut current = tree.clone();
9637 while let Some(component) = components.next() {
9638 if component.is_empty() || component.contains(&0) {
9639 return Err(git_error(format!("invalid Git tree path '{path}'")));
9640 }
9641 let entry = current
9642 .get_name_bytes(component)
9643 .ok_or_else(|| git_error(format!("Path not found in tree: '{path}'")))?;
9644 if components.peek().is_none() {
9645 return Ok(entry.to_owned());
9646 }
9647 let subtree_id = entry.id();
9648 drop(entry);
9649 current = git_repo
9650 .find_tree(subtree_id)
9651 .map_err(|error| git_error(format!("cannot read Git subtree for '{path}': {error}")))?;
9652 }
9653 Err(git_error(format!("invalid empty Git tree path '{path}'")))
9654}
9655
9656fn get_file_content(git_repo: &GitRepository, tree: &Tree, path: &str) -> CliResult<Vec<u8>> {
9657 // CB-9C path fidelity: the String identity is the reversible escape of

Callers 4

parse_diff_filesFunction · 0.85
git_mode_atFunction · 0.85
tree_entry_existsFunction · 0.85
get_file_contentFunction · 0.85

Calls 9

unescape_repo_pathFunction · 0.85
is_noneMethod · 0.80
git_errorFunction · 0.70
cloneMethod · 0.45
nextMethod · 0.45
is_emptyMethod · 0.45
containsMethod · 0.45
peekMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected