Locate a subtree by trace-relative path inside the tree at `sha` and run `f` against it. Returns `Ok(missing)` when the path isn't there (or isn't a tree) — callers pick a sensible default for that case.
(
root: &Path,
sha: &str,
rel: &str,
missing: R,
f: impl FnOnce(&Repository, &git2::Tree<'_>) -> Result<R>,
)
| 253 | /// `f` against it. Returns `Ok(missing)` when the path isn't there (or isn't |
| 254 | /// a tree) — callers pick a sensible default for that case. |
| 255 | fn with_subtree_at<R>( |
| 256 | root: &Path, |
| 257 | sha: &str, |
| 258 | rel: &str, |
| 259 | missing: R, |
| 260 | f: impl FnOnce(&Repository, &git2::Tree<'_>) -> Result<R>, |
| 261 | ) -> Result<R> { |
| 262 | let repo = open(root)?; |
| 263 | let translated = translate(&repo, root, rel); |
| 264 | let oid = git2::Oid::from_str(sha).context("invalid commit sha")?; |
| 265 | let commit = repo |
| 266 | .find_commit(oid) |
| 267 | .with_context(|| format!("commit {} not found", sha))?; |
| 268 | let tree = commit.tree()?; |
| 269 | let entry = match tree.get_path(Path::new(&translated)) { |
| 270 | Ok(e) => e, |
| 271 | Err(_) => return Ok(missing), |
| 272 | }; |
| 273 | let object = entry.to_object(&repo)?; |
| 274 | let Some(subtree) = object.as_tree() else { |
| 275 | return Ok(missing); |
| 276 | }; |
| 277 | f(&repo, subtree) |
| 278 | } |
| 279 | |
| 280 | /// For every leaf file under `dir_rel` in the tree at `sha`, return |
| 281 | /// `(filename, blob bytes)`. Reads are batched against a single repo open; |
no test coverage detected
searching dependent graphs…