diff --git a/crates/twigpine-node/src/git/visibility_pack.rs b/crates/twigpine-node/src/git/visibility_pack.rs index 2da866efb..a509cc6af 100644 --- a/crates/twigpine-node/src/git/visibility_pack.rs +++ b/crates/twigpine-node/src/git/visibility_pack.rs @@ -944,7 +944,22 @@ fn walk_tree_oids_inner( } Ok(()) } -fn blob_paths(repo_path: &Path, git_bin: &str, timeout: Duration) -> Result> { +fn blob_paths(repo_path: &Path, git_bin: &str, timeout: Duration) -> Result> { + let deadline = Instant::now() + timeout; + let mut out = object_paths(repo_path, git_bin, deadline, false)?.blobs; + let mut budget = WalkBudget::unbounded(); + let nc = non_commit_ref_sets(repo_path, git_bin, deadline, &mut budget)?; + out.extend(nc.blobs); + out.extend(nc.trees); + Ok(out.into_iter().collect()) +} + +#[cfg(test)] +fn blob_paths_ls_tree( + repo_path: &Path, + git_bin: &str, + timeout: Duration, +) -> Result> { // One deadline spans the whole walk (the HEAD probe, rev-list, every // per-commit ls-tree, and the for-each-ref phase 2), so a slow or hung walk // is bounded as a unit rather than granting each git child a fresh timeout. @@ -1724,6 +1739,7 @@ fn pair_decision( /// tree (#173 P2). `run_bounded_git` drains stdout concurrently with the stdin /// write, so a large history cannot deadlock the pipes. A commit whose root tree git /// cannot resolve fails the pass (bail), failing closed. +#[cfg(test)] fn root_tree_pairs( repo_path: &Path, git_bin: &str, @@ -1760,13 +1776,9 @@ fn root_tree_pairs( /// `replication_withheld_set`: a blob-only set handed to [`replicable_objects`] /// reintroduces #172 (withheld trees pin to public IPFS). /// -/// Strict where [`tree_paths`] is lenient. This feeds a withheld filter, so -/// absence means replicate; a missed reachable tree would leak. The walk -/// therefore matches [`blob_paths`]: [`assert_all_refs_are_commits`] first, then -/// a failing `rev-list --all [HEAD]` is an error, then [`object_paths`] (already -/// fail-closed on ls-tree / non-UTF-8) plus [`root_tree_pairs`]. [`tree_paths`] -/// stays the lenient allow-list walk for GET /ipfs/{cid} and the full-scan -/// allowed-tree set, where absence withholds. +/// This feeds a withheld filter, so absence means replicate; a missed reachable +/// tree would leak. The walk requires [`assert_all_refs_are_commits`] first, then +/// [`object_paths`] (fail-closed on Git errors or non-UTF-8 paths). pub fn withheld_object_oids_bounded( repo_path: &Path, git_bin: &str, @@ -1778,31 +1790,8 @@ pub fn withheld_object_oids_bounded( ) -> Result> { let deadline = Instant::now() + timeout; assert_all_refs_are_commits(repo_path, git_bin, deadline)?; - let head_resolves = run_bounded_git( - git_bin, - &["rev-parse", "--verify", "HEAD"], - repo_path, - b"", - deadline, - ) - .is_ok(); - let mut rev_args = vec!["rev-list", "--all"]; - if head_resolves { - rev_args.push("HEAD"); - } - let commits_out = run_bounded_git(git_bin, &rev_args, repo_path, b"", deadline)?; - let commits: Vec = String::from_utf8_lossy(&commits_out) - .lines() - .map(|l| l.trim().to_string()) - .filter(|l| !l.is_empty()) - .collect(); - let triples = object_paths(repo_path, git_bin, &commits, deadline)?; - let mut pairs: Vec<(String, String)> = triples - .into_iter() - .filter(|(_, _, kind)| kind == "blob" || kind == "tree") - .map(|(oid, path, _)| (oid, path)) - .collect(); - pairs.extend(root_tree_pairs(repo_path, git_bin, &commits, deadline)?); + let history = object_paths(repo_path, git_bin, deadline, true)?; + let pairs: Vec<_> = history.blobs.into_iter().chain(history.trees).collect(); Ok(withheld_from_pairs( &pairs, rules, is_public, owner_did, caller, )) @@ -2011,6 +2000,7 @@ pub fn allowed_blob_set_for_caller_bounded( /// enumerates non-commit ref targets and inserts them with empty path /// (round-3 fix for the annotated-tag-of-blob leak; the previous `assert_all_refs_are_commits` /// guard was removed in commit 91d0578, leaving that path fail-open). +#[cfg(test)] fn reachable_commit_oids( repo_path: &Path, git_bin: &str, @@ -2039,20 +2029,210 @@ fn reachable_commit_oids( .collect()) } +#[derive(Default)] +struct HistoryPaths { + blobs: HashSet, + trees: HashSet, + #[cfg(test)] + gitlinks: HashSet, +} + +enum DiffKind { + Deleted, + Blob, + Tree, + Gitlink, +} + +fn full_oid(oid: &str) -> bool { + matches!(oid.len(), 40 | 64) && oid.bytes().all(|b| b.is_ascii_hexdigit()) +} + +#[derive(Default)] +struct RawHistory { + paths: HistoryPaths, + first_parents: HashMap, + pending_path: Option<(DiffKind, String)>, + partial_field: Vec, +} + +impl RawHistory { + fn field(&mut self, bytes: &[u8], include_trees: bool) -> Result<()> { + let field = std::str::from_utf8(bytes).context("git log --raw returned non-UTF-8 data")?; + if let Some((kind, oid)) = self.pending_path.take() { + anyhow::ensure!(!field.is_empty(), "git log --raw returned an empty path"); + match kind { + DiffKind::Blob => self.paths.blobs.insert((oid, format!("/{field}"))), + DiffKind::Tree if include_trees => { + self.paths.trees.insert((oid, format!("/{field}"))) + } + #[cfg(test)] + DiffKind::Gitlink if include_trees => { + self.paths.gitlinks.insert((oid, format!("/{field}"))) + } + _ => false, + }; + } else if let Some(header) = field.strip_prefix('R') { + let (commit, parents_and_tree) = + header.split_once(' ').context("invalid commit header")?; + let (parents, tree) = parents_and_tree + .rsplit_once(' ') + .context("invalid commit header")?; + let first_parent = parents.split(' ').next().unwrap_or_default(); + anyhow::ensure!( + full_oid(commit) + && full_oid(tree) + && (first_parent.is_empty() || full_oid(first_parent)), + "invalid commit header from git log --raw" + ); + self.first_parents + .insert(commit.to_owned(), first_parent.to_owned()); + if include_trees { + self.paths.trees.insert((tree.to_owned(), "/".to_owned())); + } + } else { + // Git inserts a LF between the pretty header and its first raw record. + let meta = field.strip_prefix('\n').unwrap_or(field); + let meta = meta + .strip_prefix(':') + .context("invalid git log --raw record")?; + let mut fields = meta.split(' '); + let (Some(_), Some(mode), Some(old_oid), Some(oid), Some(status), None) = ( + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + fields.next(), + ) else { + anyhow::bail!("invalid git log --raw metadata"); + }; + anyhow::ensure!( + full_oid(old_oid) && full_oid(oid) && old_oid.len() == oid.len(), + "invalid object ID from git log --raw" + ); + let kind = match (status, mode) { + ("D", "000000") => DiffKind::Deleted, + ("A" | "M" | "T", "100644" | "100755" | "120000") => DiffKind::Blob, + ("A" | "M" | "T", "040000") => DiffKind::Tree, + ("A" | "M" | "T", "160000") => DiffKind::Gitlink, + _ => anyhow::bail!("unexpected status or mode from git log --raw: {status} {mode}"), + }; + self.pending_path = Some((kind, oid.to_owned())); + } + Ok(()) + } + + fn chunk(&mut self, chunk: &[u8], include_trees: bool) -> Result<()> { + let mut partial = std::mem::take(&mut self.partial_field); + for field in chunk.split_inclusive(|&byte| byte == 0) { + if let Some(field) = field.strip_suffix(&[0]) { + if partial.is_empty() { + self.field(field, include_trees)?; + } else { + partial.extend_from_slice(field); + self.field(&partial, include_trees)?; + partial.clear(); + } + } else { + partial.extend_from_slice(field); + } + } + self.partial_field = partial; + Ok(()) + } + + fn finish(self) -> Result { + anyhow::ensure!( + self.pending_path.is_none() && self.partial_field.is_empty(), + "git log --raw returned a partial record" + ); + // Replace refs or grafts can create a cycle in effective history. No diff + // would report paths that are unchanged around that cycle. + let mut rooted = HashSet::new(); + let mut chain = HashSet::new(); + for mut oid in self.first_parents.keys().map(String::as_str) { + while !oid.is_empty() && !rooted.contains(oid) { + anyhow::ensure!(chain.insert(oid), "cyclic first-parent history"); + oid = self + .first_parents + .get(oid) + .context("git log --raw omitted a first parent")?; + } + rooted.extend(chain.drain()); + } + Ok(self.paths) + } +} + +/// Walk all refs and detached HEAD. Every path/object pair is either new relative +/// to the first parent, or already exists in that parent's snapshot. Diff merges +/// against the first parent *without* restricting traversal to first parents, so +/// merge resolutions and pairs exclusive to a side branch are both covered. +/// Roots (including shallow boundaries) diff against the empty tree. +fn object_paths( + repo_path: &Path, + git_bin: &str, + deadline: Instant, + include_trees: bool, +) -> Result { + let mut args = vec![ + "log", + "--all", + "--raw", + "-r", + "-z", + "--root", + "--format=tformat:R%H %P %T", + "--no-abbrev", + "--diff-merges=first-parent", + "--no-renames", + "--ignore-submodules=none", + "--no-relative", + "--no-follow", + "--no-ext-diff", + "--no-textconv", + "--no-decorate", + "--no-notes", + "--no-show-signature", + "--no-color", + ]; + if include_trees { + args.push("-t"); + } + args.push("--"); + + let mut raw = RawHistory::default(); + let mut parse_result = Ok(()); + let (status, stderr, _) = + run_bounded_git_streaming(git_bin, &args, repo_path, b"", deadline, &mut |chunk| { + parse_result = raw.chunk(chunk, include_trees); + parse_result.is_ok() + })?; + parse_result?; + anyhow::ensure!( + status.success(), + "git log --raw failed: {}", + String::from_utf8_lossy(&stderr) + ); + raw.finish() +} + /// Every `(oid, "/repo/relative/path", kind)` triple reachable from the given /// `commits` — the shared ls-tree seam the tree walk filters (`kind == "tree"`). /// One bounded `git ls-tree -rzt` per commit under the caller's shared `deadline`: /// `-rzt` is byte-identical to `-rz` for blob records and additionally emits the /// tree object for each directory at its own path. `kind` is git's object-type /// string ("blob", "tree", or "commit" for a gitlink). The commit's ROOT tree is -/// not emitted by `ls-tree` (it lists entries *under* a tree); `tree_paths` adds -/// it. Triples are de-duplicated across commits and paths carry a leading "/" to +/// not emitted by `ls-tree` (it lists entries *under* a tree); [`root_tree_pairs`] +/// adds it. Triples are de-duplicated across commits and paths carry a leading "/" to /// match the glob form of visibility rules ("/secret/**"). /// /// Fails closed: if any tree walk fails — or a path is not valid UTF-8 — it /// returns an error so the caller aborts rather than producing a partial /// (under-withheld) set. -fn object_paths( +#[cfg(test)] +fn object_paths_ls_tree( repo_path: &Path, git_bin: &str, commits: &[String], @@ -2248,34 +2428,6 @@ fn tree_structurally_safe( Ok(true) } -/// Every `(tree_oid, "/path")` pair reachable in `repo_path`: the `kind == "tree"` -/// slice of [`object_paths`] (subtree trees at their directory paths) PLUS every -/// reachable commit's root tree at "/" (see [`root_tree_pairs`]). Computes the -/// reachable-commit set ONCE (leniently, see [`reachable_commit_oids`]; the tree -/// allowed-set feeds the `/ipfs/{cid}` tree gate AND the full-scan pin allow-list, -/// where absence = fail-closed) and drives both the ls-tree walk and the root-tree -/// pass from it, so the two cannot diverge and neither re-enumerates. The tree analog -/// of [`blob_paths`], bounded by the same shared `deadline`. Not for a withheld -/// filter: that path is [`withheld_object_oids_bounded`]. -fn tree_paths( - repo_path: &Path, - git_bin: &str, - deadline: Instant, -) -> Result> { - let commits = reachable_commit_oids(repo_path, git_bin, deadline)?; - // Subtree trees at their directory paths; the root tree is - // enumerated separately via `root_tree_oids` so the structural - // post-pass can apply without overlapping with the empty-path - // cat-file catch-all sentinel (#218 review P1b). - let mut out: HashSet<(String, String)> = HashSet::new(); - for (oid, path, kind) in object_paths(repo_path, git_bin, &commits, deadline)? { - if kind == "tree" { - out.insert((oid, path)); - } - } - Ok(out) -} - /// Reachable tree OIDs that visibility ALLOWS `caller` at some path — the tree /// analog of [`allowed_blob_set_for_caller`]. `GET /ipfs/{cid}` gates tree objects /// with this so the CID surface matches `get_tree`: a tree reachable only at a @@ -2305,8 +2457,7 @@ pub fn allowed_tree_set_for_caller( } /// [`allowed_tree_set_for_caller`] with an injectable `git_bin` and walk `timeout`, -/// for the `GET /ipfs/{cid}` tree gate. One deadline spans the whole walk (the HEAD -/// probe, rev-list, every per-commit ls-tree, and the root-tree pass), matching +/// for the `GET /ipfs/{cid}` tree gate. One deadline spans the whole walk, matching /// `blob_paths`, so a slow or hung walk is bounded as a unit while the handler holds /// its /ipfs walk permit (#174 F5). pub fn allowed_tree_set_for_caller_bounded( @@ -2330,7 +2481,7 @@ pub fn allowed_tree_set_for_caller_bounded( // on cycles and on the same tree reachable at multiple paths // (the "blob reachable at any allowed path" rule, applied to // trees). - let tree_pairs = tree_paths(repo_path, git_bin, deadline)?; + let tree_pairs = object_paths(repo_path, git_bin, deadline, true)?.trees; let ctx = TreeCheckCtx { repo_path, git_bin, @@ -2341,32 +2492,10 @@ pub fn allowed_tree_set_for_caller_bounded( }; let mut admitted: HashSet = HashSet::new(); for (oid, path) in &tree_pairs { - // `tree_paths` only emits non-empty paths (root trees are - // enumerated below), so the empty-path case is not reachable - // here. P3 (reviewer round 9): the previous comment described - // a caller-aware empty-path carve-out that the surrounding - // code never produced, so the call degenerated to the same - // decision `visibility_check` would make. Reverting the - // routing through `pair_decision` removes the dead code and - // its comment. `visibility_check` is still the policy surface - // for the root tree pass below. if visibility_check(rules, is_public, owner_did, caller, path) == Decision::Allow { tree_structurally_safe(&ctx, oid, path, &mut admitted, deadline)?; } } - // Root trees of reachable commits: they have no path in - // `tree_paths` (ls-tree emits descendants only), so evaluate - // them at "/" — the root tree is admitted iff every direct - // entry is safe at the root and (for tree entries) the child - // tree is itself structurally safe. The check is recursive, so - // a denied subtree propagates up to the root. - let commits = reachable_commit_oids(repo_path, git_bin, deadline)?; - for root_oid in root_tree_oids(repo_path, git_bin, &commits, deadline)? { - if visibility_check(rules, is_public, owner_did, caller, "/") != Decision::Allow { - continue; - } - tree_structurally_safe(&ctx, &root_oid, "/", &mut admitted, deadline)?; - } Ok(admitted) } @@ -3005,7 +3134,7 @@ mod tests { /// #174 U3: the withheld-blob walk is bounded at the shared `blob_paths` seam, so /// a hung git child cannot pin the caller's permit past the deadline. A fake git - /// that hangs on `rev-list` must make `blob_paths` return `GitServiceTimeout` + /// that hangs on `log` must make `blob_paths` return `GitServiceTimeout` /// within the watchdog budget (not block for the child's lifetime), and the /// child's process group must be reaped (its recorded leader PID gone). Every /// caller (upload-pack serve, receive-pack replication) funnels through @@ -3016,10 +3145,10 @@ mod tests { fn blob_paths_times_out_and_reaps_a_hung_walk() { use std::time::Duration; let tmp = TempDir::new().unwrap(); - // Fast on every stage except rev-list, which records its own (group-leader) + // Fast on every stage except log, which records its own (group-leader) // PID and then hangs. `sleep 30` bounds the worst case if the watchdog is // ever broken, so a regression cannot wedge the suite for 300s. - let body = "#!/bin/sh\ncase \"$1\" in\n rev-list) echo $$ > revlist.pid ; sleep 30 ;;\n rev-parse) echo deadbeef ;;\n *) : ;;\nesac\nexit 0\n"; + let body = "#!/bin/sh\ncase \"$1\" in\n log) echo $$ > log.pid ; sleep 30 ;;\n *) : ;;\nesac\nexit 0\n"; let git_bin = write_fake_git(tmp.path(), body); // Run the walk on a thread with a short budget; the recv_timeout succeeding @@ -3032,7 +3161,7 @@ mod tests { let result = rx.recv_timeout(Duration::from_secs(10)).expect( "blob_paths must return within the watchdog budget, not hang on a stuck git child", ); - let err = result.expect_err("a hung rev-list must abort the walk with an error"); + let err = result.expect_err("a hung log must abort the walk with an error"); assert!( err.downcast_ref::() .is_some(), @@ -3044,8 +3173,8 @@ mod tests { // The recorded process-group leader must be gone: the watchdog reaps the // whole group before blob_paths returns, so no orphaned git lingers. - let pid: i32 = std::fs::read_to_string(tmp.path().join("revlist.pid")) - .expect("the fake git must have recorded its rev-list PID") + let pid: i32 = std::fs::read_to_string(tmp.path().join("log.pid")) + .expect("the fake git must have recorded its log PID") .trim() .parse() .expect("recorded PID must parse"); @@ -3573,7 +3702,7 @@ esac\n"; let deadline = Instant::now() + WALK_TIMEOUT; // The lenient enumeration; on this clean fixture it matches the strict one. let commits = reachable_commit_oids(&bare, "git", deadline).unwrap(); - let objs = object_paths(&bare, "git", &commits, deadline).unwrap(); + let objs = object_paths_ls_tree(&bare, "git", &commits, deadline).unwrap(); // Blob records survive the `-rzt` change, at their paths (unchanged). assert!(objs.contains(&(secret_oid.clone(), "/secret/b.txt".into(), "blob".into()))); @@ -3606,6 +3735,171 @@ esac\n"; ); } + #[test] + fn raw_history_matches_ls_tree_snapshots() { + let repo = TempDir::new().unwrap(); + let path = repo.path(); + let git = |args: &[&str], input: &[u8]| { + let deadline = Instant::now() + WALK_TIMEOUT; + let result = run_bounded_git("git", args, path, input, deadline).unwrap(); + String::from_utf8(result).unwrap().trim_end().to_owned() + }; + git(&["init", "--bare", "-q"], b""); + git(&["config", "user.email", "t@t"], b""); + git(&["config", "user.name", "t"], b""); + git(&["config", "diff.renames", "copies"], b""); + git(&["config", "diff.ignoreSubmodules", "all"], b""); + git(&["config", "log.showRoot", "false"], b""); + let check = || { + let deadline = Instant::now() + WALK_TIMEOUT; + let commits = reachable_commit_oids(path, "git", deadline).unwrap(); + let old = object_paths_ls_tree(path, "git", &commits, deadline).unwrap(); + let pairs = |kind: &str| -> HashSet<_> { + old.iter() + .filter(|(_, _, k)| k == kind) + .map(|(oid, path, _)| (oid.clone(), path.clone())) + .collect() + }; + let mut old_trees = pairs("tree"); + old_trees.extend(root_tree_pairs(path, "git", &commits, deadline).unwrap()); + let new = object_paths(path, "git", deadline, true).unwrap(); + assert_eq!(new.blobs, pairs("blob")); + assert_eq!(new.trees, old_trees); + assert_eq!(new.gitlinks, pairs("commit")); + let old_blobs: HashSet<_> = blob_paths_ls_tree(path, "git", WALK_TIMEOUT) + .unwrap() + .into_iter() + .collect(); + let new_blobs: HashSet<_> = blob_paths(path, "git", WALK_TIMEOUT) + .unwrap() + .into_iter() + .collect(); + assert_eq!(new_blobs, old_blobs); + }; + check(); + + let tree = |entries: &[(&str, &str, &str)]| { + let mut input = Vec::new(); + for (mode_and_kind, oid, name) in entries { + input.extend_from_slice(format!("{mode_and_kind} {oid}\t{name}\0").as_bytes()); + } + git(&["mktree", "-z"], &input) + }; + let commit = |tree: &str, parents: &[&str], message: &str| { + let mut args = vec!["commit-tree", tree, "-m", message]; + for parent in parents { + args.extend(["-p", parent]); + } + git(&args, b"") + }; + let empty = tree(&[]); + let root = commit(&empty, &[], "empty root"); + let contents = make_blob(path, b"same file before and after rename"); + let other = make_blob(path, b"side branch only"); + let resolved = make_blob(path, b"merge-only conflict resolution"); + let inner = tree(&[("100644 blob", &contents, "- café \"quote\"\n\t ")]); + let nested = tree(&[("040000 tree", &inner, "child")]); + let name = "conflict"; + let common = tree(&[ + ("040000 tree", &nested, "nested"), + ("040000 tree", &empty, "empty-dir"), + ("100644 blob", &contents, name), + ("160000 commit", &root, "submodule"), + ]); + let base = commit(&common, &[&root], "nested files and submodule"); + let left_tree = tree(&[ + ("040000 tree", &nested, "renamed"), + ("100755 blob", &contents, "executable"), + ("100644 blob", &other, name), + ("160000 commit", &base, "submodule"), + ]); + let left = commit(&left_tree, &[&base], "rename and update gitlink"); + let right_tree = tree(&[ + ("100644 blob", &other, "side-only"), + ("120000 blob", &contents, name), + ("100644 blob", &contents, "submodule"), + ]); + let right = commit(&right_tree, &[&base], "delete trees and replace gitlink"); + let merged_tree = tree(&[ + ("040000 tree", &nested, "renamed"), + ("100644 blob", &resolved, name), + ("160000 commit", &right, "submodule"), + ]); + let merge = commit( + &merged_tree, + &[&left, &right], + "resolve against both parents", + ); + let tip = commit(&merged_tree, &[&merge], "empty commit on detached HEAD"); + git(&["update-ref", "--no-deref", "HEAD", &tip], b""); + git(&["update-ref", "refs/heads/other-root", &root], b""); + check(); + + // A shallow boundary with a nonempty tree must enumerate its snapshot. + std::fs::write(path.join("shallow"), format!("{merge}\n")).unwrap(); + check(); + + // A graft can make a tree identical to its only parent forever. Refuse + // a partial inventory rather than treating the unchanged paths as absent. + std::fs::remove_file(path.join("shallow")).unwrap(); + std::fs::write(path.join("info/grafts"), format!("{tip} {tip}\n")).unwrap(); + let err = blob_paths(path, "git", WALK_TIMEOUT).unwrap_err(); + assert!(err.to_string().contains("cyclic first-parent history")); + } + + #[test] + #[ignore = "times the paired walks over the developer checkout"] + fn benchmark_visibility_history_walk() { + use std::hint::black_box; + + let repo = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + fn median_ms(mut walk: impl FnMut()) -> f64 { + walk(); + let mut samples = [Duration::ZERO; 5]; + for sample in &mut samples { + let start = Instant::now(); + walk(); + *sample = start.elapsed(); + } + samples.sort_unstable(); + samples[2].as_secs_f64() * 1_000.0 + } + + let before_blobs = median_ms(|| { + black_box(blob_paths_ls_tree(&repo, "git", WALK_TIMEOUT).unwrap()); + }); + let after_blobs = median_ms(|| { + black_box(blob_paths(&repo, "git", WALK_TIMEOUT).unwrap()); + }); + let before_objects = median_ms(|| { + let deadline = Instant::now() + WALK_TIMEOUT; + let commits = reachable_commit_oids(&repo, "git", deadline).unwrap(); + let mut pairs: Vec<_> = object_paths_ls_tree(&repo, "git", &commits, deadline) + .unwrap() + .into_iter() + .filter(|(_, _, kind)| kind == "blob" || kind == "tree") + .map(|(oid, path, _)| (oid, path)) + .collect(); + pairs.extend(root_tree_pairs(&repo, "git", &commits, deadline).unwrap()); + black_box(pairs); + }); + let after_objects = median_ms(|| { + let history = object_paths(&repo, "git", Instant::now() + WALK_TIMEOUT, true).unwrap(); + let pairs: Vec<_> = history.blobs.into_iter().chain(history.trees).collect(); + black_box(pairs); + }); + println!("| Rust walk | Before (median ms) | After (median ms) | Speedup |"); + println!("|---|---:|---:|---:|"); + println!( + "| Blob paths | {before_blobs:.2} | {after_blobs:.2} | {:.1}× |", + before_blobs / after_blobs + ); + println!( + "| Blob and tree paths | {before_objects:.2} | {after_objects:.2} | {:.1}× |", + before_objects / after_objects + ); + } + #[test] fn allowed_tree_set_gates_withheld_subtree_tree() { let (_td, bare, _s, _p) = fixture(); @@ -5891,7 +6185,7 @@ esac\n"; /// /// #218 review round 8 P2 (why this exists): the phase-2 ref tests used to /// hang the ref on `fixture()`'s `secret` blob, which is COMMITTED at - /// `secret/b.txt`. Phase 1's per-commit `ls-tree` therefore already yielded + /// `secret/b.txt`. The commit walk therefore already yields /// `(secret, "/secret/b.txt")`, the `/secret/**` rule already denied it, and /// the `withheld.contains(&secret)` assertion passed with phase 2 deleted /// outright — the tests bound nothing. A blob written straight to the object @@ -6378,7 +6672,7 @@ esac\n"; // * nested tag (tag-of-tag-of-blob) // The blob OID and tree OID are distinct so the consumers // can disambiguate. The blob is NOT committed anywhere, so - // phase 1 (`rev-list --all` + `ls-tree`) does not see it — + // the commit walk does not see it — // every entry in the `(oid, path)` set arrives through // phase 2 (`for-each-ref`) with an empty path. let td = TempDir::new().unwrap();