builtins: mark unused prefix parameters

All builtins receive a "prefix" parameter, but it is only useful if they need to adjust filenames given by the user on the command line. For builtins that do not even call parse_options(), they often don't look at the prefix at all, and -Wunused-parameter complains. Let's annotate those to silence the compiler warning. I gave a quick scan of each of these cases, and it seems like they don't have anything they _should_ be using the prefix for (i.e., there is no hidden bug that we are missing). The only questionable cases I saw were: - in git-unpack-file, we create a tempfile which will always be at the root of the repository, even if the command is run from a subdir. Arguably this should be created in the subdir from which we're run (as we report the path only as a relative name). However, nobody has complained, and I'm hesitant to change something that is deep plumbing going back to April 2005 (though I think within our scripts, the sole caller in git-merge-one-file would be OK, as it moves to the toplevel itself). - in fetch-pack, local-filesystem remotes are taken as relative to the project root, not the current directory. So: git init server.git [...put stuff in server.git...] git init client.git cd client.git mkdir subdir cd subdir git fetch-pack ../../server.git ... won't work, as we quietly move to the top of the repository before interpreting the path (so "../server.git" would work). This is weird, but again, nobody has complained and this is how it has always worked. And this is how "git fetch" works, too. Plus it raises questions about how a configured remote like: git config remote.origin.url ../server.git should behave. I can certainly come up with a reasonable set of behavior, but it may not be worth stirring up complications in a plumbing tool. So I've left the behavior untouched in both of those cases. If anybody really wants to revisit them, it's easy enough to drop the UNUSED marker. This commit is just about removing them as obstacles to turning on -Wunused-parameter all the time. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 28, 2023 at 16:56 UTC 5247b762d0c22875c4ac71183e89b50d9f9acc2d
12 files changed +12 -12
builtin/credential.c
+1 -1
@@ -6,7 +6,7 @@
6 static const char usage_msg[] =
7 "git credential (fill|approve|reject)";
8
9 -int cmd_credential(int argc, const char **argv, const char *prefix)
9 +int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
10 {
11 const char *op;
12 struct credential c = CREDENTIAL_INIT;
builtin/fetch-pack.c
+1 -1
@@ -42,7 +42,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
42 (*sought)[*nr - 1] = ref;
43 }
44
45 -int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
45 +int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
46 {
47 int i, ret;
48 struct ref *ref = NULL;
builtin/fsmonitor--daemon.c
+1 -1
@@ -1575,7 +1575,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
1575 }
1576
1577 #else
1578 -int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
1578 +int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED)
1579 {
1580 struct option options[] = {
1581 OPT_END()
builtin/merge-index.c
+1 -1
@@ -71,7 +71,7 @@ static void merge_all(void)
71 }
72 }
73
74 -int cmd_merge_index(int argc, const char **argv, const char *prefix)
74 +int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
75 {
76 int i, force_file = 0;
77
builtin/merge-ours.c
+1 -1
@@ -14,7 +14,7 @@
14 static const char builtin_merge_ours_usage[] =
15 "git merge-ours <base>... -- HEAD <remote>...";
16
17 -int cmd_merge_ours(int argc, const char **argv, const char *prefix)
17 +int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
18 {
19 if (argc == 2 && !strcmp(argv[1], "-h"))
20 usage(builtin_merge_ours_usage);
builtin/merge-recursive.c
+1 -1
@@ -20,7 +20,7 @@ static char *better_branch_name(const char *branch)
20 return xstrdup(name ? name : branch);
21 }
22
23 -int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
23 +int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
24 {
25 const struct object_id *bases[21];
26 unsigned bases_count = 0;
builtin/pack-redundant.c
+1 -1
@@ -558,7 +558,7 @@ static void load_all(void)
558 }
559 }
560
561 -int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
561 +int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED)
562 {
563 int i;
564 int i_still_use_this = 0;
builtin/stash.c
+1 -1
@@ -1466,7 +1466,7 @@ done:
1466 return ret;
1467 }
1468
1469 -static int create_stash(int argc, const char **argv, const char *prefix)
1469 +static int create_stash(int argc, const char **argv, const char *prefix UNUSED)
1470 {
1471 int ret;
1472 struct strbuf stash_msg_buf = STRBUF_INIT;
builtin/submodule--helper.c
+1 -1
@@ -2766,7 +2766,7 @@ cleanup:
2766 return ret;
2767 }
2768
2769 -static int push_check(int argc, const char **argv, const char *prefix)
2769 +static int push_check(int argc, const char **argv, const char *prefix UNUSED)
2770 {
2771 struct remote *remote;
2772 const char *superproject_head;
builtin/unpack-file.c
+1 -1
@@ -24,7 +24,7 @@ static char *create_temp_file(struct object_id *oid)
24 return path;
25 }
26
27 -int cmd_unpack_file(int argc, const char **argv, const char *prefix)
27 +int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
28 {
29 struct object_id oid;
30
builtin/unpack-objects.c
+1 -1
@@ -600,7 +600,7 @@ static void unpack_all(void)
600 die("unresolved deltas left after unpacking");
601 }
602
603 -int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
603 +int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
604 {
605 int i;
606 struct object_id oid;
builtin/var.c
+1 -1
@@ -78,7 +78,7 @@ static int show_config(const char *var, const char *value, void *cb)
78 return git_default_config(var, value, cb);
79 }
80
81 -int cmd_var(int argc, const char **argv, const char *prefix)
81 +int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
82 {
83 const struct git_var *git_var;
84 const char *val;