@matheusbsbs / matheus-bagliano / commits / 4bf0c06c71
Fork 0

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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Feb 11, 2020 at 15:02 UTC 4bf0c06c7169da61de489544207a7659ef31029f
1 file changed +26 -18
builtin/sparse-checkout.c
+26 -18
@@ -462,29 +462,17 @@ static void add_patterns_from_input(struct pattern_list *pl,
462 }
463 }
464
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)
470 {
467 - struct pattern_list pl;
471 int result;
472 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;
474 memset(&pl, 0, sizeof(pl));
475
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 -
476 add_patterns_from_input(&pl, argc, argv);
477
478 if (!core_apply_sparse_checkout) {
@@ -502,6 +490,26 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
490 return result;
491 }
492
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 +
513 static int sparse_checkout_disable(int argc, const char **argv)
514 {
515 struct pattern_list pl;