@@ -6,3 +6,11 @@ extensions.objectFormat::
Note that this setting should only be set by linkgit:git-init[1] or
linkgit:git-clone[1]. Trying to change it after initialization will not
work and will produce hard-to-diagnose issues.
+
+extensions.sparseIndex::
+ When combined with `core.sparseCheckout=true` and
+ `core.sparseCheckoutCone=true`, the index may contain entries
+ corresponding to directories outside of the sparse-checkout
+ definition in lieu of containing each path under such directories.
+ Versions of Git that do not understand this extension do not
+ expect directory entries in the index.
@@ -1059,6 +1059,7 @@ struct repository_format {
int worktree_config;
int is_bare;
int hash_algo;
+ int sparse_index;
char *work_tree;
struct string_list unknown_extensions;
struct string_list v1_only_extensions;
@@ -85,4 +85,11 @@ void prepare_repo_settings(struct repository *r)
* removed.
*/
r->settings.command_requires_full_index = 1;
+
+ /*
+ * Initialize this as off.
+ */
+ r->settings.sparse_index = 0;
+ if (!repo_config_get_bool(r, "extensions.sparseindex", &value) && value)
+ r->settings.sparse_index = 1;
}
@@ -42,7 +42,8 @@ struct repo_settings {
int core_multi_pack_index;
- unsigned command_requires_full_index:1;
+ unsigned command_requires_full_index:1,
+ sparse_index:1;
};
struct repository {
@@ -500,6 +500,9 @@ static enum extension_result handle_extension(const char *var,
return error("invalid value for 'extensions.objectformat'");
data->hash_algo = format;
return EXTENSION_OK;
+ } else if (!strcmp(ext, "sparseindex")) {
+ data->sparse_index = 1;
+ return EXTENSION_OK;
}
return EXTENSION_UNKNOWN;
}
@@ -102,19 +102,47 @@ static int convert_to_sparse_rec(struct index_state *istate,
return num_converted - start_converted;
}
+static int enable_sparse_index(struct repository *repo)
+{
+ const char *config_path = repo_git_path(repo, "config.worktree");
+
+ if (upgrade_repository_format(1) < 0) {
+ warning(_("unable to upgrade repository format to enable sparse-index"));
+ return -1;
+ }
+ git_config_set_in_file_gently(config_path,
+ "extensions.sparseIndex",
+ "true");
+
+ prepare_repo_settings(repo);
+ repo->settings.sparse_index = 1;
+ return 0;
+}
+
int convert_to_sparse(struct index_state *istate)
{
if (istate->split_index || istate->sparse_index ||
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
return 0;
+ if (!istate->repo)
+ istate->repo = the_repository;
+
+ /*
+ * The GIT_TEST_SPARSE_INDEX environment variable triggers the
+ * extensions.sparseIndex config variable to be on.
+ */
+ if (git_env_bool("GIT_TEST_SPARSE_INDEX", 0)) {
+ int err = enable_sparse_index(istate->repo);
+ if (err < 0)
+ return err;
+ }
+
/*
- * For now, only create a sparse index with the
- * GIT_TEST_SPARSE_INDEX environment variable. We will relax
- * this once we have a proper way to opt-in (and later still,
- * opt-out).
+ * Only convert to sparse if extensions.sparseIndex is set.
*/
- if (!git_env_bool("GIT_TEST_SPARSE_INDEX", 0))
+ prepare_repo_settings(istate->repo);
+ if (!istate->repo->settings.sparse_index)
return 0;
if (!istate->sparse_checkout_patterns) {