All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <stolee@gmail.com>,
	Lessley Dennington <lessleydennington@gmail.com>,
	Victoria Dye <vdye@github.com>, Elijah Newren <newren@gmail.com>,
	Elijah Newren <newren@gmail.com>
Subject: [PATCH 1/6] sparse-checkout: pass use_stdin as a parameter instead of as a global
Date: Sat, 04 Dec 2021 20:00:15 +0000	[thread overview]
Message-ID: <e41cfe3c1bbf4c26202102782631a614a450ac27.1638648020.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1151.git.git.1638648020.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

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.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/sparse-checkout.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index d0f5c4702be..8612328e5dd 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[] = {
-- 
gitgitgadget


  reply	other threads:[~2021-12-04 20:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-04 20:00 [PATCH 0/6] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-04 20:00 ` Elijah Newren via GitGitGadget [this message]
2021-12-04 20:00 ` [PATCH 2/6] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 3/6] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-04 21:40   ` Victoria Dye
2021-12-07 17:04     ` Elijah Newren
2021-12-07 20:36       ` Lessley Dennington
2021-12-07 16:42   ` Derrick Stolee
2021-12-07 18:18     ` Elijah Newren
2021-12-04 20:00 ` [PATCH 4/6] git-sparse-checkout.txt: update to document that set handles init Elijah Newren via GitGitGadget
2021-12-04 21:48   ` Victoria Dye
2021-12-07 16:45     ` Derrick Stolee
2021-12-07 17:06     ` Elijah Newren
2021-12-07 20:42   ` Lessley Dennington
2021-12-07 21:13     ` Elijah Newren
2021-12-07 22:36       ` Lessley Dennington
2021-12-04 20:00 ` [PATCH 5/6] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 6/6] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 16:48 ` [PATCH 0/6] sparse-checkout: make set subsume init Derrick Stolee
2021-12-07 20:20 ` [PATCH v2 00/10] " Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 21:05   ` [PATCH v2 00/10] sparse-checkout: make set subsume init Derrick Stolee
2021-12-08 14:16   ` Victoria Dye
2021-12-10  3:56   ` [PATCH v3 " Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-13 18:11       ` Junio C Hamano
2021-12-14  2:25         ` Elijah Newren
2021-12-10  3:56     ` [PATCH v3 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-13 18:23       ` Junio C Hamano
2021-12-14  2:39         ` Elijah Newren
2021-12-10  3:56     ` [PATCH v3 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-14  4:09     ` [PATCH v4 00/10] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-23  0:47         ` Jiang Xin
2021-12-23 17:09           ` Elijah Newren
2021-12-23 19:09             ` Junio C Hamano
2021-12-14  4:09       ` [PATCH v4 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-14  7:38         ` Bagas Sanjaya
2021-12-14  7:48           ` Elijah Newren
2021-12-14  4:09       ` [PATCH v4 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e41cfe3c1bbf4c26202102782631a614a450ac27.1638648020.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=lessleydennington@gmail.com \
    --cc=newren@gmail.com \
    --cc=stolee@gmail.com \
    --cc=vdye@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.