@matheusbsbs / matheus-bagliano / commits / 75d3bee157
Fork 0

sparse-checkout: fill in some options boilerplate

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

Jeff King committed Sep 30, 2020 at 08:30 UTC 75d3bee15778a3aaeb8234023fc224838ac53181
1 file changed +37
builtin/sparse-checkout.c
+37
@@ -46,12 +46,24 @@ static void write_patterns_to_file(FILE *fp, struct pattern_list *pl)
46 }
47 }
48
49 +static char const * const builtin_sparse_checkout_list_usage[] = {
50 + N_("git sparse-checkout list"),
51 + NULL
52 +};
53 +
54 static int sparse_checkout_list(int argc, const char **argv)
55 {
56 + static struct option builtin_sparse_checkout_list_options[] = {
57 + OPT_END(),
58 + };
59 struct pattern_list pl;
60 char *sparse_filename;
61 int res;
62
63 + argc = parse_options(argc, argv, NULL,
64 + builtin_sparse_checkout_list_options,
65 + builtin_sparse_checkout_list_usage, 0);
66 +
67 memset(&pl, 0, sizeof(pl));
68
69 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,
572 return modify_pattern_list(argc, argv, m);
573 }
574
575 +static char const * const builtin_sparse_checkout_reapply_usage[] = {
576 + N_("git sparse-checkout reapply"),
577 + NULL
578 +};
579 +
580 static int sparse_checkout_reapply(int argc, const char **argv)
581 {
582 + static struct option builtin_sparse_checkout_reapply_options[] = {
583 + OPT_END(),
584 + };
585 +
586 + argc = parse_options(argc, argv, NULL,
587 + builtin_sparse_checkout_reapply_options,
588 + builtin_sparse_checkout_reapply_usage, 0);
589 +
590 repo_read_index(the_repository);
591 return update_working_directory(NULL);
592 }
593
594 +static char const * const builtin_sparse_checkout_disable_usage[] = {
595 + N_("git sparse-checkout disable"),
596 + NULL
597 +};
598 +
599 static int sparse_checkout_disable(int argc, const char **argv)
600 {
601 + static struct option builtin_sparse_checkout_disable_options[] = {
602 + OPT_END(),
603 + };
604 struct pattern_list pl;
605 struct strbuf match_all = STRBUF_INIT;
606
607 + argc = parse_options(argc, argv, NULL,
608 + builtin_sparse_checkout_disable_options,
609 + builtin_sparse_checkout_disable_usage, 0);
610 +
611 repo_read_index(the_repository);
612
613 memset(&pl, 0, sizeof(pl));