Repository navigation
Make orphaned commit checks configurable - #2264
wyatt-holden wants to merge 3 commits into
Conversation
Welcome to GitGitGadgetHi @wyatt-holden, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax: NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txtTo iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description): To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
|
There is an issue in commit 44df4e9:
|
|
There is an issue in commit 00d3fc0:
|
00d3fc0 to
8d9f70d
Compare
|
There is an issue in commit 1e3e99b:
|
|
There is an issue in commit 8d9f70d:
|
b4c882f to
76d29a1
Compare
|
/allow |
|
User wyatt-holden is now allowed to use GitGitGadget. WARNING: wyatt-holden has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use. |
|
/allow |
|
User wyatt-holden already allowed to use GitGitGadget. |
derrickstolee
left a comment
There was a problem hiding this comment.
I have some recommendations, but here are some top-level thoughts:
-
You use your
@microsoft.comemail address, but we can't use that to reply to the mailing list. Have you subscribed to the mailing list somewhere? (I use my Gmail account, have a rule to put the mailing list messages in a folder, and use Thunderbird to navigate and reply to those messages in plaintext.) -
Your cover letter could include an introduction of yourself (and I'll chime in to vouch for you). But be sure that any justification of the change also happens in the commit messages. You'll want to add
cc: gitster@pobox.comandcc: stolee@gmail.comto CC the maintainer and me. -
"In an affected Scalar-managed repository" you could say "In an internal monorepo" as this could impact a non-Scalar repo. I do wonder how much Scalar and the GVFS Protocol could have impacted this situation, but probably the repo didn't have a commit-graph file (yet) which would have sped-up this check. It might be worth spending some time to understand what exactly was slow about it: did the client use the full endpoint and thus was walking from a huge list of refs? Was it missing commits and thus downloading thousands of missing commits one-by-one? (that last one won't really impact upstream Git clients) It can be worth mentioning that this was something in an automated environment, so we didn't care about abandoning the detached HEAD commit. Users might want to know this information, but I suspect that most ignore it and aren't willing to wait for it.
-
You should mention these two commits directly (and in this format):
06b324c1d71 (status: add status.aheadbehind setting, 2019-06-18)
0a53561a622 (status: warn when a/b calculation takes too long, 2019-06-18)
One thing that is different between those two changes and your change is that git status got a --no-ahead-behind argument that is referenced by the warning, but you're only adding a config option. I think that this is the right call, but it might be worth pointing out that difference as something you know about and is open for changing if reviewers think it's important.
@derrickstolee - |
76d29a1 to
f24d401
Compare
|
/submit |
|
Error: Could not determine full name of wyatt-holden |
|
/submit |
|
Submitted as pull.2264.git.1794337920.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag WARNING: wyatt-holden has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use. |
| @@ -38,6 +38,12 @@ all advice messages. | |||
| configuration variable for how to set a given remote | |||
There was a problem hiding this comment.
Derrick Stolee wrote on the Git mailing list (how to reply to this email):
On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:
> [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" },
> + [ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING] = { "checkoutOrphanedCommitWarning" },
> [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" },
It looks like we have a slight whitespace alignment problem here.
Thanks,
-Stolee
There was a problem hiding this comment.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):
Derrick Stolee <stolee@gmail.com> writes:
> On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:
>
>> [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" },
>> + [ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING] = { "checkoutOrphanedCommitWarning" },
>> [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" },
>
> It looks like we have a slight whitespace alignment problem here.
>
> Thanks,
> -Stolee
Good eyes. What the patch aims does sound sensible to me, though.|
Derrick Stolee wrote on the Git mailing list (how to reply to this email): On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:
> 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:
Welcome, Wyatt! (I was prepared for your series.)
> 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 example shows a significant pain caused by this check, but we also
want to be able to see progress indicators over time in our logs, so
using --quiet isn't preferred, long term.
> This three-commit series adds a targeted opt-out, advertises it when the
> check is slow, and enables it in Scalar:
I did some pre-review with Wyatt (but found one nitpick in my on-list
re-review) so I'm biased. Further bias: I recommended that he follow
the model of the status.aheadBehind config [1] and advice.statusAheadBehind
[2] patches as prior art.
[1] https://lore.kernel.org/git/2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/c1056545b617b89e881f5991beb2fe0d860de740.1560889284.git.gitgitgadget@gmail.com/
And also I added status.aheadBehind to Scalar's recommended config in
its very first version [3]. Wyatt has updated the Scalar config docs
that justify the recommendation, which was introduced only recently [4].
[3] https://lore.kernel.org/git/4439ab4de0bc3f48a6bdcf4b5165b16fad792ebd.1638538470.git.gitgitgadget@gmail.com/
[4] https://lore.kernel.org/git/f062b0e0773b9d168c031bb1f35538665394a077.1765552528.git.gitgitgadget@gmail.com/
So I give my support publicly for Wyatt's updates.
Thanks,
-Stolee
|
| @@ -22,6 +22,17 @@ commands or functionality in the future. | |||
| option in `git checkout` and `git switch`. See | |||
There was a problem hiding this comment.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):
"Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Wyatt Holden <wyattholden@microsoft.com>
>
> When leaving a detached HEAD, checkout enumerates refs and walks
> history to warn about commits left behind. This work can dominate
> checkout time even after the working tree has been updated.
Interesting.
I often am on a detached HEAD but never realized this particular
check was expensive. The size of changes between the HEAD and the
next branch would affect the time it needs to update the working
tree (the larger the difference, the more expensive to complete the
branch switching). What factors are involved in making this
"orphaned commits" check more expensive? The total number of
branches? The length of commit chain we are leaving behind? I am
trying to see if this is something we can aim to optimize or if it
is a lost cause and a cop-out to introduce an option to disable the
check altogether is the best we can do.
> In an automated checkout of an internal monorepo, unpack_trees ended
> about 12 seconds into a roughly 204-second run. Stack dumps captured
> the main thread in orphaned_commit_warning(), enumerating loose refs
> and opening ref files. Using --quiet reduced the observed checkout
> time to about 14 seconds, but also suppressed unrelated output.
> These observations motivate an opt-out; they do not establish how
> much of the delay came from enumeration versus history traversal.
So, in short, the answer to my earlier question is "we don't know".
> Add checkout.orphanedCommitWarning, enabled by default, so checkout
> and switch can skip the check while retaining normal checkout output.
> Automated callers can opt out when they do not need a warning about
> leaving detached commits behind.
Sounds sensible.
> Follow the configuration precedent of 06b324c1d71 (status: add
> status.aheadbehind setting, 2019-06-18). Unlike status, introduce no
> dedicated command-line option; callers can use git -c for a one-off
> override.
I am not sure how justifiable the design decision to leave the
command line option out is.
The automation can run with "-q" to omit the overhead altogether, as
well as squelching any other output the automation would not read
anyway, so I would not worry too much about them.
But for human users, what are they losing by passing "-q" when they
do not want to pay the cost of this check because we are not giving
them an easy to use command line option? What other output are they
declining by "--quiet"? "The following paths have local changes"
list? Anything else?
> Add a Trace2 region around the check to make its cost visible in
> future investigations and to verify that disabling the setting skips
> the routine rather than merely hiding its warning. Document the
> setting and test both checkout and switch.
Sounds sensible.
> @@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
> struct rev_info revs;
> struct object *object = &old_commit->object;
>
> + trace2_region_enter("checkout", "orphaned_commit_warning", the_repository);
> repo_init_revisions(the_repository, &revs, NULL);
> setup_revisions(0, NULL, &revs, NULL);
>
> @@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
> /* Clean up objects used, as they will be reused. */
> repo_clear_commit_marks(the_repository, ALL_REV_FLAGS);
> release_revisions(&revs);
> + trace2_region_leave("checkout", "orphaned_commit_warning", the_repository);
> }
Quite straightforward. There is no early return in the middle, so
entering at the beginning with leaving at the end is the only change
necessary.
> @@ -1253,8 +1257,14 @@ static int switch_branches(const struct checkout_opts *opts,
> }
> }
>
> - if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)
> - orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
> + if (!opts->quiet && !old_branch_info.path && old_branch_info.commit &&
> + new_branch_info->commit != old_branch_info.commit) {
> + if (opts->orphaned_commit_warning)
> + orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
> + else
> + describe_detached_head(_("Previous HEAD position was"),
> + old_branch_info.commit);
> + }
OK. The call into suggest_reattach() via orphaned_commit_warning()
is the more expensive part, and it also is where "Previous HEAD
was" comes, which we do not want to lose. It makes sense.
Another thing I noticed is that the loop in suggest_reattach() stops
showing each commit after showing ORPHAN_CUTOFF but keeps counting.
I wonder if it becomes palatable to introduce a configuration to
stop it early, instead of disabling the orphaned_commit_warning()
altogether?|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): "Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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.
I found some design choices made in 1/3 questionable but overall the
series is coherently done and very easy to understand _why_ it wants
to do what it does. Nice work.
|
When leaving a detached HEAD, checkout enumerates refs and walks history to warn about commits left behind. This work can dominate checkout time even after the working tree has been updated. In an automated checkout of an internal monorepo, unpack_trees ended about 12 seconds into a roughly 204-second run. Stack dumps captured the main thread in orphaned_commit_warning(), enumerating loose refs and opening ref files. Using --quiet reduced the observed checkout time to about 14 seconds. These observations do not establish how much of the delay came from enumeration versus history traversal. However, --quiet also suppresses local-change summaries, HEAD and branch-switch messages, and upstream tracking information. Add checkout.orphanedCommitWarning, enabled by default, and --[no-]orphaned-commit-warning to checkout and switch. Let the command line override the configuration while preserving --quiet's existing behavior. Callers can then skip the check without suppressing other checkout output. Follow the configuration and command-line precedent of 06b324c (status: add status.aheadbehind setting, 2019-06-18). Add a Trace2 region to expose the check's duration and verify that disabling it skips the work rather than merely hiding its warning. Test both commands, configuration overrides, and retained output. Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
Users encountering a slow orphaned-commit check need a way to discover how to skip it without suppressing other checkout output. Measure the complete check and suggest --no-orphaned-commit-warning or checkout.orphanedCommitWarning=false when it takes more than two seconds. Explain that skipping the check also removes the warning about commits left behind. Allow the advice itself to be disabled with advice.checkoutOrphanedCommitWarning. Follow 0a53561 (status: warn when a/b calculation takes too long, 2019-06-18). Add a test hook that forces the advice condition without changing the measured duration. Test advice suppression independently of the orphan warning, and tolerate scope options in the shared advice's suggested configuration command. Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
Checking for commits left behind when leaving a detached HEAD can be expensive in large repositories. Add checkout.orphanedCommitWarning=false to Scalar's recommended settings to avoid this foreground work while preserving normal checkout output. Use the existing set-if-missing behavior so explicit user choices are preserved during clone, register, and reconfigure. Document the loss of the immediate orphan warning and the availability of reflog recovery. Existing Scalar tests cover configuration preservation, so no additional inventory of recommended settings is needed. Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
f24d401 to
89792a3
Compare
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 a roughly 204-second checkout. Stack samples 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. These observations identify ref enumeration as a contributor but do not establish how much time was spent enumerating refs versus traversing history. They motivate an opt-out without ruling out improvements to the check itself. However, --quiet also suppresses local-change summaries, HEAD and branch-switch messages, and upstream tracking information.
This three-commit series adds a targeted opt-out, advertises it when the check is slow, and enables it in Scalar:
Add checkout.orphanedCommitWarning , enabled by default, and --[no-]orphaned-commit-warning for both checkout and switch. The command-line options override the configuration; --quiet continues to skip the check regardless of those options. Disabling the check retains the previous HEAD description and normal checkout output. Add a Trace2 region to expose the check's duration and tests verifying configuration and command-line overrides, retained output, and that disabling the check bypasses the routine rather than merely hiding its warning.
When the check takes more than two seconds, suggest --no-orphaned-commit-warning or checkout.orphanedCommitWarning=false and explain that disabling the check 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.
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.
Changes since v1:
• Add --[no-]orphaned-commit-warning to checkout and switch, with documentation and tests covering configuration overrides and interaction with --quiet .
• Mention the command-line opt-out in the slow-check advice and its documentation.
• Relax the shared advice-command test to allow options such as --global , while still checking the literal configuration key and false value.
• Correct the alignment of the new entry in advice.c . The Scalar patch is unchanged.
CC: gitster@pobox.com, stolee@gmail.com, wyattj.holden@gmail.com