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,
)
| 9626 | /// filesystem cannot represent. Their repository identities must still be |
| 9627 | /// decoded exactly for blob, gitlink, existence, and mode lookups. |
| 9628 | fn 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 | |
| 9656 | fn 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 |
no test coverage detected