From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:08:50
This series integrates the sparse index with commands that perform merges
such as 'git merge', 'git cherry-pick', 'git revert' (free with
cherry-pick), and 'git rebase'.
When the ORT merge strategy is enabled, this allows most merges to succeed
without expanding the sparse index, leading to significant performance
gains. I tested these changes against an internal monorepo with over 2
million paths at HEAD but with a sparse-checkout that only has ~60,000 files
within the sparse-checkout cone. 'git merge' commands went from 5-6 seconds
to 0.750-1.250s.
In the case of the recursive merge strategy, the sparse index is expanded
before the recursive algorithm proceeds. We expect that this is as good as
we can get with that strategy. When the strategy shifts to ORT as the
default, then this will not be a problem except for users who decide to
change the behavior.
Most of the hard work was done by previous series, such as
ds/sparse-index-ignored-files (which this series is based on).
Thanks, -Stolee
Derrick Stolee (6):
t1092: use ORT merge strategy
diff: ignore sparse paths in diffstat
merge: make sparse-aware with ORT
merge-ort: expand only for out-of-cone conflicts
t1092: add cherry-pick, rebase tests
sparse-index: integrate with cherry-pick and rebase
builtin/merge.c | 3 +
builtin/rebase.c | 6 ++
builtin/revert.c | 3 +
diff.c | 8 ++
merge-ort.c | 16 ++++
merge-recursive.c | 3 +
t/t1092-sparse-checkout-compatibility.sh | 97 +++++++++++++++++++++---
7 files changed, 124 insertions(+), 12 deletions(-)
base-commit: febef675f051eb08896751bb5661b6deb5579ead
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1019%2Fderrickstolee%2Fsparse-index%2Fmerge-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1019/derrickstolee/sparse-index/merge-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1019
--
gitgitgadget
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:08:52
From: Derrick Stolee <redacted>
The sparse index will be compatible with the ORT merge strategy, so
let's use it explicitly in our tests.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
@@ -7,6 +7,11 @@ GIT_TEST_SPARSE_INDEX= ../test-lib.sh+# Force the use of the ORT merge algorithm until testing with the+# recursive strategy. We expect ORT to be used with sparse-index.+GIT_TEST_MERGE_ALGORITHM=ort+exportGIT_TEST_MERGE_ALGORITHM+ test_expect_success'setup''gitinitinitial-repo&&(
@@ -501,7 +506,7 @@ test_expect_success 'merge with conflict outside cone' 'test_all_matchgitcheckout-bmerge-tipmerge-left&&test_all_matchgitstatus--porcelain=v2&&-test_all_matchtest_must_failgitmerge-mmergemerge-right&&+test_all_matchtest_must_failgitmerge-sort-mmergemerge-right&&test_all_matchgitstatus--porcelain=v2&&# Resolve the conflict in different ways:
@@ -531,7 +536,7 @@ test_expect_success 'merge with outside renames' 'dotest_all_matchgitreset--hard&&test_all_matchgitcheckout-f-bmerge-$typeupdate-deep&&-test_all_matchgitmerge-m"$type"rename-$type&&+test_all_matchgitmerge-sort-m"$type"rename-$type&&test_all_matchgitrev-parseHEAD^{tree}||return1done'
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:08:55
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete, especially when a conflict appears. In
order to avoid expanding a sparse index, the reuse_worktree_file() needs
to be adapted to ignore files that are outside of the sparse-checkout
cone. The file names and OIDs used for this check come from the merged
tree in the case of the ORT strategy, not the index, hence the ability
to look into these paths without having already expanded the index.
Signed-off-by: Derrick Stolee <redacted>
---
diff.c | 8 ++++++++
1 file changed, 8 insertions(+)
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:08:57
From: Derrick Stolee <redacted>
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:
1. If the merge strategy is 'recursive', then we enable
command_requires_full_index at the start of the merge_recursive()
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
2. If the merge results in a conflicted file, then we expand the index
before updating the working tree. The loop that iterates over the
worktree replaces index entries and tracks 'origintal_cache_nr' which
can become completely wrong if the index expands in the middle of the
operation. This safety valve is important before that loop starts. A
later change will focus this to only expand if we indeed have a
conflict outside of the sparse-checkout cone.
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/merge.c | 3 +++
merge-ort.c | 8 ++++++++
merge-recursive.c | 3 +++
t/t1092-sparse-checkout-compatibility.sh | 8 ++++++--
4 files changed, 20 insertions(+), 2 deletions(-)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)if(strmap_empty(&opt->priv->conflicted))return0;+/*+*Weareinaconflictedstate.Theseconflictsmightbeinside+*sparse-directoryentries,soexpandtheindexpreemtively.+*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*index_name_pos()callsaskforpathswithinsparsedirectories.+*/+ensure_full_index(index);+/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;state.quiet=1;
@@ -652,7 +652,11 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/extra.txt&&ensure_not_expandedaddextra.txt&&echo>>sparse-index/untracked.txt&&-ensure_not_expandedadd.+ensure_not_expandedadd.&&++ensure_not_expandedcheckout-fupdate-deep&&+ensure_not_expandedmerge-sort-mmergeupdate-folder1&&+ensure_not_expandedmerge-sort-mmergeupdate-folder2'# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:08:58
From: Derrick Stolee <redacted>
Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.
Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.
Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.
Signed-off-by: Derrick Stolee <redacted>
---
merge-ort.c | 14 ++++++++---
t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++--
2 files changed, 39 insertions(+), 5 deletions(-)
@@ -4060,11 +4061,18 @@ static int record_conflicted_index_entries(struct merge_options *opt)/**Weareinaconflictedstate.Theseconflictsmightbeinside-*sparse-directoryentries,soexpandtheindexpreemtively.-*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*sparse-directoryentries,socheckifanyentriesareoutside+*ofthesparse-checkoutconepreemptively.+*+*Wesetoriginal_cache_nrbelow,butthatmightchangeif*index_name_pos()callsaskforpathswithinsparsedirectories.*/-ensure_full_index(index);+strmap_for_each_entry(&opt->priv->conflicted,&iter,e){+if(!path_in_sparse_checkout(e->key,index)){+ensure_full_index(index);+break;+}+}/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;
@@ -622,8 +622,21 @@ test_expect_success 'sparse-index is expanded and converted back' ' ensure_not_expanded(){rm-ftrace2.txt&&echo>>sparse-index/untracked.txt&&-GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\-git-Csparse-index"$@"&&++iftest"$1"="!"+then+shift&&+(+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"&&+GIT_TRACE2_EVENT_NESTING=10&&+exportGIT_TRACE2_EVENT&&+exportGIT_TRACE2_EVENT_NESTING&&+test_must_failgit-Csparse-index"$@"||return1+)+else+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+fi&&test_region!indexensure_full_indextrace2.txt}
@@ -659,6 +672,19 @@ test_expect_success 'sparse-index is not expanded' 'ensure_not_expandedmerge-sort-mmergeupdate-folder2'+test_expect_success'sparse-index is not expanded: merge conflict in cone''+init_repos&&++forsideinrightleft+do+git-Csparse-indexcheckout-bexpand-$sidebase&&+echo$side>sparse-index/deep/a&&+git-Csparse-indexcommit-a-m"$side"||return1+done&&++ensure_not_expanded!merge-mmergedexpand-right+'+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout# in this scenario, but it shouldn't. test_expect_success'reset mixed and checkout orphan''
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:09:00
From: Derrick Stolee <redacted>
Add tests to check that cherry-pick and rebase behave the same in the
sparse-index case as in the full index cases.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
@@ -486,14 +486,17 @@ test_expect_success 'checkout and reset (mixed) [sparse]' 'test_sparse_matchgitresetupdate-folder2'-test_expect_success'merge''+test_expect_success'merge, cherry-pick, and rebase''init_repos&&-test_all_matchgitcheckout-bmergeupdate-deep&&-test_all_matchgitmerge-m"folder1"update-folder1&&-test_all_matchgitrev-parseHEAD^{tree}&&-test_all_matchgitmerge-m"folder2"update-folder2&&-test_all_matchgitrev-parseHEAD^{tree}+forOPERATIONin"merge -s ort -m merge"cherry-pickrebase+do+test_all_matchgitcheckout-Btempupdate-deep&&+test_all_matchgit$OPERATIONupdate-folder1&&+test_all_matchgitrev-parseHEAD^{tree}&&+test_all_matchgit$OPERATIONupdate-folder2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done'# NEEDSWORK: This test is documenting current behavior, but that
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-17 17:09:01
From: Derrick Stolee <redacted>
The hard work was already done with 'git merge' and the ORT strategy.
Just add extra tests to see that we get the expected results in the
non-conflict cases.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/rebase.c | 6 ++++
builtin/revert.c | 3 ++
t/t1092-sparse-checkout-compatibility.sh | 41 ++++++++++++++++++++++--
3 files changed, 47 insertions(+), 3 deletions(-)
@@ -1430,6 +1433,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)usage_with_options(builtin_rebase_usage,builtin_rebase_options);+prepare_repo_settings(the_repository);+the_repository->settings.command_requires_full_index=0;+options.allow_empty_message=1;git_config(rebase_config,&options);/* options.gpg_sign_opt will be either "-S" or NULL */
@@ -532,6 +532,38 @@ test_expect_success 'merge with conflict outside cone' 'test_all_matchgitrev-parseHEAD^{tree}'+test_expect_success'cherry-pick/rebase with conflict outside cone''+init_repos&&++forOPERATIONincherry-pickrebase+do+test_all_matchgitcheckout-Btip&&+test_all_matchgitreset--hardmerge-left&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchtest_must_failgit$OPERATIONmerge-right&&+test_all_matchgitstatus--porcelain=v2&&++# Resolve the conflict in different ways:+# 1. Revert to the base+test_all_matchgitcheckoutbase--deep/deeper2/a&&+test_all_matchgitstatus--porcelain=v2&&++# 2. Add the file with conflict markers+test_all_matchgitaddfolder1/a&&+test_all_matchgitstatus--porcelain=v2&&++# 3. Rename the file to another sparse filename and+# accept conflict markers as resolved content.+run_on_allmvfolder2/afolder2/z&&+test_all_matchgitaddfolder2&&+test_all_matchgitstatus--porcelain=v2&&++test_all_matchgit$OPERATION--continue&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done+'+ test_expect_success'merge with outside renames''init_repos&&
@@ -670,9 +702,12 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/untracked.txt&&ensure_not_expandedadd.&&-ensure_not_expandedcheckout-fupdate-deep&&-ensure_not_expandedmerge-sort-mmergeupdate-folder1&&-ensure_not_expandedmerge-sort-mmergeupdate-folder2+forOPERATIONin"merge -s ort -m merge"cherry-pickrebase+do+ensure_not_expandedcheckout-f-Btempupdate-deep&&+ensure_not_expanded$OPERATIONupdate-folder1&&+ensure_not_expanded$OPERATIONupdate-folder2||return1+done' test_expect_success'sparse-index is not expanded: merge conflict in cone''
From: Taylor Blau <hidden> Date: 2021-08-18 17:17:03
On Tue, Aug 17, 2021 at 05:08:39PM +0000, Derrick Stolee via GitGitGadget wrote:
quoted hunk
From: Derrick Stolee <redacted>
The sparse index will be compatible with the ORT merge strategy, so
let's use it explicitly in our tests.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
@@ -7,6 +7,11 @@ GIT_TEST_SPARSE_INDEX= ../test-lib.sh+# Force the use of the ORT merge algorithm until testing with the+# recursive strategy. We expect ORT to be used with sparse-index.+GIT_TEST_MERGE_ALGORITHM=ort+exportGIT_TEST_MERGE_ALGORITHM+
Looks good, but are the lower hunks which set `-s ort` necessary, too? I
applied this series into my tree and t1092 still passes after reverting
the next two hunks.
Not worth a reroll on its own, just curious.
Thanks,
Taylor
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete, especially when a conflict appears. In
order to avoid expanding a sparse index, the reuse_worktree_file() needs
to be adapted to ignore files that are outside of the sparse-checkout
cone. The file names and OIDs used for this check come from the merged
tree in the case of the ORT strategy, not the index, hence the ability
to look into these paths without having already expanded the index.
I'm confused; I thought the diffstat was only shown if the merge was
successful, in which case there would be no conflicts appearing.
Also, I'm not that familiar with the general diff machinery (just the
rename detection parts), but...if the diffstat only shows when the
merge is successful, wouldn't we be comparing two REVS (ORIG_HEAD to
HEAD)? Why would we make use of the working tree at all in such a
case? And, wouldn't using the working tree be dangerous...what if
there was a merge performed with a dirty working tree?
On a bit of a tangent, I know diffcore-rename.c calls into
diff_populate_filespec() as well, and I have some code doing merges in
a bare repository (where there obviously is no index). It seemed to
be working, but given this commit message, now I'm wondering if I've
missed something fundamental either in that implementation or there's
something amiss in this patch. Or both. Maybe I need to dig into
diff_populate_filespec() more, but it seems you already have. Any
pointers to orient me on why your changes are right here (and, if you
know, why diffcore-rename.c should or shouldn't be using
diff_populate_filespec() in a bare repo)?
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
From: Derrick Stolee <redacted>
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:
1. If the merge strategy is 'recursive', then we enable
command_requires_full_index at the start of the merge_recursive()
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
What about `resolve`, `octopus`, `subtree` (which technically could be
implemented via either recursive or ort, such fun...) or a
user-defined strategy?
`resolve` and `octopus` would absolutely need a full index. `subtree`
would if implemented via merge-recursive, and not if implemented via
merge-ort.
I'm not sure what to assume about user-defined strategies; I guess for
safety reasons and backward compatibility, we should always expand?
Or maybe there are no backward compatibility concerns since no one who
uses a sparse-index will attempt to use any pre-existing external
merge strategies (are there even any known ones in the wild or is this
still a theoretical capability?), and we can assume they will only use
ones written in the future? Hmm...
2. If the merge results in a conflicted file, then we expand the index
before updating the working tree. The loop that iterates over the
worktree replaces index entries and tracks 'origintal_cache_nr' which
can become completely wrong if the index expands in the middle of the
operation. This safety valve is important before that loop starts. A
later change will focus this to only expand if we indeed have a
conflict outside of the sparse-checkout cone.
From reading the patch below, this is specific to ort, but that wasn't
clear on reading the commit message.
quoted hunk
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/merge.c | 3 +++
merge-ort.c | 8 ++++++++
merge-recursive.c | 3 +++
t/t1092-sparse-checkout-compatibility.sh | 8 ++++++--
4 files changed, 20 insertions(+), 2 deletions(-)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)if(strmap_empty(&opt->priv->conflicted))return0;+/*+*Weareinaconflictedstate.Theseconflictsmightbeinside+*sparse-directoryentries,soexpandtheindexpreemtively.
s/preemtively/preemptively/
+ * Also, we set original_cache_nr below, but that might change if
+ * index_name_pos() calls ask for paths within sparse directories.
+ */
+ ensure_full_index(index);
+
This seems somewhat pessimistic; what if all the conflicts are within
the sparse-checkout? Having conflicts contains within the
sparse-checkout seems likely, since we'd only get conflicts for files
modified by both sides of history, and sparse-checkouts are used when
users aren't going to modify files outside the sparse-checkout.
quoted hunk
/* If any entries have skip_worktree set, we'll have to check 'em out */
state.force = 1;
state.quiet = 1;
@@ -652,7 +652,11 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/extra.txt&&ensure_not_expandedaddextra.txt&&echo>>sparse-index/untracked.txt&&-ensure_not_expandedadd.+ensure_not_expandedadd.&&++ensure_not_expandedcheckout-fupdate-deep&&+ensure_not_expandedmerge-sort-mmergeupdate-folder1&&+ensure_not_expandedmerge-sort-mmergeupdate-folder2
Can we just set GIT_TEST_MERGE_ALGORITHM=ort at the beginning of the
test file and then avoid repeating `-s ort`?
'
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
--
gitgitgadget
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
From: Derrick Stolee <redacted>
Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.
Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.
Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.
If I had read ahead a little bit instead of responding as I went.... :-)
Awesome to see this.
dir.h was already included from merge-ort.c; no need to include it
again. (Plus, the original line keeps the nice ordering of the
include list...)
quoted hunk
/*
* We have many arrays of size 3. Whenever we have such an array, the
@@ -4060,11 +4061,18 @@ static int record_conflicted_index_entries(struct merge_options *opt) /* * We are in a conflicted state. These conflicts might be inside- * sparse-directory entries, so expand the index preemtively.- * Also, we set original_cache_nr below, but that might change if+ * sparse-directory entries, so check if any entries are outside+ * of the sparse-checkout cone preemptively.+ *+ * We set original_cache_nr below, but that might change if * index_name_pos() calls ask for paths within sparse directories. */- ensure_full_index(index);+ strmap_for_each_entry(&opt->priv->conflicted, &iter, e) {+ if (!path_in_sparse_checkout(e->key, index)) {+ ensure_full_index(index);+ break;+ }+ }
Sweet, awesome that it was so simple to implement.
quoted hunk
/* If any entries have skip_worktree set, we'll have to check 'em out */
state.force = 1;
@@ -622,8 +622,21 @@ test_expect_success 'sparse-index is expanded and converted back' ' ensure_not_expanded(){rm-ftrace2.txt&&echo>>sparse-index/untracked.txt&&-GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\-git-Csparse-index"$@"&&++iftest"$1"="!"+then+shift&&+(+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"&&+GIT_TRACE2_EVENT_NESTING=10&&+exportGIT_TRACE2_EVENT&&+exportGIT_TRACE2_EVENT_NESTING&&+test_must_failgit-Csparse-index"$@"||return1+)
Could this be simplified to
test_must_fail env \
GIT_TRACE2_EVENT="$(pwd)/trace2.txt"
GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index "$@" || return 1
?
Especially if the lines can be indented to make it clear that the only
difference between this block and the one below is the "test_must_fail
env" being added at the front.
@@ -659,6 +672,19 @@ test_expect_success 'sparse-index is not expanded' ' ensure_not_expanded merge -s ort -m merge update-folder2 '+test_expect_success 'sparse-index is not expanded: merge conflict in cone' '+ init_repos &&++ for side in right left+ do+ git -C sparse-index checkout -b expand-$side base &&+ echo $side >sparse-index/deep/a &&+ git -C sparse-index commit -a -m "$side" || return 1+ done &&++ ensure_not_expanded ! merge -m merged expand-right+'+ # NEEDSWORK: a sparse-checkout behaves differently from a full checkout # in this scenario, but it shouldn't. test_expect_success 'reset mixed and checkout orphan' '--
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted hunk
From: Derrick Stolee <redacted>
Add tests to check that cherry-pick and rebase behave the same in the
sparse-index case as in the full index cases.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
@@ -486,14 +486,17 @@ test_expect_success 'checkout and reset (mixed) [sparse]' 'test_sparse_matchgitresetupdate-folder2'-test_expect_success'merge''+test_expect_success'merge, cherry-pick, and rebase''init_repos&&-test_all_matchgitcheckout-bmergeupdate-deep&&-test_all_matchgitmerge-m"folder1"update-folder1&&-test_all_matchgitrev-parseHEAD^{tree}&&-test_all_matchgitmerge-m"folder2"update-folder2&&-test_all_matchgitrev-parseHEAD^{tree}+forOPERATIONin"merge -s ort -m merge"cherry-pickrebase
You're explicitly testing the ort strategy with merge, but relying on
GIT_TEST_MERGE_ALGORITHM for cherry-pick and rebase?
It'd probably be better to set GIT_TEST_MERGE_ALGORITHM=ort at the
beginning of the file and leave out the `-s ort` references.
Or, if you really wanted to test both algorithms, then in addition to
leaving out the `-s ort`, don't bother setting
GIT_TEST_MERGE_ALGORITHM. (That works because automated test suites
will set GIT_TEST_MERGE_ALGORITHM=recursive on linux-gcc, and
GIT_TEST_MERGE_ALGORITHM=ort elsewhere).
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
From: Derrick Stolee <redacted>
The hard work was already done with 'git merge' and the ORT strategy.
Just add extra tests to see that we get the expected results in the
non-conflict cases.
While rebase can use either merge-recursive or merge-ort under the
covers, this change is okay because merge-recursive.c now has code to
expand the index unconditionally, and merge-ort does so only
conditionally in the cases needed. Right? (Same for change below to
revert.c)
quoted hunk
options.allow_empty_message = 1;
git_config(rebase_config, &options);
/* options.gpg_sign_opt will be either "-S" or NULL */
@@ -532,6 +532,38 @@ test_expect_success 'merge with conflict outside cone' 'test_all_matchgitrev-parseHEAD^{tree}'+test_expect_success'cherry-pick/rebase with conflict outside cone''+init_repos&&++forOPERATIONincherry-pickrebase+do+test_all_matchgitcheckout-Btip&&+test_all_matchgitreset--hardmerge-left&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchtest_must_failgit$OPERATIONmerge-right&&+test_all_matchgitstatus--porcelain=v2&&++# Resolve the conflict in different ways:+# 1. Revert to the base+test_all_matchgitcheckoutbase--deep/deeper2/a&&+test_all_matchgitstatus--porcelain=v2&&++# 2. Add the file with conflict markers+test_all_matchgitaddfolder1/a&&+test_all_matchgitstatus--porcelain=v2&&++# 3. Rename the file to another sparse filename and+# accept conflict markers as resolved content.+run_on_allmvfolder2/afolder2/z&&+test_all_matchgitaddfolder2&&+test_all_matchgitstatus--porcelain=v2&&++test_all_matchgit$OPERATION--continue&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done+'+ test_expect_success'merge with outside renames''init_repos&&
@@ -670,9 +702,12 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/untracked.txt&&ensure_not_expandedadd.&&-ensure_not_expandedcheckout-fupdate-deep&&-ensure_not_expandedmerge-sort-mmergeupdate-folder1&&-ensure_not_expandedmerge-sort-mmergeupdate-folder2+forOPERATIONin"merge -s ort -m merge"cherry-pickrebase+do+ensure_not_expandedcheckout-f-Btempupdate-deep&&+ensure_not_expanded$OPERATIONupdate-folder1&&+ensure_not_expanded$OPERATIONupdate-folder2||return1+done
Won't this fail on linux-gcc in the automated testing, since it uses
GIT_TEST_MERGE_ALGORITHM=recursive and you didn't override the merge
strategy for cherry-pick and rebase?
To fix, you'd either need to put a GIT_TEST_MERGE_ALGORITHM=ort at the
beginning of the file, or add `--strategy ort` options to the
cherry-pick and rebase commands.
'
test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
--
gitgitgadget
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete, especially when a conflict appears. In
order to avoid expanding a sparse index, the reuse_worktree_file() needs
to be adapted to ignore files that are outside of the sparse-checkout
cone. The file names and OIDs used for this check come from the merged
tree in the case of the ORT strategy, not the index, hence the ability
to look into these paths without having already expanded the index.
I'm confused; I thought the diffstat was only shown if the merge was
successful, in which case there would be no conflicts appearing.
That's my mistake. I'll edit the message accordingly.
Also, I'm not that familiar with the general diff machinery (just the
rename detection parts), but...if the diffstat only shows when the
merge is successful, wouldn't we be comparing two REVS (ORIG_HEAD to
HEAD)? Why would we make use of the working tree at all in such a
case? And, wouldn't using the working tree be dangerous...what if
there was a merge performed with a dirty working tree?
On a bit of a tangent, I know diffcore-rename.c calls into
diff_populate_filespec() as well, and I have some code doing merges in
a bare repository (where there obviously is no index). It seemed to
be working, but given this commit message, now I'm wondering if I've
missed something fundamental either in that implementation or there's
something amiss in this patch. Or both. Maybe I need to dig into
diff_populate_filespec() more, but it seems you already have. Any
pointers to orient me on why your changes are right here (and, if you
know, why diffcore-rename.c should or shouldn't be using
diff_populate_filespec() in a bare repo)?
I think the cases you are thinking about are covered by this
condition before the one I'm inserting:
/* We want to avoid the working directory if our caller
* doesn't need the data in a normal file, this system
* is rather slow with its stat/open/mmap/close syscalls,
* and the object is contained in a pack file. The pack
* is probably already open and will be faster to obtain
* the data through than the working directory. Loose
* objects however would tend to be slower as they need
* to be individually opened and inflated.
*/
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
return 0;
or after:
/*
* Similarly, if we'd have to convert the file contents anyway, that
* makes the optimization not worthwhile.
*/
if (!want_file && would_convert_to_git(istate, name))
return 0;
(This makes me think that I should move my new condition further down
so these two can be linked by context.)
Sounds like this is just an optimization, so it is fine to opt out of it
if we think the optimization isn't necessary. Outside of the sparse-checkout
cone qualifies.
Thanks,
-Stolee
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:12
From: Derrick Stolee <redacted>
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:
1. If the merge strategy is 'recursive', then we enable
command_requires_full_index at the start of the merge_recursive()
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
2. With the 'ort' strategy, if the merge results in a conflicted file,
then we expand the index before updating the working tree. The loop
that iterates over the worktree replaces index entries and tracks
'origintal_cache_nr' which can become completely wrong if the index
expands in the middle of the operation. This safety valve is
important before that loop starts. A later change will focus this
to only expand if we indeed have a conflict outside of the
sparse-checkout cone.
3. Other merge strategies are executed as a 'git merge-X' subcommand,
and those strategies are currently protected with the
'command_requires_full_index' guard.
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/merge.c | 3 +++
merge-ort.c | 8 ++++++++
merge-recursive.c | 3 +++
t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++--
4 files changed, 24 insertions(+), 2 deletions(-)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)if(strmap_empty(&opt->priv->conflicted))return0;+/*+*Weareinaconflictedstate.Theseconflictsmightbeinside+*sparse-directoryentries,soexpandtheindexpreemtively.+*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*index_name_pos()callsaskforpathswithinsparsedirectories.+*/+ensure_full_index(index);+/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;state.quiet=1;
@@ -647,7 +647,15 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/extra.txt&&ensure_not_expandedaddextra.txt&&echo>>sparse-index/untracked.txt&&-ensure_not_expandedadd.+ensure_not_expandedadd.&&++ensure_not_expandedcheckout-fupdate-deep&&+(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+git-Csparse-indexconfigpull.twoheadort&&+ensure_not_expandedmerge-mmergeupdate-folder1&&+ensure_not_expandedmerge-mmergeupdate-folder2+)'# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:12
This series integrates the sparse index with commands that perform merges
such as 'git merge', 'git cherry-pick', 'git revert' (free with
cherry-pick), and 'git rebase'.
When the ORT merge strategy is enabled, this allows most merges to succeed
without expanding the sparse index, leading to significant performance
gains. I tested these changes against an internal monorepo with over 2
million paths at HEAD but with a sparse-checkout that only has ~60,000 files
within the sparse-checkout cone. 'git merge' commands went from 5-6 seconds
to 0.750-1.250s.
In the case of the recursive merge strategy, the sparse index is expanded
before the recursive algorithm proceeds. We expect that this is as good as
we can get with that strategy. When the strategy shifts to ORT as the
default, then this will not be a problem except for users who decide to
change the behavior.
Most of the hard work was done by previous series, such as
ds/sparse-index-ignored-files (which this series is based on).
Updates in V2
=============
* The tests no longer specify GIT_TEST_MERGE_ALGORITHM or directly
reference "-s ort". By relaxing this condition, I found an issue with
'git cherry-pick' and 'git rebase' when using the 'recursive' algorithm
which is fixed in a new patch.
* Use the pul.twohead config to specify the ORT merge algorithm to avoid
expanding the sparse index when that is what we are testing.
* Corrected some misstatements in my commit messages.
Thanks, -Stolee
Derrick Stolee (6):
diff: ignore sparse paths in diffstat
merge: make sparse-aware with ORT
merge-ort: expand only for out-of-cone conflicts
t1092: add cherry-pick, rebase tests
sequencer: ensure full index if not ORT strategy
sparse-index: integrate with cherry-pick and rebase
builtin/merge.c | 3 +
builtin/rebase.c | 6 ++
builtin/revert.c | 3 +
diff.c | 8 +++
merge-ort.c | 15 ++++
merge-recursive.c | 3 +
sequencer.c | 9 +++
t/t1092-sparse-checkout-compatibility.sh | 92 +++++++++++++++++++++---
8 files changed, 129 insertions(+), 10 deletions(-)
base-commit: 8d55a6ba2fdf64cee4eb51f3cb6f9808bd0b7505
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1019%2Fderrickstolee%2Fsparse-index%2Fmerge-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1019/derrickstolee/sparse-index/merge-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1019
Range-diff vs v1:
1: 7cad9eee90b < -: ----------- t1092: use ORT merge strategy
2: 9f50f11d394 ! 1: c5ae705648c diff: ignore sparse paths in diffstat
@@ Commit message
diff: ignore sparse paths in diffstat
The diff_populate_filespec() method is used to describe the diff after a
- merge operation is complete, especially when a conflict appears. In
- order to avoid expanding a sparse index, the reuse_worktree_file() needs
- to be adapted to ignore files that are outside of the sparse-checkout
- cone. The file names and OIDs used for this check come from the merged
- tree in the case of the ORT strategy, not the index, hence the ability
- to look into these paths without having already expanded the index.
+ merge operation is complete. In order to avoid expanding a sparse index,
+ the reuse_worktree_file() needs to be adapted to ignore files that are
+ outside of the sparse-checkout cone. The file names and OIDs used for
+ this check come from the merged tree in the case of the ORT strategy,
+ not the index, hence the ability to look into these paths without having
+ already expanded the index.
+
+ The work done by reuse_worktree_file() is only an optimization, and
+ requires the file being on disk for it to be of any value. Thus, it is
+ safe to exit the method early if we do not expect the file on disk.
Signed-off-by: Derrick Stolee [off-list ref]
@@ diff.c
#ifdef NO_FAST_WORKING_DIRECTORY
#define FAST_WORKING_DIRECTORY 0
@@ diff.c: static int reuse_worktree_file(struct index_state *istate,
- if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
+ if (!want_file && would_convert_to_git(istate, name))
return 0;
+ /*
@@ diff.c: static int reuse_worktree_file(struct index_state *istate,
+ if (!path_in_sparse_checkout(name, istate))
+ return 0;
+
- /*
- * Similarly, if we'd have to convert the file contents anyway, that
- * makes the optimization not worthwhile.
+ len = strlen(name);
+ pos = index_name_pos(istate, name, len);
+ if (pos < 0)
3: 4c1104a0dd3 ! 2: bb150483bcf merge: make sparse-aware with ORT
@@ Commit message
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
- 2. If the merge results in a conflicted file, then we expand the index
- before updating the working tree. The loop that iterates over the
- worktree replaces index entries and tracks 'origintal_cache_nr' which
- can become completely wrong if the index expands in the middle of the
- operation. This safety valve is important before that loop starts. A
- later change will focus this to only expand if we indeed have a
- conflict outside of the sparse-checkout cone.
+ 2. With the 'ort' strategy, if the merge results in a conflicted file,
+ then we expand the index before updating the working tree. The loop
+ that iterates over the worktree replaces index entries and tracks
+ 'origintal_cache_nr' which can become completely wrong if the index
+ expands in the middle of the operation. This safety valve is
+ important before that loop starts. A later change will focus this
+ to only expand if we indeed have a conflict outside of the
+ sparse-checkout cone.
+
+ 3. Other merge strategies are executed as a 'git merge-X' subcommand,
+ and those strategies are currently protected with the
+ 'command_requires_full_index' guard.
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n
+ ensure_not_expanded add . &&
+
+ ensure_not_expanded checkout -f update-deep &&
-+ ensure_not_expanded merge -s ort -m merge update-folder1 &&
-+ ensure_not_expanded merge -s ort -m merge update-folder2
++ (
++ sane_unset GIT_TEST_MERGE_ALGORITHM &&
++ git -C sparse-index config pull.twohead ort &&
++ ensure_not_expanded merge -m merge update-folder1 &&
++ ensure_not_expanded merge -m merge update-folder2
++ )
'
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
4: e47b15554e3 ! 3: 815b1b1cfbf merge-ort: expand only for out-of-cone conflicts
@@ Commit message
Signed-off-by: Derrick Stolee [off-list ref]
## merge-ort.c ##
-@@
- #include "tree.h"
- #include "unpack-trees.h"
- #include "xdiff-interface.h"
-+#include "dir.h"
-
- /*
- * We have many arrays of size 3. Whenever we have such an array, the
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *opt)
/*
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is e
+ if test "$1" = "!"
+ then
+ shift &&
-+ (
-+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" &&
-+ GIT_TRACE2_EVENT_NESTING=10 &&
-+ export GIT_TRACE2_EVENT &&
-+ export GIT_TRACE2_EVENT_NESTING &&
-+ test_must_fail git -C sparse-index "$@" || return 1
-+ )
++ test_must_fail env \
++ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
++ git -C sparse-index "$@" || return 1
+ else
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+ git -C sparse-index "$@" || return 1
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is e
}
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is not expanded' '
- ensure_not_expanded merge -s ort -m merge update-folder2
+ )
'
+test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n
+ git -C sparse-index commit -a -m "$side" || return 1
+ done &&
+
-+ ensure_not_expanded ! merge -m merged expand-right
++ (
++ sane_unset GIT_TEST_MERGE_ALGORITHM &&
++ git -C sparse-index config pull.twohead ort &&
++ ensure_not_expanded ! merge -m merged expand-right
++ )
+'
+
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
5: ca23bf38bd9 ! 4: 8032154bc8a t1092: add cherry-pick, rebase tests
@@ Commit message
t1092: add cherry-pick, rebase tests
Add tests to check that cherry-pick and rebase behave the same in the
- sparse-index case as in the full index cases.
+ sparse-index case as in the full index cases. These tests are agnostic
+ to GIT_TEST_MERGE_ALGORITHM, so a full CI test suite will check both the
+ 'ort' and 'recursive' strategies on this test.
Signed-off-by: Derrick Stolee [off-list ref]
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'checkout and rese
- test_all_match git rev-parse HEAD^{tree} &&
- test_all_match git merge -m "folder2" update-folder2 &&
- test_all_match git rev-parse HEAD^{tree}
-+ for OPERATION in "merge -s ort -m merge" cherry-pick rebase
++ for OPERATION in "merge -m merge" cherry-pick rebase
+ do
+ test_all_match git checkout -B temp update-deep &&
+ test_all_match git $OPERATION update-folder1 &&
-: ----------- > 5: 90ac85500b8 sequencer: ensure full index if not ORT strategy
6: 350ed86a453 ! 6: df4bbec744f sparse-index: integrate with cherry-pick and rebase
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'merge with confli
init_repos &&
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is not expanded' '
- echo >>sparse-index/untracked.txt &&
- ensure_not_expanded add . &&
-
-- ensure_not_expanded checkout -f update-deep &&
-- ensure_not_expanded merge -s ort -m merge update-folder1 &&
-- ensure_not_expanded merge -s ort -m merge update-folder2
-+ for OPERATION in "merge -s ort -m merge" cherry-pick rebase
-+ do
-+ ensure_not_expanded checkout -f -B temp update-deep &&
-+ ensure_not_expanded $OPERATION update-folder1 &&
-+ ensure_not_expanded $OPERATION update-folder2 || return 1
-+ done
+ (
+ sane_unset GIT_TEST_MERGE_ALGORITHM &&
+ git -C sparse-index config pull.twohead ort &&
+- ensure_not_expanded merge -m merge update-folder1 &&
+- ensure_not_expanded merge -m merge update-folder2
++ for OPERATION in "merge -m merge" cherry-pick rebase
++ do
++ ensure_not_expanded merge -m merge update-folder1 &&
++ ensure_not_expanded merge -m merge update-folder2 || return 1
++ done
+ )
'
- test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
--
gitgitgadget
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:15
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete. In order to avoid expanding a sparse index,
the reuse_worktree_file() needs to be adapted to ignore files that are
outside of the sparse-checkout cone. The file names and OIDs used for
this check come from the merged tree in the case of the ORT strategy,
not the index, hence the ability to look into these paths without having
already expanded the index.
The work done by reuse_worktree_file() is only an optimization, and
requires the file being on disk for it to be of any value. Thus, it is
safe to exit the method early if we do not expect the file on disk.
Signed-off-by: Derrick Stolee <redacted>
---
diff.c | 8 ++++++++
1 file changed, 8 insertions(+)
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:16
From: Derrick Stolee <redacted>
Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.
Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.
Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.
Signed-off-by: Derrick Stolee <redacted>
---
merge-ort.c | 13 +++++++---
t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++--
2 files changed, 38 insertions(+), 5 deletions(-)
@@ -4060,11 +4060,18 @@ static int record_conflicted_index_entries(struct merge_options *opt)/**Weareinaconflictedstate.Theseconflictsmightbeinside-*sparse-directoryentries,soexpandtheindexpreemtively.-*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*sparse-directoryentries,socheckifanyentriesareoutside+*ofthesparse-checkoutconepreemptively.+*+*Wesetoriginal_cache_nrbelow,butthatmightchangeif*index_name_pos()callsaskforpathswithinsparsedirectories.*/-ensure_full_index(index);+strmap_for_each_entry(&opt->priv->conflicted,&iter,e){+if(!path_in_sparse_checkout(e->key,index)){+ensure_full_index(index);+break;+}+}/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;
@@ -617,8 +617,17 @@ test_expect_success 'sparse-index is expanded and converted back' ' ensure_not_expanded(){rm-ftrace2.txt&&echo>>sparse-index/untracked.txt&&-GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\-git-Csparse-index"$@"&&++iftest"$1"="!"+then+shift&&+test_must_failenv\+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+else+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+fi&&test_region!indexensure_full_indextrace2.txt}
@@ -658,6 +667,23 @@ test_expect_success 'sparse-index is not expanded' ')'+test_expect_success'sparse-index is not expanded: merge conflict in cone''+init_repos&&++forsideinrightleft+do+git-Csparse-indexcheckout-bexpand-$sidebase&&+echo$side>sparse-index/deep/a&&+git-Csparse-indexcommit-a-m"$side"||return1+done&&++(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+git-Csparse-indexconfigpull.twoheadort&&+ensure_not_expanded!merge-mmergedexpand-right+)+'+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout# in this scenario, but it shouldn't. test_expect_success'reset mixed and checkout orphan''
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:18
From: Derrick Stolee <redacted>
Add tests to check that cherry-pick and rebase behave the same in the
sparse-index case as in the full index cases. These tests are agnostic
to GIT_TEST_MERGE_ALGORITHM, so a full CI test suite will check both the
'ort' and 'recursive' strategies on this test.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
@@ -481,14 +481,17 @@ test_expect_success 'checkout and reset (mixed) [sparse]' 'test_sparse_matchgitresetupdate-folder2'-test_expect_success'merge''+test_expect_success'merge, cherry-pick, and rebase''init_repos&&-test_all_matchgitcheckout-bmergeupdate-deep&&-test_all_matchgitmerge-m"folder1"update-folder1&&-test_all_matchgitrev-parseHEAD^{tree}&&-test_all_matchgitmerge-m"folder2"update-folder2&&-test_all_matchgitrev-parseHEAD^{tree}+forOPERATIONin"merge -m merge"cherry-pickrebase+do+test_all_matchgitcheckout-Btempupdate-deep&&+test_all_matchgit$OPERATIONupdate-folder1&&+test_all_matchgitrev-parseHEAD^{tree}&&+test_all_matchgit$OPERATIONupdate-folder2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done'# NEEDSWORK: This test is documenting current behavior, but that
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:19
From: Derrick Stolee <redacted>
The sequencer is used by 'cherry-pick' and 'rebase' to sequence a list
of operations that modify the index. Since we intend to remove the need
for 'command_requires_full_index', we need to ensure the sparse index is
expanded every time it is written to disk between these steps. That is,
unless the merge strategy is 'ort' where the index can remain sparse
throughout.
There are two main places to be extra careful about a full index:
1. Right before calling merge_trees(), ensure the index is full. This
happens within an 'else' where the 'if' block checks if the 'ort'
strategy is selected.
2. During read_and_refresh_cache(), the index might be written to disk
and converted to sparse in the process. Ensure it expands back to
full afterwards by checking if the strategy is _not_ 'ort'. This
'if' statement is the logical negation of the 'if' in item (1).
Signed-off-by: Derrick Stolee <redacted>
---
sequencer.c | 9 +++++++++
1 file changed, 9 insertions(+)
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-08-24 21:53:20
From: Derrick Stolee <redacted>
The hard work was already done with 'git merge' and the ORT strategy.
Just add extra tests to see that we get the expected results in the
non-conflict cases.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/rebase.c | 6 ++++
builtin/revert.c | 3 ++
t/t1092-sparse-checkout-compatibility.sh | 39 ++++++++++++++++++++++--
3 files changed, 46 insertions(+), 2 deletions(-)
@@ -1430,6 +1433,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)usage_with_options(builtin_rebase_usage,builtin_rebase_options);+prepare_repo_settings(the_repository);+the_repository->settings.command_requires_full_index=0;+options.allow_empty_message=1;git_config(rebase_config,&options);/* options.gpg_sign_opt will be either "-S" or NULL */
@@ -527,6 +527,38 @@ test_expect_success 'merge with conflict outside cone' 'test_all_matchgitrev-parseHEAD^{tree}'+test_expect_success'cherry-pick/rebase with conflict outside cone''+init_repos&&++forOPERATIONincherry-pickrebase+do+test_all_matchgitcheckout-Btip&&+test_all_matchgitreset--hardmerge-left&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchtest_must_failgit$OPERATIONmerge-right&&+test_all_matchgitstatus--porcelain=v2&&++# Resolve the conflict in different ways:+# 1. Revert to the base+test_all_matchgitcheckoutbase--deep/deeper2/a&&+test_all_matchgitstatus--porcelain=v2&&++# 2. Add the file with conflict markers+test_all_matchgitaddfolder1/a&&+test_all_matchgitstatus--porcelain=v2&&++# 3. Rename the file to another sparse filename and+# accept conflict markers as resolved content.+run_on_allmvfolder2/afolder2/z&&+test_all_matchgitaddfolder2&&+test_all_matchgitstatus--porcelain=v2&&++test_all_matchgit$OPERATION--continue&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done+'+ test_expect_success'merge with outside renames''init_repos&&
@@ -665,8 +697,11 @@ test_expect_success 'sparse-index is not expanded' '(sane_unsetGIT_TEST_MERGE_ALGORITHM&&git-Csparse-indexconfigpull.twoheadort&&-ensure_not_expandedmerge-mmergeupdate-folder1&&-ensure_not_expandedmerge-mmergeupdate-folder2+forOPERATIONin"merge -m merge"cherry-pickrebase+do+ensure_not_expandedmerge-mmergeupdate-folder1&&+ensure_not_expandedmerge-mmergeupdate-folder2||return1+done)'
On Tue, Aug 24, 2021 at 11:30 AM Derrick Stolee [off-list ref] wrote:
On 8/20/2021 5:32 PM, Elijah Newren wrote:
quoted
On Tue, Aug 17, 2021 at 10:08 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete, especially when a conflict appears. In
order to avoid expanding a sparse index, the reuse_worktree_file() needs
to be adapted to ignore files that are outside of the sparse-checkout
cone. The file names and OIDs used for this check come from the merged
tree in the case of the ORT strategy, not the index, hence the ability
to look into these paths without having already expanded the index.
I'm confused; I thought the diffstat was only shown if the merge was
successful, in which case there would be no conflicts appearing.
That's my mistake. I'll edit the message accordingly.
quoted
Also, I'm not that familiar with the general diff machinery (just the
rename detection parts), but...if the diffstat only shows when the
merge is successful, wouldn't we be comparing two REVS (ORIG_HEAD to
HEAD)? Why would we make use of the working tree at all in such a
case? And, wouldn't using the working tree be dangerous...what if
there was a merge performed with a dirty working tree?
On a bit of a tangent, I know diffcore-rename.c calls into
diff_populate_filespec() as well, and I have some code doing merges in
a bare repository (where there obviously is no index). It seemed to
be working, but given this commit message, now I'm wondering if I've
missed something fundamental either in that implementation or there's
something amiss in this patch. Or both. Maybe I need to dig into
diff_populate_filespec() more, but it seems you already have. Any
pointers to orient me on why your changes are right here (and, if you
know, why diffcore-rename.c should or shouldn't be using
diff_populate_filespec() in a bare repo)?
I think the cases you are thinking about are covered by this
condition before the one I'm inserting:
/* We want to avoid the working directory if our caller
* doesn't need the data in a normal file, this system
* is rather slow with its stat/open/mmap/close syscalls,
* and the object is contained in a pack file. The pack
* is probably already open and will be faster to obtain
* the data through than the working directory. Loose
* objects however would tend to be slower as they need
* to be individually opened and inflated.
*/
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
return 0;
or after:
/*
* Similarly, if we'd have to convert the file contents anyway, that
* makes the optimization not worthwhile.
*/
if (!want_file && would_convert_to_git(istate, name))
return 0;
(This makes me think that I should move my new condition further down
so these two can be linked by context.)
Sounds like this is just an optimization, so it is fine to opt out of it
if we think the optimization isn't necessary. Outside of the sparse-checkout
cone qualifies.
Ah, this is very helpful. Thanks for digging up these details.
On Tue, Aug 24, 2021 at 2:52 PM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
From: Derrick Stolee <redacted>
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:
1. If the merge strategy is 'recursive', then we enable
command_requires_full_index at the start of the merge_recursive()
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
2. With the 'ort' strategy, if the merge results in a conflicted file,
then we expand the index before updating the working tree. The loop
that iterates over the worktree replaces index entries and tracks
'origintal_cache_nr' which can become completely wrong if the index
expands in the middle of the operation. This safety valve is
important before that loop starts. A later change will focus this
to only expand if we indeed have a conflict outside of the
sparse-checkout cone.
3. Other merge strategies are executed as a 'git merge-X' subcommand,
and those strategies are currently protected with the
'command_requires_full_index' guard.
Oh, indeed, it appears ag/merge-strategies-in-c didn't complete but
was discarded, as per the July 6 "What's cooking in git.git" email.
Well, that certainly makes things easier for you; thanks for
mentioning them in this item #3.
quoted hunk
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/merge.c | 3 +++
merge-ort.c | 8 ++++++++
merge-recursive.c | 3 +++
t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++--
4 files changed, 24 insertions(+), 2 deletions(-)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)if(strmap_empty(&opt->priv->conflicted))return0;+/*+*Weareinaconflictedstate.Theseconflictsmightbeinside+*sparse-directoryentries,soexpandtheindexpreemtively.
Same typo I pointed out in v1.
quoted hunk
+ * Also, we set original_cache_nr below, but that might change if
+ * index_name_pos() calls ask for paths within sparse directories.
+ */
+ ensure_full_index(index);
+
/* If any entries have skip_worktree set, we'll have to check 'em out */
state.force = 1;
state.quiet = 1;
@@ -647,7 +647,15 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/extra.txt&&ensure_not_expandedaddextra.txt&&echo>>sparse-index/untracked.txt&&-ensure_not_expandedadd.+ensure_not_expandedadd.&&++ensure_not_expandedcheckout-fupdate-deep&&+(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+git-Csparse-indexconfigpull.twoheadort&&+ensure_not_expandedmerge-mmergeupdate-folder1&&+ensure_not_expandedmerge-mmergeupdate-folder2+)'
Should you use test_config rather than git config here?
More importantly, why the subshell and unsetting of
GIT_TEST_MERGE_ALGORITHM and the special worrying about pull.twohead?
Wouldn't it be simpler to just set GIT_TEST_MERGE_ALGORITHM=ort,
perhaps at the beginning of the file?
On Tue, Aug 24, 2021 at 2:52 PM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted hunk
From: Derrick Stolee <redacted>
Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.
Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.
Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.
Signed-off-by: Derrick Stolee <redacted>
---
merge-ort.c | 13 +++++++---
t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++--
2 files changed, 38 insertions(+), 5 deletions(-)
@@ -4060,11 +4060,18 @@ static int record_conflicted_index_entries(struct merge_options *opt)/**Weareinaconflictedstate.Theseconflictsmightbeinside-*sparse-directoryentries,soexpandtheindexpreemtively.-*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*sparse-directoryentries,socheckifanyentriesareoutside+*ofthesparse-checkoutconepreemptively.+*+*Wesetoriginal_cache_nrbelow,butthatmightchangeif*index_name_pos()callsaskforpathswithinsparsedirectories.*/-ensure_full_index(index);+strmap_for_each_entry(&opt->priv->conflicted,&iter,e){+if(!path_in_sparse_checkout(e->key,index)){+ensure_full_index(index);+break;+}+}/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;
@@ -617,8 +617,17 @@ test_expect_success 'sparse-index is expanded and converted back' ' ensure_not_expanded(){rm-ftrace2.txt&&echo>>sparse-index/untracked.txt&&-GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\-git-Csparse-index"$@"&&++iftest"$1"="!"+then+shift&&+test_must_failenv\+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+else+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+fi&&test_region!indexensure_full_indextrace2.txt}
@@ -658,6 +667,23 @@ test_expect_success 'sparse-index is not expanded' ')'+test_expect_success'sparse-index is not expanded: merge conflict in cone''+init_repos&&++forsideinrightleft+do+git-Csparse-indexcheckout-bexpand-$sidebase&&+echo$side>sparse-index/deep/a&&+git-Csparse-indexcommit-a-m"$side"||return1+done&&++(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+git-Csparse-indexconfigpull.twoheadort&&+ensure_not_expanded!merge-mmergedexpand-right+)
These last five lines could just be replaced with the fourth, if you
just set GIT_TEST_MERGE_ALGORITHM=ort at the beginning of the file.
Are you worrying about testing with recursive in some of the testcases?
On Tue, Aug 24, 2021 at 2:52 PM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
This series integrates the sparse index with commands that perform merges
such as 'git merge', 'git cherry-pick', 'git revert' (free with
cherry-pick), and 'git rebase'.
When the ORT merge strategy is enabled, this allows most merges to succeed
without expanding the sparse index, leading to significant performance
gains. I tested these changes against an internal monorepo with over 2
million paths at HEAD but with a sparse-checkout that only has ~60,000 files
within the sparse-checkout cone. 'git merge' commands went from 5-6 seconds
to 0.750-1.250s.
In the case of the recursive merge strategy, the sparse index is expanded
before the recursive algorithm proceeds. We expect that this is as good as
we can get with that strategy. When the strategy shifts to ORT as the
default, then this will not be a problem except for users who decide to
change the behavior.
Most of the hard work was done by previous series, such as
ds/sparse-index-ignored-files (which this series is based on).
Updates in V2
=============
* The tests no longer specify GIT_TEST_MERGE_ALGORITHM or directly
reference "-s ort". By relaxing this condition, I found an issue with
'git cherry-pick' and 'git rebase' when using the 'recursive' algorithm
which is fixed in a new patch.
* Use the pul.twohead config to specify the ORT merge algorithm to avoid
expanding the sparse index when that is what we are testing.
pull.twohead, not pul.twohead.
I'm curious, though, why use it instead of just setting
GIT_TEST_MERGE_ALGORITHM=ort? That'd seem to avoid the need for the
explicit subshells and the sane_unset calls.
* Corrected some misstatements in my commit messages.
I read over v2. Other than some minor questions about whether using
GIT_TEST_MERGE_ALGORITHM=ort would be easier, and a typo still present
from v1, the series looks good to me.
Should you use test_config rather than git config here?
That's a better pattern. It's not technically _required_ for these
tests because the repositories are completely rewritten at the start
of each new test, but it's best to be a good example.
More importantly, why the subshell and unsetting of
GIT_TEST_MERGE_ALGORITHM and the special worrying about pull.twohead?
Wouldn't it be simpler to just set GIT_TEST_MERGE_ALGORITHM=ort,
perhaps at the beginning of the file?
I don't set GIT_TEST_MERGE_ALGORITHM at the beginning of the file so
the rest of the tests are covered with both 'ort' and 'recursive' in
the CI test suite.
Using the config more carefully matches how I expect the 'ort'
strategy to be specified in practice (very temporarily, as it will
soon be the default).
Thanks,
-Stolee
These last five lines could just be replaced with the fourth, if you
just set GIT_TEST_MERGE_ALGORITHM=ort at the beginning of the file.
Are you worrying about testing with recursive in some of the testcases?
Yes. In fact, since I _stopped_ setting GIT_TEST_MERGE_ALGORITHM at the
start of the file since the previous version, I found and fixed a bug
which forms the new Patch 5 (sequencer: ensure full index if not ORT
strategy).
Thanks,
-Stolee
On Tue, Aug 24, 2021 at 2:52 PM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
quoted
...
quoted
Updates in V2
=============
* The tests no longer specify GIT_TEST_MERGE_ALGORITHM or directly
reference "-s ort". By relaxing this condition, I found an issue with
'git cherry-pick' and 'git rebase' when using the 'recursive' algorithm
which is fixed in a new patch.
This describes why the tests no longer use GIT_TEST_MERGE_ALGORITHM at
the top. It improves coverage in case users opt-out of ORT. Instead,
quoted
* Use the pul.twohead config to specify the ORT merge algorithm to avoid
expanding the sparse index when that is what we are testing.
pull.twohead, not pul.twohead.
We use this config option to specify when we _really care_ about the ORT
strategy as it is necessary to avoid expanding the full index.
I'm curious, though, why use it instead of just setting
GIT_TEST_MERGE_ALGORITHM=ort? That'd seem to avoid the need for the
explicit subshells and the sane_unset calls.
quoted
* Corrected some misstatements in my commit messages.
I read over v2. Other than some minor questions about whether using
GIT_TEST_MERGE_ALGORITHM=ort would be easier, and a typo still present
from v1, the series looks good to me.
Sorry about the typo, as I fixed it in Patch 3 but not Patch 2. I will
fix these in v3 after I send a v5 of the ignored files series.
Thanks,
-Stolee
Should you use test_config rather than git config here?
That's a better pattern. It's not technically _required_ for these
tests because the repositories are completely rewritten at the start
of each new test, but it's best to be a good example.
Actually, test_config runs test_when_finished, and that results in
the following message and failure on macOS and Windows:
BUG 'test_when_finished does nothing in a subshell'
So, I'll leave this as-is.
Thanks,
-Stolee
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:06
This series integrates the sparse index with commands that perform merges
such as 'git merge', 'git cherry-pick', 'git revert' (free with
cherry-pick), and 'git rebase'.
When the ORT merge strategy is enabled, this allows most merges to succeed
without expanding the sparse index, leading to significant performance
gains. I tested these changes against an internal monorepo with over 2
million paths at HEAD but with a sparse-checkout that only has ~60,000 files
within the sparse-checkout cone. 'git merge' commands went from 5-6 seconds
to 0.750-1.250s.
In the case of the recursive merge strategy, the sparse index is expanded
before the recursive algorithm proceeds. We expect that this is as good as
we can get with that strategy. When the strategy shifts to ORT as the
default, then this will not be a problem except for users who decide to
change the behavior.
Most of the hard work was done by previous series, such as
ds/sparse-index-ignored-files (which this series is based on).
Updates in V3
=============
* Fixed a typo in patch 2 (it is then moved in patch 3, affecting the
range-diff)
* There was a recommendation to use test_config over git config, but that
is not possible in a subshell. So, it got moved outside of the subshell
and that works just fine.
* The other comments were about the use of GIT_TEST_MERGE_ALGORITHM in the
test script, but the tests that isolate that environment variable are
only for the 'ensure_not_expanded' tests, not the rest of the tests that
already exist and are beneficial to cover the 'recursive' mode.
Updates in V2
=============
* The tests no longer specify GIT_TEST_MERGE_ALGORITHM or directly
reference "-s ort". By relaxing this condition, I found an issue with
'git cherry-pick' and 'git rebase' when using the 'recursive' algorithm
which is fixed in a new patch.
* Use the pull.twohead config to specify the ORT merge algorithm to avoid
expanding the sparse index when that is what we are testing.
* Corrected some misstatements in my commit messages.
Thanks, -Stolee
Derrick Stolee (6):
diff: ignore sparse paths in diffstat
merge: make sparse-aware with ORT
merge-ort: expand only for out-of-cone conflicts
t1092: add cherry-pick, rebase tests
sequencer: ensure full index if not ORT strategy
sparse-index: integrate with cherry-pick and rebase
builtin/merge.c | 3 +
builtin/rebase.c | 6 ++
builtin/revert.c | 3 +
diff.c | 8 +++
merge-ort.c | 15 ++++
merge-recursive.c | 3 +
sequencer.c | 9 +++
t/t1092-sparse-checkout-compatibility.sh | 92 +++++++++++++++++++++---
8 files changed, 129 insertions(+), 10 deletions(-)
base-commit: 91b53f20109fe55635b1815f87afd5d5da68a182
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1019%2Fderrickstolee%2Fsparse-index%2Fmerge-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1019/derrickstolee/sparse-index/merge-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1019
Range-diff vs v2:
1: c5ae705648c = 1: a6963182fe0 diff: ignore sparse paths in diffstat
2: bb150483bcf ! 2: 141f7fb26d6 merge: make sparse-aware with ORT
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *op
+ /*
+ * We are in a conflicted state. These conflicts might be inside
-+ * sparse-directory entries, so expand the index preemtively.
++ * sparse-directory entries, so expand the index preemptively.
+ * Also, we set original_cache_nr below, but that might change if
+ * index_name_pos() calls ask for paths within sparse directories.
+ */
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n
+ ensure_not_expanded add . &&
+
+ ensure_not_expanded checkout -f update-deep &&
++ test_config -C sparse-index pull.twohead ort &&
+ (
+ sane_unset GIT_TEST_MERGE_ALGORITHM &&
-+ git -C sparse-index config pull.twohead ort &&
+ ensure_not_expanded merge -m merge update-folder1 &&
+ ensure_not_expanded merge -m merge update-folder2
+ )
3: 815b1b1cfbf ! 3: c3c9ffd855c merge-ort: expand only for out-of-cone conflicts
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *op
/*
* We are in a conflicted state. These conflicts might be inside
-- * sparse-directory entries, so expand the index preemtively.
+- * sparse-directory entries, so expand the index preemptively.
- * Also, we set original_cache_nr below, but that might change if
+ * sparse-directory entries, so check if any entries are outside
+ * of the sparse-checkout cone preemptively.
4: 8032154bc8a = 4: 7aae5727fb7 t1092: add cherry-pick, rebase tests
5: 90ac85500b8 = 5: 20f5bbae546 sequencer: ensure full index if not ORT strategy
6: df4bbec744f ! 6: 36cecb22330 sparse-index: integrate with cherry-pick and rebase
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'merge with confli
init_repos &&
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is not expanded' '
+ test_config -C sparse-index pull.twohead ort &&
(
sane_unset GIT_TEST_MERGE_ALGORITHM &&
- git -C sparse-index config pull.twohead ort &&
- ensure_not_expanded merge -m merge update-folder1 &&
- ensure_not_expanded merge -m merge update-folder2
+ for OPERATION in "merge -m merge" cherry-pick rebase
--
gitgitgadget
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:07
From: Derrick Stolee <redacted>
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete. In order to avoid expanding a sparse index,
the reuse_worktree_file() needs to be adapted to ignore files that are
outside of the sparse-checkout cone. The file names and OIDs used for
this check come from the merged tree in the case of the ORT strategy,
not the index, hence the ability to look into these paths without having
already expanded the index.
The work done by reuse_worktree_file() is only an optimization, and
requires the file being on disk for it to be of any value. Thus, it is
safe to exit the method early if we do not expect the file on disk.
Signed-off-by: Derrick Stolee <redacted>
---
diff.c | 8 ++++++++
1 file changed, 8 insertions(+)
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:08
From: Derrick Stolee <redacted>
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:
1. If the merge strategy is 'recursive', then we enable
command_requires_full_index at the start of the merge_recursive()
method. We expect sparse-index users to also have the 'ort' strategy
enabled.
2. With the 'ort' strategy, if the merge results in a conflicted file,
then we expand the index before updating the working tree. The loop
that iterates over the worktree replaces index entries and tracks
'origintal_cache_nr' which can become completely wrong if the index
expands in the middle of the operation. This safety valve is
important before that loop starts. A later change will focus this
to only expand if we indeed have a conflict outside of the
sparse-checkout cone.
3. Other merge strategies are executed as a 'git merge-X' subcommand,
and those strategies are currently protected with the
'command_requires_full_index' guard.
Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/merge.c | 3 +++
merge-ort.c | 8 ++++++++
merge-recursive.c | 3 +++
t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++--
4 files changed, 24 insertions(+), 2 deletions(-)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)if(strmap_empty(&opt->priv->conflicted))return0;+/*+*Weareinaconflictedstate.Theseconflictsmightbeinside+*sparse-directoryentries,soexpandtheindexpreemptively.+*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*index_name_pos()callsaskforpathswithinsparsedirectories.+*/+ensure_full_index(index);+/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;state.quiet=1;
@@ -647,7 +647,15 @@ test_expect_success 'sparse-index is not expanded' 'echo>>sparse-index/extra.txt&&ensure_not_expandedaddextra.txt&&echo>>sparse-index/untracked.txt&&-ensure_not_expandedadd.+ensure_not_expandedadd.&&++ensure_not_expandedcheckout-fupdate-deep&&+test_config-Csparse-indexpull.twoheadort&&+(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+ensure_not_expandedmerge-mmergeupdate-folder1&&+ensure_not_expandedmerge-mmergeupdate-folder2+)'# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:10
From: Derrick Stolee <redacted>
Add tests to check that cherry-pick and rebase behave the same in the
sparse-index case as in the full index cases. These tests are agnostic
to GIT_TEST_MERGE_ALGORITHM, so a full CI test suite will check both the
'ort' and 'recursive' strategies on this test.
Signed-off-by: Derrick Stolee <redacted>
---
t/t1092-sparse-checkout-compatibility.sh | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
@@ -481,14 +481,17 @@ test_expect_success 'checkout and reset (mixed) [sparse]' 'test_sparse_matchgitresetupdate-folder2'-test_expect_success'merge''+test_expect_success'merge, cherry-pick, and rebase''init_repos&&-test_all_matchgitcheckout-bmergeupdate-deep&&-test_all_matchgitmerge-m"folder1"update-folder1&&-test_all_matchgitrev-parseHEAD^{tree}&&-test_all_matchgitmerge-m"folder2"update-folder2&&-test_all_matchgitrev-parseHEAD^{tree}+forOPERATIONin"merge -m merge"cherry-pickrebase+do+test_all_matchgitcheckout-Btempupdate-deep&&+test_all_matchgit$OPERATIONupdate-folder1&&+test_all_matchgitrev-parseHEAD^{tree}&&+test_all_matchgit$OPERATIONupdate-folder2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done'# NEEDSWORK: This test is documenting current behavior, but that
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:10
From: Derrick Stolee <redacted>
Merge conflicts happen often enough to want to avoid expanding a sparse
index when they happen, as long as those conflicts are within the
sparse-checkout cone. If a conflict exists outside of the
sparse-checkout cone, then we still need to expand before iterating over
the index entries. This is critical to do in advance because of how the
original_cache_nr is tracked to allow inserting and replacing cache
entries.
Iterate over the conflicted files and check if any paths are outside of
the sparse-checkout cone. If so, then expand the full index.
Add a test that demonstrates that we do not expand the index, even when
we hit a conflict within the sparse-checkout cone.
Signed-off-by: Derrick Stolee <redacted>
---
merge-ort.c | 13 +++++++---
t/t1092-sparse-checkout-compatibility.sh | 30 ++++++++++++++++++++++--
2 files changed, 38 insertions(+), 5 deletions(-)
@@ -4060,11 +4060,18 @@ static int record_conflicted_index_entries(struct merge_options *opt)/**Weareinaconflictedstate.Theseconflictsmightbeinside-*sparse-directoryentries,soexpandtheindexpreemptively.-*Also,wesetoriginal_cache_nrbelow,butthatmightchangeif+*sparse-directoryentries,socheckifanyentriesareoutside+*ofthesparse-checkoutconepreemptively.+*+*Wesetoriginal_cache_nrbelow,butthatmightchangeif*index_name_pos()callsaskforpathswithinsparsedirectories.*/-ensure_full_index(index);+strmap_for_each_entry(&opt->priv->conflicted,&iter,e){+if(!path_in_sparse_checkout(e->key,index)){+ensure_full_index(index);+break;+}+}/* If any entries have skip_worktree set, we'll have to check 'em out */state.force=1;
@@ -617,8 +617,17 @@ test_expect_success 'sparse-index is expanded and converted back' ' ensure_not_expanded(){rm-ftrace2.txt&&echo>>sparse-index/untracked.txt&&-GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\-git-Csparse-index"$@"&&++iftest"$1"="!"+then+shift&&+test_must_failenv\+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+else+GIT_TRACE2_EVENT="$(pwd)/trace2.txt"GIT_TRACE2_EVENT_NESTING=10\+git-Csparse-index"$@"||return1+fi&&test_region!indexensure_full_indextrace2.txt}
@@ -658,6 +667,23 @@ test_expect_success 'sparse-index is not expanded' ')'+test_expect_success'sparse-index is not expanded: merge conflict in cone''+init_repos&&++forsideinrightleft+do+git-Csparse-indexcheckout-bexpand-$sidebase&&+echo$side>sparse-index/deep/a&&+git-Csparse-indexcommit-a-m"$side"||return1+done&&++(+sane_unsetGIT_TEST_MERGE_ALGORITHM&&+git-Csparse-indexconfigpull.twoheadort&&+ensure_not_expanded!merge-mmergedexpand-right+)+'+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout# in this scenario, but it shouldn't. test_expect_success'reset mixed and checkout orphan''
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:11
From: Derrick Stolee <redacted>
The sequencer is used by 'cherry-pick' and 'rebase' to sequence a list
of operations that modify the index. Since we intend to remove the need
for 'command_requires_full_index', we need to ensure the sparse index is
expanded every time it is written to disk between these steps. That is,
unless the merge strategy is 'ort' where the index can remain sparse
throughout.
There are two main places to be extra careful about a full index:
1. Right before calling merge_trees(), ensure the index is full. This
happens within an 'else' where the 'if' block checks if the 'ort'
strategy is selected.
2. During read_and_refresh_cache(), the index might be written to disk
and converted to sparse in the process. Ensure it expands back to
full afterwards by checking if the strategy is _not_ 'ort'. This
'if' statement is the logical negation of the 'if' in item (1).
Signed-off-by: Derrick Stolee <redacted>
---
sequencer.c | 9 +++++++++
1 file changed, 9 insertions(+)
From: Derrick Stolee via GitGitGadget <hidden> Date: 2021-09-08 11:24:14
From: Derrick Stolee <redacted>
The hard work was already done with 'git merge' and the ORT strategy.
Just add extra tests to see that we get the expected results in the
non-conflict cases.
Signed-off-by: Derrick Stolee <redacted>
---
builtin/rebase.c | 6 ++++
builtin/revert.c | 3 ++
t/t1092-sparse-checkout-compatibility.sh | 39 ++++++++++++++++++++++--
3 files changed, 46 insertions(+), 2 deletions(-)
@@ -1430,6 +1433,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)usage_with_options(builtin_rebase_usage,builtin_rebase_options);+prepare_repo_settings(the_repository);+the_repository->settings.command_requires_full_index=0;+options.allow_empty_message=1;git_config(rebase_config,&options);/* options.gpg_sign_opt will be either "-S" or NULL */
@@ -527,6 +527,38 @@ test_expect_success 'merge with conflict outside cone' 'test_all_matchgitrev-parseHEAD^{tree}'+test_expect_success'cherry-pick/rebase with conflict outside cone''+init_repos&&++forOPERATIONincherry-pickrebase+do+test_all_matchgitcheckout-Btip&&+test_all_matchgitreset--hardmerge-left&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchtest_must_failgit$OPERATIONmerge-right&&+test_all_matchgitstatus--porcelain=v2&&++# Resolve the conflict in different ways:+# 1. Revert to the base+test_all_matchgitcheckoutbase--deep/deeper2/a&&+test_all_matchgitstatus--porcelain=v2&&++# 2. Add the file with conflict markers+test_all_matchgitaddfolder1/a&&+test_all_matchgitstatus--porcelain=v2&&++# 3. Rename the file to another sparse filename and+# accept conflict markers as resolved content.+run_on_allmvfolder2/afolder2/z&&+test_all_matchgitaddfolder2&&+test_all_matchgitstatus--porcelain=v2&&++test_all_matchgit$OPERATION--continue&&+test_all_matchgitstatus--porcelain=v2&&+test_all_matchgitrev-parseHEAD^{tree}||return1+done+'+ test_expect_success'merge with outside renames''init_repos&&
@@ -665,8 +697,11 @@ test_expect_success 'sparse-index is not expanded' 'test_config-Csparse-indexpull.twoheadort&&(sane_unsetGIT_TEST_MERGE_ALGORITHM&&-ensure_not_expandedmerge-mmergeupdate-folder1&&-ensure_not_expandedmerge-mmergeupdate-folder2+forOPERATIONin"merge -m merge"cherry-pickrebase+do+ensure_not_expandedmerge-mmergeupdate-folder1&&+ensure_not_expandedmerge-mmergeupdate-folder2||return1+done)'
On Wed, Sep 8, 2021 at 4:24 AM Derrick Stolee via GitGitGadget
[off-list ref] wrote:
This series integrates the sparse index with commands that perform merges
such as 'git merge', 'git cherry-pick', 'git revert' (free with
cherry-pick), and 'git rebase'.
When the ORT merge strategy is enabled, this allows most merges to succeed
without expanding the sparse index, leading to significant performance
gains. I tested these changes against an internal monorepo with over 2
million paths at HEAD but with a sparse-checkout that only has ~60,000 files
within the sparse-checkout cone. 'git merge' commands went from 5-6 seconds
to 0.750-1.250s.
In the case of the recursive merge strategy, the sparse index is expanded
before the recursive algorithm proceeds. We expect that this is as good as
we can get with that strategy. When the strategy shifts to ORT as the
default, then this will not be a problem except for users who decide to
change the behavior.
Most of the hard work was done by previous series, such as
ds/sparse-index-ignored-files (which this series is based on).
Updates in V3
=============
* Fixed a typo in patch 2 (it is then moved in patch 3, affecting the
range-diff)
* There was a recommendation to use test_config over git config, but that
is not possible in a subshell. So, it got moved outside of the subshell
and that works just fine.
* The other comments were about the use of GIT_TEST_MERGE_ALGORITHM in the
test script, but the tests that isolate that environment variable are
only for the 'ensure_not_expanded' tests, not the rest of the tests that
already exist and are beneficial to cover the 'recursive' mode.
This round addresses all my feedback and looks good to me:
Reviewed-by: Elijah Newren <redacted>
Updates in V2
=============
* The tests no longer specify GIT_TEST_MERGE_ALGORITHM or directly
reference "-s ort". By relaxing this condition, I found an issue with
'git cherry-pick' and 'git rebase' when using the 'recursive' algorithm
which is fixed in a new patch.
* Use the pull.twohead config to specify the ORT merge algorithm to avoid
expanding the sparse index when that is what we are testing.
* Corrected some misstatements in my commit messages.
Thanks, -Stolee
Derrick Stolee (6):
diff: ignore sparse paths in diffstat
merge: make sparse-aware with ORT
merge-ort: expand only for out-of-cone conflicts
t1092: add cherry-pick, rebase tests
sequencer: ensure full index if not ORT strategy
sparse-index: integrate with cherry-pick and rebase
builtin/merge.c | 3 +
builtin/rebase.c | 6 ++
builtin/revert.c | 3 +
diff.c | 8 +++
merge-ort.c | 15 ++++
merge-recursive.c | 3 +
sequencer.c | 9 +++
t/t1092-sparse-checkout-compatibility.sh | 92 +++++++++++++++++++++---
8 files changed, 129 insertions(+), 10 deletions(-)
base-commit: 91b53f20109fe55635b1815f87afd5d5da68a182
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1019%2Fderrickstolee%2Fsparse-index%2Fmerge-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1019/derrickstolee/sparse-index/merge-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1019
Range-diff vs v2:
1: c5ae705648c = 1: a6963182fe0 diff: ignore sparse paths in diffstat
2: bb150483bcf ! 2: 141f7fb26d6 merge: make sparse-aware with ORT
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *op
+ /*
+ * We are in a conflicted state. These conflicts might be inside
-+ * sparse-directory entries, so expand the index preemtively.
++ * sparse-directory entries, so expand the index preemptively.
+ * Also, we set original_cache_nr below, but that might change if
+ * index_name_pos() calls ask for paths within sparse directories.
+ */
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is n
+ ensure_not_expanded add . &&
+
+ ensure_not_expanded checkout -f update-deep &&
++ test_config -C sparse-index pull.twohead ort &&
+ (
+ sane_unset GIT_TEST_MERGE_ALGORITHM &&
-+ git -C sparse-index config pull.twohead ort &&
+ ensure_not_expanded merge -m merge update-folder1 &&
+ ensure_not_expanded merge -m merge update-folder2
+ )
3: 815b1b1cfbf ! 3: c3c9ffd855c merge-ort: expand only for out-of-cone conflicts
@@ merge-ort.c: static int record_conflicted_index_entries(struct merge_options *op
/*
* We are in a conflicted state. These conflicts might be inside
-- * sparse-directory entries, so expand the index preemtively.
+- * sparse-directory entries, so expand the index preemptively.
- * Also, we set original_cache_nr below, but that might change if
+ * sparse-directory entries, so check if any entries are outside
+ * of the sparse-checkout cone preemptively.
4: 8032154bc8a = 4: 7aae5727fb7 t1092: add cherry-pick, rebase tests
5: 90ac85500b8 = 5: 20f5bbae546 sequencer: ensure full index if not ORT strategy
6: df4bbec744f ! 6: 36cecb22330 sparse-index: integrate with cherry-pick and rebase
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'merge with confli
init_repos &&
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is not expanded' '
+ test_config -C sparse-index pull.twohead ort &&
(
sane_unset GIT_TEST_MERGE_ALGORITHM &&
- git -C sparse-index config pull.twohead ort &&
- ensure_not_expanded merge -m merge update-folder1 &&
- ensure_not_expanded merge -m merge update-folder2
+ for OPERATION in "merge -m merge" cherry-pick rebase
--
gitgitgadget