forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 188
restore: better integrate with sparse index #2121
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
derrickstolee
wants to merge
2
commits into
gitgitgadget:master
Choose a base branch
from
derrickstolee:restore-sparse-index
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.
+101
−6
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -2573,4 +2573,54 @@ test_expect_success 'sparse-index is not expanded: merge-ours' ' | |
| ensure_not_expanded merge -s ours merge-right | ||
|
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): "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Derrick Stolee <stolee@gmail.com>
>
> A user reported that 'git restore --staged .' causes the sparse index to
> expand. This is somewhat natural because the '.' pathspec means 'check
> every path'. However, the restore will not update paths marked with the
> SKIP_WORKTREE bit, so we shouldn't need to process such entries.
Interesting. So, ideally we should be able to say "we are doing
everything because the user gave us '.' from the top level of the
working tree, so let's see each entry and decide what to do. Ah we
have this tree entry in this sparse index, and that is outside the
directories we are dealing with in this working tree that is
sparsely checked out, so we would skip", and for that we have no
need to expand the index. But in reality, what happens is "OK, '.'
so we need to deal with everything. Let's expand.", which would
break the contents of such a "skipped" tree out to constituent
paths, all of which inherits the SKIP_WORKTREE bit to tell us that
these paths are outside the directories we are dealing with".
The end result in the working tree should be the same, but we
unnecessarily expand the index. Correctness wins with a room for
improvement in the performance, which is what we want to see and
then improve ;-) Nice.
> For now, establish the current behavior, including the sparse index
> expansion, in the t1092 test case as a baseline.
>
> Signed-off-by: Derrick Stolee <stolee@gmail.com>
> ---
> t/t1092-sparse-checkout-compatibility.sh | 50 ++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
> index d98cb4ac11..d69434e7ab 100755
> --- a/t/t1092-sparse-checkout-compatibility.sh
> +++ b/t/t1092-sparse-checkout-compatibility.sh
> @@ -2573,4 +2573,54 @@ test_expect_success 'sparse-index is not expanded: merge-ours' '
> ensure_not_expanded merge -s ours merge-right
> '
>
> +test_expect_success 'restore --staged with sparse definition' '
> + init_repos &&
> +
> + # Stage changes within the sparse definition
> + test_all_match git checkout -b restore-staged-1 base &&
> + test_all_match git reset --soft update-deep &&
> + test_all_match git restore --staged . &&
> + test_all_match git status --porcelain=v2 &&
> + test_all_match git diff --cached
> +'
> +
> +test_expect_success 'restore --staged with outside sparse definition' '
> + init_repos &&
> +
> + # Stage changes that include paths outside the sparse definition.
> + # Although the working tree differs between full and sparse checkouts
> + # after restore, the state of the index should be the same.
> + test_all_match git checkout -b restore-staged-2 base &&
> + test_all_match git reset --soft update-folder1 &&
> + test_sparse_match git restore --staged . &&
> + git -C full-checkout restore --staged . &&
> + test_all_match git ls-files -s -- folder1 &&
> + test_all_match git diff --cached -- folder1
> +'
> +
> +test_expect_success 'restore --staged with wildcards' '
> + init_repos &&
> +
> + test_all_match git checkout -b restore-staged-3 base &&
> + test_all_match git reset --soft update-deep &&
> + test_all_match git restore --staged "deep/*" &&
> + test_all_match git status --porcelain=v2 &&
> + test_all_match git diff --cached
> +'
> +
> +test_expect_success 'sparse-index is expanded: restore --staged' '
> + init_repos &&
> +
> + git -C sparse-index checkout -b restore-staged-exp base &&
> + git -C sparse-index reset --soft update-folder1 &&
> + ensure_expanded restore --staged .
> +'
> +
> +test_expect_success 'sparse-index is expanded: restore --source --staged' '
> + init_repos &&
> +
> + git -C sparse-index checkout -b restore-source-staged base &&
> + ensure_expanded restore --source update-folder1 --staged .
> +'
> +
> test_done |
||
| ' | ||
|
|
||
| test_expect_success 'restore --staged with sparse definition' ' | ||
| init_repos && | ||
|
|
||
| # Stage changes within the sparse definition | ||
| test_all_match git checkout -b restore-staged-1 base && | ||
| test_all_match git reset --soft update-deep && | ||
| test_all_match git restore --staged . && | ||
| test_all_match git status --porcelain=v2 && | ||
| test_all_match git diff --cached | ||
| ' | ||
|
|
||
| test_expect_success 'restore --staged with outside sparse definition' ' | ||
| init_repos && | ||
|
|
||
| # Stage changes that include paths outside the sparse definition. | ||
| # Although the working tree differs between full and sparse checkouts | ||
| # after restore, the state of the index should be the same. | ||
| test_all_match git checkout -b restore-staged-2 base && | ||
| test_all_match git reset --soft update-folder1 && | ||
| test_sparse_match git restore --staged . && | ||
| git -C full-checkout restore --staged . && | ||
| test_all_match git ls-files -s -- folder1 && | ||
| test_all_match git diff --cached -- folder1 | ||
| ' | ||
|
|
||
| test_expect_success 'restore --staged with wildcards' ' | ||
| init_repos && | ||
|
|
||
| test_all_match git checkout -b restore-staged-3 base && | ||
| test_all_match git reset --soft update-deep && | ||
| test_all_match git restore --staged "deep/*" && | ||
| test_all_match git status --porcelain=v2 && | ||
| test_all_match git diff --cached | ||
| ' | ||
|
|
||
| test_expect_success 'sparse-index is not expanded: restore --staged' ' | ||
| init_repos && | ||
|
|
||
| git -C sparse-index checkout -b restore-staged-exp base && | ||
| git -C sparse-index reset --soft update-folder1 && | ||
| ensure_not_expanded restore --staged . | ||
| ' | ||
|
|
||
| test_expect_success 'sparse-index is not expanded: restore --source --staged' ' | ||
| init_repos && | ||
|
|
||
| git -C sparse-index checkout -b restore-source-staged base && | ||
| ensure_not_expanded restore --source update-folder1 --staged . | ||
| ' | ||
|
|
||
| test_done | ||
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.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):