Hi there - my name's Wyatt Holden and I'm a Software Engineer at Microsoft :) I've been working with Derrick Stolee over the past few weeks on optimizing git in the Office mono-repo. We found some issues around slow checkouts on mono-repos in an automated environment:
When leaving a detached HEAD, git checkout and git switch call orphaned_commit_warning() to warn about commits that are not reachable from any existing ref or the destination HEAD. This requires enumerating refs and walking commit history, which can be expensive in large repositories.
In an internal mono-repo, Trace2 showed tree unpacking finishing approximately 12 seconds into checkout, but the process continuing for roughly another 193 seconds. A stack dump captured the main thread inside orphaned_commit_warning(), enumerating loose refs and opening ref files. Running checkout with --quiet, which bypasses this routine, reduced the observed runtime to approximately 14 seconds. However, --quiet also suppresses unrelated output.
This three-commit series adds a targeted opt-out, advertises it when the check is slow, and enables it in Scalar:
1. checkout: make orphaned commit checks configurable Add
checkout.orphanedCommitWarning , enabled by default, for both checkout
and switch. Setting it to false skips the reachability check while
retaining the previous HEAD description and normal checkout output. Add
a Trace2 region to expose the check’s duration and tests verifying that
disabling the setting bypasses the routine.
2. checkout: advise when orphaned commit checks are slow When the check
takes more than two seconds, suggest the opt-out and explain that
disabling it also removes the warning about commits left behind. Control
this advice independently through advice.checkoutOrphanedCommitWarning.
Test advice and suppression without relying on wall-clock delays.
3. scalar: disable orphaned commit checks by default Add
checkout.orphanedCommitWarning=false to Scalar’s recommended
configuration using its existing set-if-missing mechanism, preserving
explicit user settings during clone, register, and reconfigure. Document
the tradeoff and reflog recovery; rely on existing Scalar tests for
configuration-preservation behavior.Ordinary Git retains its existing default behavior. Users who disable the check lose the immediate warning about commits left behind; those commits can still be recovered through the HEAD reflog while the relevant entries and objects remain available.
Wyatt Holden (3): checkout: make orphaned commit checks configurable checkout: advise when orphaned commit checks are slow scalar: disable orphaned commit checks by default
Documentation/config/advice.adoc | 6 +++ Documentation/config/checkout.adoc | 11 +++++ Documentation/scalar.adoc | 7 +++ advice.c | 1 + advice.h | 1 + builtin/checkout.c | 31 +++++++++++++- scalar.c | 1 + t/README | 5 +++ t/t2020-checkout-detach.sh | 69 ++++++++++++++++++++++++++++++ 9 files changed, 130 insertions(+), 2 deletions(-)
base-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2264%2Fwyatt-holden%2Fwyattholden%2Fcheckout-orphaned-commit-warning-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2264/wyatt-holden/wyattholden/checkout-orphaned-commit-warning-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2264
-- gitgitgadget