Repository navigation
perf(commit): skip the second staging pass when no pre-commit hook ran - #4540
Merged
Merged
Conversation
Since #4520, every commit path (`wt step commit`, `wt step squash`, `wt merge`) stages before and after the pre-commit hooks. The second pass exists so a formatter hook's edits land in the commit, but it ran whenever hooks were enabled, including the common case where no pre-commit hook is configured. Each extra pass repeats the untracked-file `git status` and `git add -A`, a full worktree scan on a large repo. `execute_hook` already reports whether any hook ran; restage only then. `test_commit_stages_once_without_pre_commit_hook` counts the untracked-file scans in the `-vv` trace for `wt merge` and `wt step commit` with no hook configured; it saw two before this change.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When no pre-commit hook is configured,
wt step commit,wt step squashandwt mergenow stage once instead of twice. Before this change, each of them ran an extra untracked-filegit statusandgit add -Afor nothing. On a large repo, each of those is a full worktree scan.#4520 made every commit path stage before and after the pre-commit hooks. The pass after the hooks exists so a formatter hook's edits land in the commit. It was gated on hooks being enabled, not on any hook running.
execute_hookalready returns whether a hook ran, so the secondauto_stagenow runs only then. When a hook does run, both passes happen as before.The new
test_commit_stages_once_without_pre_commit_hookcoverswt mergeandwt step commitwith no hook configured. It counts the untracked-file scans in the-vvtrace: one with this change, two without it. The existing #4520 tests cover the case where a hook runs and still pass.Locally, the clippy, doc and doctest steps of the pre-merge gate passed. Seven tests failed with and without this change, so the sandbox causes them: it blocks Unix sockets (the non-regular-file and fsmonitor tests) and lacks PowerShell and commit signing.