Skip to content

Commit 0b624e0

Browse files
newrengitster
authored andcommitted
sparse-checkout: break apart functions for sparse_checkout_(set|add)
sparse_checkout_set() was reused by sparse_checkout_add() with the only difference being a single parameter being passed to that function. However, we would like sparse_checkout_set() to do the same work that sparse_checkout_init() does if sparse checkouts are not already enabled. To facilitate this transition, give each mode their own copy of the function. This does not introduce any behavioral changes; that will come in a subsequent patch. Reviewed-by: Derrick Stolee <[email protected]> Reviewed-by: Victoria Dye <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1530ff3 commit 0b624e0

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

builtin/sparse-checkout.c

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,6 @@ static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
515515
insert_recursive_pattern(pl, line);
516516
}
517517

518-
static char const * const builtin_sparse_checkout_set_usage[] = {
519-
N_("git sparse-checkout (set|add) (--stdin | <patterns>)"),
520-
NULL
521-
};
522-
523-
static struct sparse_checkout_set_opts {
524-
int use_stdin;
525-
} set_opts;
526-
527518
static void add_patterns_from_input(struct pattern_list *pl,
528519
int argc, const char **argv,
529520
int use_stdin)
@@ -663,8 +654,43 @@ static int modify_pattern_list(int argc, const char **argv, int use_stdin,
663654
return result;
664655
}
665656

666-
static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
667-
enum modify_type m)
657+
static char const * const builtin_sparse_checkout_add_usage[] = {
658+
N_("git sparse-checkout add (--stdin | <patterns>)"),
659+
NULL
660+
};
661+
662+
static struct sparse_checkout_add_opts {
663+
int use_stdin;
664+
} add_opts;
665+
666+
static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
667+
{
668+
static struct option builtin_sparse_checkout_add_options[] = {
669+
OPT_BOOL(0, "stdin", &add_opts.use_stdin,
670+
N_("read patterns from standard in")),
671+
OPT_END(),
672+
};
673+
674+
repo_read_index(the_repository);
675+
676+
argc = parse_options(argc, argv, prefix,
677+
builtin_sparse_checkout_add_options,
678+
builtin_sparse_checkout_add_usage,
679+
PARSE_OPT_KEEP_UNKNOWN);
680+
681+
return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD);
682+
}
683+
684+
static char const * const builtin_sparse_checkout_set_usage[] = {
685+
N_("git sparse-checkout set (--stdin | <patterns>)"),
686+
NULL
687+
};
688+
689+
static struct sparse_checkout_set_opts {
690+
int use_stdin;
691+
} set_opts;
692+
693+
static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
668694
{
669695
static struct option builtin_sparse_checkout_set_options[] = {
670696
OPT_BOOL(0, "stdin", &set_opts.use_stdin,
@@ -679,7 +705,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
679705
builtin_sparse_checkout_set_usage,
680706
PARSE_OPT_KEEP_UNKNOWN);
681707

682-
return modify_pattern_list(argc, argv, set_opts.use_stdin, m);
708+
return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE);
683709
}
684710

685711
static char const * const builtin_sparse_checkout_reapply_usage[] = {
@@ -762,9 +788,9 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
762788
if (!strcmp(argv[0], "init"))
763789
return sparse_checkout_init(argc, argv);
764790
if (!strcmp(argv[0], "set"))
765-
return sparse_checkout_set(argc, argv, prefix, REPLACE);
791+
return sparse_checkout_set(argc, argv, prefix);
766792
if (!strcmp(argv[0], "add"))
767-
return sparse_checkout_set(argc, argv, prefix, ADD);
793+
return sparse_checkout_add(argc, argv, prefix);
768794
if (!strcmp(argv[0], "reapply"))
769795
return sparse_checkout_reapply(argc, argv);
770796
if (!strcmp(argv[0], "disable"))

0 commit comments

Comments
 (0)