Skip to content

refactor(core): combine git discovery queries#36321

Merged
kitlangton merged 2 commits into
v2from
git-discovery
Jul 10, 2026
Merged

refactor(core): combine git discovery queries#36321
kitlangton merged 2 commits into
v2from
git-discovery

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Summary

  • combine Git repository discovery metadata into one git rev-parse subprocess
  • preserve discovery when Git directory metadata is available but the repository has no work tree
  • add live coverage for the worktree-less fallback

Context

After #36290 removed eager Snapshot discovery from Location acquisition, Git discovery remained a smaller measured first-use cost. Git.repo.discover() previously launched three sequential subprocesses after locating .git:

git rev-parse --show-toplevel
git rev-parse --git-dir
git rev-parse --git-common-dir

This PR asks Git for the same metadata in one process:

git rev-parse --git-dir --git-common-dir --show-toplevel

The required Git and common directories are emitted first. If --show-toplevel fails because the repository has no work tree, discovery retains the previous behavior by using the discovered .git parent as worktree. Discovery still returns undefined when the required directory fields are unavailable.

Benchmark

An alternating 20-run benchmark executed discovery metadata queries concurrently across five repositories. It used three warmups and compared the previous three-process sequence with the combined command in alternating order.

Operation Median Spread
Three sequential queries 33.2 ms 31.2-35.3 ms
One combined query 11.5 ms 10.9-12.7 ms

The combined query reduced the measured batch median by 65%. An earlier run before rebasing measured 23.3 ms → 12.2 ms (-48%), so the direction is durable across both runs.

This deliberately does not change the preceding filesystem ascent or add cross-call discovery caching. Those are separate behaviors and were not needed to test the subprocess-count hypothesis.

Compatibility

  • normal repositories retain canonical worktree, Git directory, and common directory resolution
  • linked worktrees retain distinct Git directories and shared common directories
  • repositories whose .git metadata is present but whose work tree is disabled retain the previous cwd worktree fallback
  • failed required Git/common-directory discovery still returns undefined

Verification

  • bun typecheck from packages/core: passed
  • bun run test test/git.test.ts test/snapshot.test.ts from packages/core: 10 passed
  • push-hook repository typecheck: 31 packages passed

Follow-up to #36285 and #36290.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant