git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 07/10] sparse-checkout: fill in some options boilerplate

From
Jeff King <peff@peff.net>
Date
Sep 30, 2020, 12:30 UTC
Message-ID
<20200930123010.GG1901279@coredump.intra.peff.net>
In-Reply-To
<20200930122732.GA1901036@coredump.intra.peff.net>

The sparse-checkout passes along argv and argc to its sub-command helper functions. Many of these sub-commands do not yet take any command-line options, and ignore those parameters.

Let's instead add empty option lists and make sure we call parse_options(). That will give a useful error message for something like:

  git sparse-checkout list --nonsense
which currently just silently ignores the unknown option.
As a bonus, it also silences some -Wunused-parameter warnings.
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/sparse-checkout.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 4003f4d13a..e3140db2a0 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -46,12 +46,24 @@ static void write_patterns_to_file(FILE *fp, struct pattern_list *pl)
 	}
 }
 
+static char const * const builtin_sparse_checkout_list_usage[] = {
+	N_("git sparse-checkout list"),
+	NULL
+};
+
 static int sparse_checkout_list(int argc, const char **argv)
 {
+	static struct option builtin_sparse_checkout_list_options[] = {
+		OPT_END(),
+	};
 	struct pattern_list pl;
 	char *sparse_filename;
 	int res;
 
+	argc = parse_options(argc, argv, NULL,
+			     builtin_sparse_checkout_list_options,
+			     builtin_sparse_checkout_list_usage, 0);
+
 	memset(&pl, 0, sizeof(pl));
 
 	pl.use_cone_patterns = core_sparse_checkout_cone;
@@ -560,17 +572,42 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
 	return modify_pattern_list(argc, argv, m);
 }
 
+static char const * const builtin_sparse_checkout_reapply_usage[] = {
+	N_("git sparse-checkout reapply"),
+	NULL
+};
+
 static int sparse_checkout_reapply(int argc, const char **argv)
 {
+	static struct option builtin_sparse_checkout_reapply_options[] = {
+		OPT_END(),
+	};
+
+	argc = parse_options(argc, argv, NULL,
+			     builtin_sparse_checkout_reapply_options,
+			     builtin_sparse_checkout_reapply_usage, 0);
+
 	repo_read_index(the_repository);
 	return update_working_directory(NULL);
 }
 
+static char const * const builtin_sparse_checkout_disable_usage[] = {
+	N_("git sparse-checkout disable"),
+	NULL
+};
+
 static int sparse_checkout_disable(int argc, const char **argv)
 {
+	static struct option builtin_sparse_checkout_disable_options[] = {
+		OPT_END(),
+	};
 	struct pattern_list pl;
 	struct strbuf match_all = STRBUF_INIT;
 
+	argc = parse_options(argc, argv, NULL,
+			     builtin_sparse_checkout_disable_options,
+			     builtin_sparse_checkout_disable_usage, 0);
+
 	repo_read_index(the_repository);
 
 	memset(&pl, 0, sizeof(pl));
-- 
2.28.0.1173.gad90222cf0
Previous: Jeff KingNext: Jeff King
Message 8 of 11 in “dropping more unused parameters”
  1. 0/10 dropping more unused parametersJeff King, Sep 30, 2020
  2. 01/10 convert: drop unused crlf_action from check_global_conv_flags_eol()Jeff King, Sep 30, 2020
  3. 02/10 drop unused argc parametersJeff King, Sep 30, 2020
  4. 03/10 env--helper: write to opt->value in parseopt helperJeff King, Sep 30, 2020
  5. 04/10 assert PARSE_OPT_NONEG in parse-options callbacksJeff King, Sep 30, 2020
  6. 05/10 push: drop unused repo argument to do_push()Jeff King, Sep 30, 2020
  7. 06/10 sequencer: drop repository argument from run_git_commit()Jeff King, Sep 30, 2020
  8. 07/10 sparse-checkout: fill in some options boilerplateJeff King, Sep 30, 2020
  9. 08/10 test-advise: check argument count with argc instead of argvJeff King, Sep 30, 2020
  10. 09/10 sequencer: handle ignore_footer when parsing trailersJeff King, Sep 30, 2020
  11. 10/10 dir.c: drop unused "untracked" from treat_path_fast()Jeff King, Sep 30, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.