Skip to content

Commit 4bf0c06

Browse files
derrickstoleegitster
authored andcommitted
sparse-checkout: extract pattern update from 'set' subcommand
In anticipation of adding "add" and "remove" subcommands to the sparse-checkout builtin, extract a modify_pattern_list() method from the sparse_checkout_set() method. This command will read input from the command-line or stdin to construct a set of patterns, then modify the existing sparse-checkout patterns after a successful update of the working directory. Currently, the only way to modify the patterns is to replace all of the patterns. This will be extended in a later update. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6fb705a commit 4bf0c06

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

builtin/sparse-checkout.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,29 +462,17 @@ static void add_patterns_from_input(struct pattern_list *pl,
462462
}
463463
}
464464

465-
static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
465+
enum modify_type {
466+
REPLACE,
467+
};
468+
469+
static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
466470
{
467-
struct pattern_list pl;
468471
int result;
469472
int changed_config = 0;
470-
471-
static struct option builtin_sparse_checkout_set_options[] = {
472-
OPT_BOOL(0, "stdin", &set_opts.use_stdin,
473-
N_("read patterns from standard in")),
474-
OPT_END(),
475-
};
476-
477-
repo_read_index(the_repository);
478-
require_clean_work_tree(the_repository,
479-
N_("set sparse-checkout patterns"), NULL, 1, 0);
480-
473+
struct pattern_list pl;
481474
memset(&pl, 0, sizeof(pl));
482475

483-
argc = parse_options(argc, argv, prefix,
484-
builtin_sparse_checkout_set_options,
485-
builtin_sparse_checkout_set_usage,
486-
PARSE_OPT_KEEP_UNKNOWN);
487-
488476
add_patterns_from_input(&pl, argc, argv);
489477

490478
if (!core_apply_sparse_checkout) {
@@ -502,6 +490,26 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
502490
return result;
503491
}
504492

493+
static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
494+
{
495+
static struct option builtin_sparse_checkout_set_options[] = {
496+
OPT_BOOL(0, "stdin", &set_opts.use_stdin,
497+
N_("read patterns from standard in")),
498+
OPT_END(),
499+
};
500+
501+
repo_read_index(the_repository);
502+
require_clean_work_tree(the_repository,
503+
N_("set sparse-checkout patterns"), NULL, 1, 0);
504+
505+
argc = parse_options(argc, argv, prefix,
506+
builtin_sparse_checkout_set_options,
507+
builtin_sparse_checkout_set_usage,
508+
PARSE_OPT_KEEP_UNKNOWN);
509+
510+
return modify_pattern_list(argc, argv, REPLACE);
511+
}
512+
505513
static int sparse_checkout_disable(int argc, const char **argv)
506514
{
507515
struct pattern_list pl;

0 commit comments

Comments
 (0)