]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtins: mark unused prefix parameters
authorJeff King <peff@peff.net>
Tue, 28 Mar 2023 20:56:55 +0000 (16:56 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 21:11:24 +0000 (14:11 -0700)
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>
12 files changed:
builtin/credential.c
builtin/fetch-pack.c
builtin/fsmonitor--daemon.c
builtin/merge-index.c
builtin/merge-ours.c
builtin/merge-recursive.c
builtin/pack-redundant.c
builtin/stash.c
builtin/submodule--helper.c
builtin/unpack-file.c
builtin/unpack-objects.c
builtin/var.c

index d7b304fa084fd6c714ce9a6853d903ae6636bb33..70107529876372c693fa15bbf6aff54ca63b4ce7 100644 (file)
@@ -6,7 +6,7 @@
 static const char usage_msg[] =
        "git credential (fill|approve|reject)";
 
-int cmd_credential(int argc, const char **argv, const char *prefix)
+int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
 {
        const char *op;
        struct credential c = CREDENTIAL_INIT;
index d1a4306da3ad76574603c01d199cf5f7914d014c..0d75e474f0288bc7c460ee18da823121e0de7eb6 100644 (file)
@@ -42,7 +42,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
        (*sought)[*nr - 1] = ref;
 }
 
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
+int cmd_fetch_pack(int argc, const char **argv, const char *prefix UNUSED)
 {
        int i, ret;
        struct ref *ref = NULL;
index cae804a190808bf787ad098f749c721d440c1036..3d4f2ae1d0cdbdc05103a05d3a4d0ea6f10eb851 100644 (file)
@@ -1575,7 +1575,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
 }
 
 #else
-int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
+int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED)
 {
        struct option options[] = {
                OPT_END()
index c875f5d37ee63f489f03a3f0f8007998fca69ca0..b747b4ed983f22b724dac40a6b50ecbcae5e39ba 100644 (file)
@@ -71,7 +71,7 @@ static void merge_all(void)
        }
 }
 
-int cmd_merge_index(int argc, const char **argv, const char *prefix)
+int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
 {
        int i, force_file = 0;
 
index 284eb48609837e66d4511ecb7fb3cc89dfbf8b90..c2e519301e91cef4ac3204a37aa9e792c518c0f3 100644 (file)
@@ -14,7 +14,7 @@
 static const char builtin_merge_ours_usage[] =
        "git merge-ours <base>... -- HEAD <remote>...";
 
-int cmd_merge_ours(int argc, const char **argv, const char *prefix)
+int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
 {
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(builtin_merge_ours_usage);
index b9acbf5d3427e7dd88533351db5d2fc245cc25f6..0a50d0a0ae23bb6eae561123021e3734499bfaaf 100644 (file)
@@ -20,7 +20,7 @@ static char *better_branch_name(const char *branch)
        return xstrdup(name ? name : branch);
 }
 
-int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
+int cmd_merge_recursive(int argc, const char **argv, const char *prefix UNUSED)
 {
        const struct object_id *bases[21];
        unsigned bases_count = 0;
index 82115c5808caf34ff875621fbbac22201f80aee0..104d10877b4f0210b6fcee995704e04105f4dcea 100644 (file)
@@ -558,7 +558,7 @@ static void load_all(void)
        }
 }
 
-int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
+int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED)
 {
        int i;
        int i_still_use_this = 0;
index 6a12fed2713073f91441bd9058058591f4155ddf..5f327435b5359a03a79274df289a821e0be28ada 100644 (file)
@@ -1466,7 +1466,7 @@ done:
        return ret;
 }
 
-static int create_stash(int argc, const char **argv, const char *prefix)
+static int create_stash(int argc, const char **argv, const char *prefix UNUSED)
 {
        int ret;
        struct strbuf stash_msg_buf = STRBUF_INIT;
index d05d1a846233341046a4835a579964323b4e07d0..65a053261a952b8b012a70f976569ee101ebfc9f 100644 (file)
@@ -2766,7 +2766,7 @@ cleanup:
        return ret;
 }
 
-static int push_check(int argc, const char **argv, const char *prefix)
+static int push_check(int argc, const char **argv, const char *prefix UNUSED)
 {
        struct remote *remote;
        const char *superproject_head;
index e9b105a5397a3fe232f8aa0c005f8ce72599b98b..374d980c9106a0dabcfb65674398105a356c0a28 100644 (file)
@@ -24,7 +24,7 @@ static char *create_temp_file(struct object_id *oid)
        return path;
 }
 
-int cmd_unpack_file(int argc, const char **argv, const char *prefix)
+int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED)
 {
        struct object_id oid;
 
index 1908dcfcffb7b89234cdcd788f1302e307beed2b..3d8510ccf81fe564f9386fea6e10be9a21634d71 100644 (file)
@@ -600,7 +600,7 @@ static void unpack_all(void)
                die("unresolved deltas left after unpacking");
 }
 
-int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
+int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
 {
        int i;
        struct object_id oid;
index d9943be9afd73dfc46e471ecee426aed00f8da08..acb988d2d56fec4645c7d905023027f203c43911 100644 (file)
@@ -78,7 +78,7 @@ static int show_config(const char *var, const char *value, void *cb)
        return git_default_config(var, value, cb);
 }
 
-int cmd_var(int argc, const char **argv, const char *prefix)
+int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
 {
        const struct git_var *git_var;
        const char *val;