Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-12-14 07:09:07 +0300
committerJunio C Hamano <gitster@pobox.com>2021-12-15 22:48:22 +0300
commitbe61fd1181f62dcb7b6a5f41021e7f086d7c30b0 (patch)
tree6771096c9b933ff84e74352584c2c8264c1fe231 /builtin/sparse-checkout.c
parentf85751a147996f7f0a8edf3ea2a00217c9ddfc99 (diff)
sparse-checkout: split out code for tweaking settings config
`init` has some code for handling updates to either cone mode or the sparse-index setting. We would like to be able to reuse this elsewhere, namely in `set` and `reapply`. Split this function out, and make it slightly more general so it can handle being called from the new callers. Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Victoria Dye <vdye@github.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/sparse-checkout.c')
-rw-r--r--builtin/sparse-checkout.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 387903eafe..3b74779bb4 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -383,6 +383,41 @@ static int set_config(enum sparse_checkout_mode mode)
return 0;
}
+static int update_modes(int *cone_mode, int *sparse_index)
+{
+ int mode, record_mode;
+
+ /* Determine if we need to record the mode; ensure sparse checkout on */
+ record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
+
+ /* If not specified, use previous definition of cone mode */
+ if (*cone_mode == -1 && core_apply_sparse_checkout)
+ *cone_mode = core_sparse_checkout_cone;
+
+ /* Set cone/non-cone mode appropriately */
+ core_apply_sparse_checkout = 1;
+ if (*cone_mode == 1) {
+ mode = MODE_CONE_PATTERNS;
+ core_sparse_checkout_cone = 1;
+ } else {
+ mode = MODE_ALL_PATTERNS;
+ }
+ if (record_mode && set_config(mode))
+ return 1;
+
+ /* Set sparse-index/non-sparse-index mode if specified */
+ if (*sparse_index >= 0) {
+ if (set_sparse_index_config(the_repository, *sparse_index) < 0)
+ die(_("failed to modify sparse-index config"));
+
+ /* force an index rewrite */
+ repo_read_index(the_repository);
+ the_repository->index->updated_workdir = 1;
+ }
+
+ return 0;
+}
+
static char const * const builtin_sparse_checkout_init_usage[] = {
N_("git sparse-checkout init [--cone] [--[no-]sparse-index]"),
NULL
@@ -399,7 +434,6 @@ static int sparse_checkout_init(int argc, const char **argv)
char *sparse_filename;
int res;
struct object_id oid;
- int mode;
struct strbuf pattern = STRBUF_INIT;
static struct option builtin_sparse_checkout_init_options[] = {
@@ -412,19 +446,14 @@ static int sparse_checkout_init(int argc, const char **argv)
repo_read_index(the_repository);
+ init_opts.cone_mode = -1;
init_opts.sparse_index = -1;
argc = parse_options(argc, argv, NULL,
builtin_sparse_checkout_init_options,
builtin_sparse_checkout_init_usage, 0);
- if (init_opts.cone_mode) {
- mode = MODE_CONE_PATTERNS;
- core_sparse_checkout_cone = 1;
- } else
- mode = MODE_ALL_PATTERNS;
-
- if (set_config(mode))
+ if (update_modes(&init_opts.cone_mode, &init_opts.sparse_index))
return 1;
memset(&pl, 0, sizeof(pl));
@@ -432,17 +461,6 @@ static int sparse_checkout_init(int argc, const char **argv)
sparse_filename = get_sparse_checkout_filename();
res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
- if (init_opts.sparse_index >= 0) {
- if (set_sparse_index_config(the_repository, init_opts.sparse_index) < 0)
- die(_("failed to modify sparse-index config"));
-
- /* force an index rewrite */
- repo_read_index(the_repository);
- the_repository->index->updated_workdir = 1;
- }
-
- core_apply_sparse_checkout = 1;
-
/* If we already have a sparse-checkout file, use it. */
if (res >= 0) {
free(sparse_filename);