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] Enable index.sparse by default #388

10 changes: 5 additions & 5 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ enum pattern_match_result path_matches_pattern_list(
struct path_pattern *pattern;
struct strbuf parent_pathname = STRBUF_INIT;
int result = NOT_MATCHED;
const char *slash_pos;
size_t slash_pos;

/*
* The virtual file system data is used to prevent git from traversing
Expand Down Expand Up @@ -1461,10 +1461,10 @@ enum pattern_match_result path_matches_pattern_list(
*/
if (parent_pathname.len > 0 &&
parent_pathname.buf[parent_pathname.len - 1] == '/') {
slash_pos = parent_pathname.buf + parent_pathname.len - 1;
slash_pos = parent_pathname.len - 1;
strbuf_add(&parent_pathname, "-", 1);
} else {
slash_pos = strrchr(parent_pathname.buf, '/');
slash_pos = strrchr(parent_pathname.buf, '/') - parent_pathname.buf;
derrickstolee marked this conversation as resolved.
Show resolved Hide resolved
}

if (hashmap_contains_path(&pl->recursive_hashmap,
Expand All @@ -1473,13 +1473,13 @@ enum pattern_match_result path_matches_pattern_list(
goto done;
}

if (slash_pos == parent_pathname.buf) {
if (!slash_pos) {
/* include every file in root */
result = MATCHED;
goto done;
}

strbuf_setlen(&parent_pathname, slash_pos - parent_pathname.buf);
strbuf_setlen(&parent_pathname, slash_pos);

if (hashmap_contains_path(&pl->parent_hashmap, &parent_pathname)) {
result = MATCHED;
Expand Down
8 changes: 4 additions & 4 deletions repo-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void prepare_repo_settings(struct repository *r)
r->settings.command_requires_full_index = 1;

/*
* Initialize this as off.
* Initialize this as on.
*/
r->settings.sparse_index = 0;
if (!repo_config_get_bool(r, "index.sparse", &value) && value)
r->settings.sparse_index = 1;
r->settings.sparse_index = 1;
if (!repo_config_get_bool(r, "index.sparse", &value) && !value)
r->settings.sparse_index = 0;
}
19 changes: 13 additions & 6 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int set_sparse_index_config(struct repository *repo, int enable)
char *config_path = repo_git_path(repo, "config.worktree");
res = git_config_set_in_file_gently(config_path,
"index.sparse",
enable ? "true" : NULL);
enable ? "true" : "false");
free(config_path);

prepare_repo_settings(repo);
Expand All @@ -130,7 +130,8 @@ static int index_has_unmerged_entries(struct index_state *istate)
int convert_to_sparse(struct index_state *istate)
{
int test_env;
if (istate->split_index || istate->sparse_index ||

if (istate->split_index || istate->sparse_index || !istate->cache_nr ||
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
return 0;

Expand Down Expand Up @@ -158,10 +159,16 @@ int convert_to_sparse(struct index_state *istate)
return 0;
}

if (!istate->sparse_checkout_patterns->use_cone_patterns) {
warning(_("attempting to use sparse-index without cone mode"));
return -1;
}
/*
* We need cone-mode patterns to use sparse-index. If a user edits
* their sparse-checkout file manually, then we can detect during
* parsing that they are not actually using cone-mode patterns and
* hence we need to abort this conversion _without error_. Warnings
* already exist in the pattern parsing to inform the user of their
* bad patterns.
*/
if (!istate->sparse_checkout_patterns->use_cone_patterns)
return 0;

/*
* NEEDSWORK: If we have unmerged entries, then stay full.
Expand Down
2 changes: 1 addition & 1 deletion t/t1091-sparse-checkout-builtin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test_expect_success 'sparse-index enabled and disabled' '
test-tool -C repo read-cache --table >cache &&
! grep " tree " cache &&
git -C repo config --list >config &&
! grep index.sparse config
test_cmp_config -C repo false index.sparse
'

test_expect_success 'cone mode: init and set' '
Expand Down
1 change: 1 addition & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ init_repos () {
git -C sparse-index reset --hard &&

# initialize sparse-checkout definitions
git -C sparse-checkout config index.sparse false &&
git -C sparse-checkout sparse-checkout init --cone &&
git -C sparse-checkout sparse-checkout set deep &&
git -C sparse-index sparse-checkout init --cone --sparse-index &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7817-grep-sparse-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test_expect_success 'setup' '
echo "text" >B/b &&
git add A B &&
git commit -m sub &&
git sparse-checkout init --cone &&
git sparse-checkout init --cone --no-sparse-index &&
git sparse-checkout set B
) &&
Expand Down