Repository navigation
perf(repo): skip submodule rev-parse probe via core.worktree in bulk config - #2350
Conversation
…k config Replace the failing `git rev-parse --show-toplevel` probe in `repo_path()` with a direct read of `core.worktree` from the bulk config map populated once per command. For non-submodule repos the probe fails (roughly 5ms on healthy macOS, ~200ms on Mark's system in #2322), so removing it wins on every invocation. The new control flow (`is_bare()` → `core.worktree` → `parent(git_common_dir)`) matches git's own resolution rules: submodules have `core.worktree` set explicitly because their data lives in the parent's `.git/modules/`, normal repos leave it unset so `parent(.git)` is correct, and bare repos are caught by `is_bare()` first. The #1070 invariant (submodule path correction in `list_worktrees()`) continues to hold — verified by `test_repo_path_in_submodule` and `wt list` inside a real submodule. hyperfine A/B, 200 runs, `-N`: - `wt noop` in normal repo: 53.2ms → 48.8ms (1.09×) - `wt noop` in submodule: 62.1ms → 55.5ms (1.12×) Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch failed at 90.9% (10/11). The uncovered line is the absolute-path branch inside the core.worktree block:
return Ok(if path.is_absolute() {
path // ← this line
} else {
self.git_common_dir.join(path).normalize()
});Git writes core.worktree as a relative path for submodules (../../sub), so the existing test_repo_path_in_submodule integration test only exercises the else arm. No test sets core.worktree to an absolute path (no matches for core.worktree in tests/).
A unit test in src/git/repository/tests.rs that pre-populates the bulk config map with an absolute core.worktree (matching the pattern used by the existing parse_config_list_z_* tests) would close the gap. Happy to push one if you'd like — dismissing the approval until this is resolved.
codecov/patch failed at 90.9% — absolute-path branch uncovered (see follow-up COMMENT review)
Reviewer flagged the absolute-path arm as uncovered — git writes relative paths for submodules, so the existing integration test only exercises the else branch. Pre-populate the bulk config cache with an absolute value to cover the other arm without needing a filesystem fixture. Co-Authored-By: Claude <[email protected]>
|
Addressed in b4cefb2 — pre-populates the bulk config cache with an absolute |
…2362) ## Summary #2350 introduced a divergence for a narrow case: normal non-bare repos where a user has set `core.worktree` in global/system config. `git config --list -z` merges scopes into the bulk map, but git itself only honors `core.worktree` from **local** config for worktree discovery — so we'd return (e.g.) a stray global path as the repo root while git would return the actual worktree. Fix: when the bulk map reports `core.worktree`, delegate to `git rev-parse --show-toplevel` so git applies its own scope rules. The common case (no `core.worktree` anywhere — the vast majority of repos) still skips the subprocess entirely; that was the whole point of #2350. Submodules pay one fork back, matching pre-#2350 behavior for that minority case. Caught by Codex review of the merged #2350. ## Correctness Verified against git (all from inside `.git`): | `core.worktree` scope | `git rev-parse --show-toplevel` | Pre-fix (`#2350`) | Post-fix | |-----------------------|---------------------------------|-------------------|----------| | Not set anywhere | fails → fall through | `parent(.git)` ✓ | `parent(.git)` ✓ | | Local (submodule / user-set) | returns resolved path | wrong for global; ok for local | matches git ✓ | | Global only | fails → git ignores it | returned global value ❌ | matches git ✓ | ## Tests - New unit test `repo_path_ignores_non_local_core_worktree` — pre-populates the bulk config cache with a `core.worktree` value but leaves the on-disk `.git/config` empty, so `rev-parse --show-toplevel` fails and we fall through to `parent(.git)`. Simulates the global-only scope case. - Existing `test_repo_path_in_submodule` integration test still passes (local `core.worktree` in a real submodule). - All 1023 lib tests and the 4 submodule integration tests pass. ## Performance No regression for the common case (no `core.worktree` anywhere): still skips the subprocess. Submodules pay one fork — same as pre-#2350. Ref #2322 > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[email protected]>
Doc-only follow-up to #2350 / #2362. The docstring on `Repository::repo_path()` had grown to ~45 lines during the scope-handling fix; trimming it to ~25 without dropping any of the reasoning that would cause accidental regressions. Kept (load-bearing): - Why we anchor on `git_common_dir` (linked-worktree invariant) - The three-case resolution table - Why submodules need `core.worktree` (or someone removes the probe) - Why we delegate to `rev-parse` instead of trusting the bulk map directly (or someone re-introduces the #2350 scope bug) - The "common case skips the subprocess" perf note (or someone always probes) Trimmed: - "# Why we anchor" heading → folded into the lead-in - "(or `[includeIf]`-imported)" parenthetical - One redundant sentence restating that git ignores global `core.worktree` - Minor phrasing cleanup > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[email protected]>
Summary
Replaces the failing
git rev-parse --show-toplevelprobe inRepository::repo_path()with a direct read ofcore.worktreefrom the bulk config map. On non-submodule repos the probe fails unconditionally, costing roughly 5ms per call on healthy macOS — or ~200ms on systems with expensiveexecvelike the one reported in #2322.repo_path()fires ~2× during parent-side alias dispatch, so the win compounds.The new control flow matches git's own rules for locating the working tree:
git_common_dirlayout.gitcore.bare = truegit_common_diris the repo.git/modules/Xcore.worktreeset by git.gitparent(git_common_dir)Submodules need
core.worktreebecause their data lives in the parent's.git/modules/, so the implicitparent(.git)rule normal repos rely on would point at the wrong directory. Readingcore.worktreefrom the bulk map is git's own signal for this — norev-parsesubprocess required.Correctness
The #762 → #1070 → #1280 chain of submodule fixes established two invariants:
repo_path()must return the submodule working directory (not.git/modules/sub), andlist_worktrees()depends on that to correct git's own mis-report for submodule main worktrees. Both still hold:test_repo_path_in_submodule(integration) passes — exercisesrepo_path(),list_worktrees(), andworktree_for_branch()in a real parent/submodule setup.wt listfrom inside a real submodule at/tmp/subm-test/parent/subreports the submodule working directory, not the git data path.test_repo_path_in_submodule,test_push_{no_ff_,}with_submodule_recurse_config,test_remove_foreground_with_submodules) pass.is_bare()short-circuit; linked worktrees still fall through toparent()because the shared.gitcommon dir has nocore.worktree.Errors still propagate via
Result(fromall_config()instead of the removed subprocess), preserving the #1280 invariant.Performance
hyperfine A/B on a healthy macOS system (200 runs each,
-Nbypasses shell):wt noopin normal repowt noopin submoduleTrace confirmation:
git rev-parse --show-toplevel [.git]no longer appears inRUST_LOG=debugoutput for alias dispatch. The unrelatedrev-parse --show-toplevel [parent]fromWorkingTree::root()(legitimately successful) remains and is out of scope.benches/aliasresults were too noisy to cite confidently on my machine during this session (wt_version— which this change doesn't touch — varied ±60% between runs), but the hyperfine measurement is clean.Ref #2322