MCPcopy Create free account
hub / github.com/AIScientists-Dev/Flowtrace / with_subtree_at

Function with_subtree_at

crates/flowtrace-cli/src/git.rs:255–278  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

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.
255fn 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;

Callers 2

list_dir_blobs_atFunction · 0.85
list_run_step_files_atFunction · 0.85

Calls 2

openFunction · 0.85
translateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…