summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Elijah Newren <newren@gmail.com>2021-12-14 04:09:03 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-12-15 11:48:21 -0800
commit1530ff3553c197ae04b5d9363e2c2b1f7d4198e1 (patch)
tree46494eb640d758e0c46cfc88682950e75ec74e49
parentThe first batch to start the current cycle (diff)
downloadtgif-1530ff3553c197ae04b5d9363e2c2b1f7d4198e1.tar.xz
sparse-checkout: pass use_stdin as a parameter instead of as a global
add_patterns_from_input() has relied on a global variable, set_opts.use_stdin, which has been used by both the `set` and `add` subcommands of sparse-checkout. Once we introduce an add_opts.use_stdin, the hardcoding of set_opts.use_stdin will be incorrect. Pass the value as function parameter instead to allow us to make subsequent changes. 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>
-rw-r--r--builtin/sparse-checkout.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index d0f5c4702b..8612328e5d 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -525,7 +525,8 @@ static struct sparse_checkout_set_opts {
} set_opts;
static void add_patterns_from_input(struct pattern_list *pl,
- int argc, const char **argv)
+ int argc, const char **argv,
+ int use_stdin)
{
int i;
if (core_sparse_checkout_cone) {
@@ -535,7 +536,7 @@ static void add_patterns_from_input(struct pattern_list *pl,
hashmap_init(&pl->parent_hashmap, pl_hashmap_cmp, NULL, 0);
pl->use_cone_patterns = 1;
- if (set_opts.use_stdin) {
+ if (use_stdin) {
struct strbuf unquoted = STRBUF_INIT;
while (!strbuf_getline(&line, stdin)) {
if (line.buf[0] == '"') {
@@ -559,7 +560,7 @@ static void add_patterns_from_input(struct pattern_list *pl,
}
}
} else {
- if (set_opts.use_stdin) {
+ if (use_stdin) {
struct strbuf line = STRBUF_INIT;
while (!strbuf_getline(&line, stdin)) {
@@ -580,7 +581,8 @@ enum modify_type {
};
static void add_patterns_cone_mode(int argc, const char **argv,
- struct pattern_list *pl)
+ struct pattern_list *pl,
+ int use_stdin)
{
struct strbuf buffer = STRBUF_INIT;
struct pattern_entry *pe;
@@ -588,7 +590,7 @@ static void add_patterns_cone_mode(int argc, const char **argv,
struct pattern_list existing;
char *sparse_filename = get_sparse_checkout_filename();
- add_patterns_from_input(pl, argc, argv);
+ add_patterns_from_input(pl, argc, argv, use_stdin);
memset(&existing, 0, sizeof(existing));
existing.use_cone_patterns = core_sparse_checkout_cone;
@@ -614,17 +616,19 @@ static void add_patterns_cone_mode(int argc, const char **argv,
}
static void add_patterns_literal(int argc, const char **argv,
- struct pattern_list *pl)
+ struct pattern_list *pl,
+ int use_stdin)
{
char *sparse_filename = get_sparse_checkout_filename();
if (add_patterns_from_file_to_list(sparse_filename, "", 0,
pl, NULL, 0))
die(_("unable to load existing sparse-checkout patterns"));
free(sparse_filename);
- add_patterns_from_input(pl, argc, argv);
+ add_patterns_from_input(pl, argc, argv, use_stdin);
}
-static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
+static int modify_pattern_list(int argc, const char **argv, int use_stdin,
+ enum modify_type m)
{
int result;
int changed_config = 0;
@@ -633,13 +637,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
switch (m) {
case ADD:
if (core_sparse_checkout_cone)
- add_patterns_cone_mode(argc, argv, pl);
+ add_patterns_cone_mode(argc, argv, pl, use_stdin);
else
- add_patterns_literal(argc, argv, pl);
+ add_patterns_literal(argc, argv, pl, use_stdin);
break;
case REPLACE:
- add_patterns_from_input(pl, argc, argv);
+ add_patterns_from_input(pl, argc, argv, use_stdin);
break;
}
@@ -675,7 +679,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
builtin_sparse_checkout_set_usage,
PARSE_OPT_KEEP_UNKNOWN);
- return modify_pattern_list(argc, argv, m);
+ return modify_pattern_list(argc, argv, set_opts.use_stdin, m);
}
static char const * const builtin_sparse_checkout_reapply_usage[] = {