Repository navigation
Make orphaned commit checks configurable #2264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wyatt-holden
wants to merge
3
commits into
gitgitgadget:master
Choose a base branch
from
wyatt-holden:wyattholden/checkout-orphaned-commit-warning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,13 @@ all advice messages. | |
| configuration variable for how to set a given remote | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Junio C Hamano wrote on the Git mailing list (how to reply to this email): "Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:
> diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh
> index d21dbd5b72..7dfaaab1b8 100755
> --- a/t/t2020-checkout-detach.sh
> +++ b/t/t2020-checkout-detach.sh
> @@ -186,6 +186,46 @@ do
> check_not_detached
> '
>
> + test_expect_success "$command advises when the orphan check is slow" '
> + git checkout --detach "$orphan2" &&
> + GIT_TEST_CHECKOUT_DELAY_WARNING=true \
> + git $command main 2>stderr &&
> + check_orphan_warning stderr "2 commits" &&
> + test_grep -E "^hint: Checking for orphaned commits took [0-9]+[.][0-9]{2} seconds[.]$" stderr &&
> + test_grep "git config set checkout.orphanedCommitWarning false" stderr &&
> + test_grep "git config set advice.checkoutOrphanedCommitWarning false" stderr
> + '
This test will not pass in the modern world where the advice message
suggests to use "git config set --global advice.FOO false".
It probably makes sense to grep for something looser like
"git config .* advice\.checkoutOrphanedCommitWarning"
|
||
| to be used by default in some situations where this | ||
| advice would be printed. | ||
| checkoutOrphanedCommitWarning:: | ||
| Shown when linkgit:git-checkout[1] or linkgit:git-switch[1] | ||
| takes more than 2 seconds to check for commits left behind | ||
| when leaving a detached `HEAD`. Suggests using | ||
| `--no-orphaned-commit-warning` or setting | ||
| `checkout.orphanedCommitWarning` to `false` to skip the check. | ||
| Disabling this advice does not disable the check itself. | ||
| commitBeforeMerge:: | ||
| Shown when linkgit:git-merge[1] refuses to | ||
| merge to avoid overwriting local changes. | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,20 @@ commands or functionality in the future. | |
| option in `git checkout` and `git switch`. See | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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? |
||
| linkgit:git-switch[1] and linkgit:git-checkout[1]. | ||
|
|
||
| `checkout.orphanedCommitWarning`:: | ||
| When leaving a detached `HEAD`, linkgit:git-checkout[1] and | ||
| linkgit:git-switch[1] check whether any commits are being left | ||
| behind that are not reachable from any ref or the new `HEAD`, | ||
| and warn if so. This check can be expensive in large repositories. | ||
| Set this variable to `false` to skip the check and its warning | ||
| without suppressing other checkout output. Defaults to `true`. | ||
| The `--orphaned-commit-warning` and `--no-orphaned-commit-warning` | ||
| options override this setting. `--quiet` skips the check regardless | ||
| of this setting or those options. | ||
| + | ||
| When disabled, commits left behind can still be found in the `HEAD` | ||
| reflog until its entries expire. See linkgit:git-reflog[1]. | ||
|
|
||
| `checkout.workers`:: | ||
| The number of parallel workers to use when updating the working tree. | ||
| The default is one, i.e. sequential execution. If set to a value less | ||
|
|
||
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derrick Stolee wrote on the Git mailing list (how to reply to this email):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):