Skip to content
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

[Sparse Index] Integrate with git commit and git checkout #361

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ static int checkout_worktree(const struct checkout_opts *opts,
if (pc_workers > 1)
init_parallel_checkout();

/* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index);

enable_fscache(active_nr);
for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos];
Expand Down Expand Up @@ -533,8 +530,6 @@ static int checkout_paths(const struct checkout_opts *opts,
* Make sure all pathspecs participated in locating the paths
* to be checked out.
*/
/* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index);
for (pos = 0; pos < active_nr; pos++)
if (opts->overlay_mode)
mark_ce_for_checkout_overlay(active_cache[pos],
Expand Down Expand Up @@ -1604,6 +1599,9 @@ static int checkout_main(int argc, const char **argv, const char *prefix,

git_config(git_checkout_config, opts);

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

opts->track = BRANCH_TRACK_UNSPECIFIED;

if (!opts->accept_pathspec && !opts->accept_ref)
Expand Down
3 changes: 3 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_commit_usage, builtin_commit_options);

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;

status_init_config(&s, git_commit_config);
s.commit_template = 1;
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
Expand Down
2 changes: 0 additions & 2 deletions cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,6 @@ int cache_tree_update(struct index_state *istate, int flags)
if (i)
return i;

ensure_full_index(istate);

if (!istate->cache_tree)
istate->cache_tree = cache_tree();

Expand Down
47 changes: 30 additions & 17 deletions t/perf/p2000-sparse-operations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_description="test performance of Git operations using the index"

test_perf_default_repo

SPARSE_CONE=f2/f4/f1
SPARSE_CONE=f2/f4

test_expect_success 'setup repo and indexes' '
git reset --hard HEAD &&
Expand All @@ -27,7 +27,7 @@ test_expect_success 'setup repo and indexes' '
OLD_COMMIT=$(git rev-parse HEAD) &&
OLD_TREE=$(git rev-parse HEAD^{tree}) &&

for i in $(test_seq 1 4)
for i in $(test_seq 1 3)
do
cat >in <<-EOF &&
100755 blob $BLOB a
Expand All @@ -43,45 +43,57 @@ test_expect_success 'setup repo and indexes' '
done &&

git sparse-checkout init --cone &&
git branch -f wide $OLD_COMMIT &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-index-v3 &&
git sparse-checkout set $SPARSE_CONE &&
git checkout -b wide $OLD_COMMIT &&

for l2 in f1 f2 f3 f4
do
echo more bogus >>$SPARSE_CONE/$l2/a &&
git commit -a -m "edit $SPARSE_CONE/$l2/a" || return 1
done &&

git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v3 &&
(
cd full-index-v3 &&
cd full-v3 &&
git sparse-checkout init --cone &&
git sparse-checkout set $SPARSE_CONE &&
git config index.version 3 &&
git update-index --index-version=3
git update-index --index-version=3 &&
git checkout HEAD~4
) &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-index-v4 &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . full-v4 &&
(
cd full-index-v4 &&
cd full-v4 &&
git sparse-checkout init --cone &&
git sparse-checkout set $SPARSE_CONE &&
git config index.version 4 &&
git update-index --index-version=4
git update-index --index-version=4 &&
git checkout HEAD~4
) &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-index-v3 &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v3 &&
(
cd sparse-index-v3 &&
cd sparse-v3 &&
git sparse-checkout init --cone --sparse-index &&
git sparse-checkout set $SPARSE_CONE &&
git config index.version 3 &&
git update-index --index-version=3
git update-index --index-version=3 &&
git checkout HEAD~4
) &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-index-v4 &&
git -c core.sparseCheckoutCone=true clone --branch=wide --sparse . sparse-v4 &&
(
cd sparse-index-v4 &&
cd sparse-v4 &&
git sparse-checkout init --cone --sparse-index &&
git sparse-checkout set $SPARSE_CONE &&
git config index.version 4 &&
git update-index --index-version=4
git update-index --index-version=4 &&
git checkout HEAD~4
)
'

test_perf_on_all () {
command="$@"
for repo in full-index-v3 full-index-v4 \
sparse-index-v3 sparse-index-v4
for repo in full-v3 full-v4 \
sparse-v3 sparse-v4
do
test_perf "$command ($repo)" "
(
Expand All @@ -97,5 +109,6 @@ test_perf_on_all git status
test_perf_on_all git add -A
test_perf_on_all git add .
test_perf_on_all git commit -a -m A
test_perf_on_all git checkout -f -

test_done
55 changes: 51 additions & 4 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,34 @@ test_expect_success 'add, commit, checkout' '
test_all_match git checkout -
'

test_expect_success 'commit including unstaged changes' '
init_repos &&

write_script edit-file <<-\EOF &&
echo $1 >$2
EOF

run_on_all ../edit-file 1 a &&
run_on_all ../edit-file 1 deep/a &&

test_all_match git commit -m "-a" -a &&
test_all_match git status --porcelain=v2 &&

run_on_all ../edit-file 2 a &&
run_on_all ../edit-file 2 deep/a &&

test_all_match git commit -m "--include" --include deep/a &&
test_all_match git status --porcelain=v2 &&
test_all_match git commit -m "--include" --include a &&
test_all_match git status --porcelain=v2 &&

run_on_all ../edit-file 3 a &&
run_on_all ../edit-file 3 deep/a &&

test_all_match git commit -m "--amend" -a --amend &&
test_all_match git status --porcelain=v2
'

test_expect_success 'status/add: outside sparse cone' '
init_repos &&

Expand Down Expand Up @@ -513,14 +541,33 @@ test_expect_success 'sparse-index is expanded and converted back' '
test_region index ensure_full_index trace2.txt
'

test_expect_success 'sparse-index is not expanded' '
init_repos &&

ensure_not_expanded () {
rm -f trace2.txt &&
echo >>sparse-index/untracked.txt &&
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index status &&
git -C sparse-index "$@" &&
test_region ! index ensure_full_index trace2.txt
}

test_expect_success 'sparse-index is not expanded' '
init_repos &&

ensure_not_expanded status &&
ensure_not_expanded commit --allow-empty -m empty &&
echo >>sparse-index/a &&
ensure_not_expanded commit -a -m a &&
echo >>sparse-index/a &&
ensure_not_expanded commit --include a -m a &&
echo >>sparse-index/deep/deeper1/a &&
ensure_not_expanded commit --include deep/deeper1/a -m deeper &&
ensure_not_expanded checkout rename-out-to-out &&
ensure_not_expanded checkout - &&
ensure_not_expanded switch rename-out-to-out &&
ensure_not_expanded switch - &&
git -C sparse-index reset --hard &&
ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
git -C sparse-index reset --hard &&
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1
'

test_expect_success 'reset mixed and checkout orphan' '
Expand Down