Merge branch 'jk/unused-post-2.40-part2'

Code clean-up for "-Wunused-parameter" build.

* jk/unused-post-2.40-part2:
  parse-options: drop parse_opt_unknown_cb()
  t/helper: mark unused argv/argc arguments
  mark "argv" as unused when we check argc
  builtins: mark unused prefix parameters
  builtins: annotate always-empty prefix parameters
  builtins: always pass prefix to parse_options()
  fast-import: fix file access when run from subdir
This commit is contained in:
Junio C Hamano 2023-04-06 13:38:28 -07:00
commit 955abf5f72
54 changed files with 115 additions and 74 deletions

View File

@ -107,6 +107,16 @@ void setup_auto_pager(const char *cmd, int def);
int is_builtin(const char *s);
/*
* Builtins which do not use RUN_SETUP should never see
* a prefix that is not empty; use this to protect downstream
* code which is not prepared to call prefix_filename(), etc.
*/
#define BUG_ON_NON_EMPTY_PREFIX(prefix) do { \
if ((prefix)) \
BUG("unexpected prefix in builtin: %s", (prefix)); \
} while (0)
int cmd_add(int argc, const char **argv, const char *prefix);
int cmd_am(int argc, const char **argv, const char *prefix);
int cmd_annotate(int argc, const char **argv, const char *prefix);

View File

@ -60,6 +60,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
char *to_free = NULL;
int ret = 1;
BUG_ON_NON_EMPTY_PREFIX(prefix);
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(builtin_check_ref_format_usage);

View 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;

View File

@ -74,7 +74,7 @@ static void stuff_change(struct diff_options *opt,
}
static int builtin_diff_b_f(struct rev_info *revs,
int argc, const char **argv,
int argc, const char **argv UNUSED,
struct object_array_entry **blob)
{
/* Blob vs file in the working tree*/
@ -109,7 +109,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
}
static int builtin_diff_blobs(struct rev_info *revs,
int argc, const char **argv,
int argc, const char **argv UNUSED,
struct object_array_entry **blob)
{
const unsigned mode = canon_mode(S_IFREG | 0644);
@ -209,7 +209,7 @@ static int builtin_diff_tree(struct rev_info *revs,
}
static int builtin_diff_combined(struct rev_info *revs,
int argc, const char **argv,
int argc, const char **argv UNUSED,
struct object_array_entry *ent,
int ents, int first_non_parent)
{

View File

@ -176,6 +176,7 @@ static FILE *pack_edges;
static unsigned int show_stats = 1;
static int global_argc;
static const char **global_argv;
static const char *global_prefix;
/* Memory pools */
static struct mem_pool fi_mem_pool = {
@ -3246,7 +3247,7 @@ static void parse_alias(void)
static char* make_fast_import_path(const char *path)
{
if (!relative_marks_paths || is_absolute_path(path))
return xstrdup(path);
return prefix_filename(global_prefix, path);
return git_pathdup("info/fast-import/%s", path);
}
@ -3317,9 +3318,11 @@ static void option_cat_blob_fd(const char *fd)
static void option_export_pack_edges(const char *edges)
{
char *fn = prefix_filename(global_prefix, edges);
if (pack_edges)
fclose(pack_edges);
pack_edges = xfopen(edges, "a");
pack_edges = xfopen(fn, "a");
free(fn);
}
static void option_rewrite_submodules(const char *arg, struct string_list *list)
@ -3334,11 +3337,13 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)
f++;
CALLOC_ARRAY(ms, 1);
f = prefix_filename(global_prefix, f);
fp = fopen(f, "r");
if (!fp)
die_errno("cannot read '%s'", f);
read_mark_file(&ms, fp, insert_oid_entry);
fclose(fp);
free(f);
string_list_insert(list, s)->util = ms;
}
@ -3552,6 +3557,7 @@ int cmd_fast_import(int argc, const char **argv, const char *prefix)
global_argc = argc;
global_argv = argv;
global_prefix = prefix;
rc_free = mem_pool_alloc(&fi_mem_pool, cmd_save * sizeof(*rc_free));
for (i = 0; i < (cmd_save - 1); i++)

View 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;

View 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()

View File

@ -14,7 +14,7 @@ static const char builtin_get_tar_commit_id_usage[] =
#define RECORDSIZE (512)
#define HEADERSIZE (2 * RECORDSIZE)
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix)
{
char buffer[HEADERSIZE];
struct ustar_header *header = (struct ustar_header *)buffer;
@ -24,6 +24,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
long len;
char *end;
BUG_ON_NON_EMPTY_PREFIX(prefix);
if (argc != 1)
usage(builtin_get_tar_commit_id_usage);

View File

@ -277,6 +277,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
const char **argp;
static const char *stdin_only[] = { "-", NULL };
BUG_ON_NON_EMPTY_PREFIX(prefix);
for (argp = argv+1; *argp; argp++) {
const char *arg = *argp;

View 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;

View 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);

View 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;

View File

@ -81,7 +81,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
int tagged_type;
struct object_id result;
argc = parse_options(argc, argv, NULL,
argc = parse_options(argc, argv, prefix,
builtin_mktag_options,
builtin_mktag_usage, 0);

View 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;

View File

@ -197,6 +197,8 @@ static int command_loop(const char *child)
int cmd_remote_ext(int argc, const char **argv, const char *prefix)
{
BUG_ON_NON_EMPTY_PREFIX(prefix);
if (argc != 3)
usage(usage_msg);

View File

@ -59,6 +59,8 @@ int cmd_remote_fd(int argc, const char **argv, const char *prefix)
int output_fd = -1;
char *end;
BUG_ON_NON_EMPTY_PREFIX(prefix);
if (argc != 3)
usage(usage_msg);

View File

@ -94,7 +94,8 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
}
static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
static int run_sequencer(int argc, const char **argv, const char *prefix,
struct replay_opts *opts)
{
const char * const * usage_str = revert_or_cherry_pick_usage(opts);
const char *me = action_name(opts);
@ -141,7 +142,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
options = parse_options_concat(options, cp_extra);
}
argc = parse_options(argc, argv, NULL, options, usage_str,
argc = parse_options(argc, argv, prefix, options, usage_str,
PARSE_OPT_KEEP_ARGV0 |
PARSE_OPT_KEEP_UNKNOWN_OPT);
@ -246,7 +247,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
opts.action = REPLAY_REVERT;
sequencer_init_config(&opts);
res = run_sequencer(argc, argv, &opts);
res = run_sequencer(argc, argv, prefix, &opts);
if (res < 0)
die(_("revert failed"));
replay_opts_release(&opts);
@ -260,7 +261,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
opts.action = REPLAY_PICK;
sequencer_init_config(&opts);
res = run_sequencer(argc, argv, &opts);
res = run_sequencer(argc, argv, prefix, &opts);
if (res < 0)
die(_("cherry-pick failed"));
replay_opts_release(&opts);

View 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;

View 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;

View 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;

View 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;

View File

@ -79,6 +79,8 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
{
struct child_process writer = CHILD_PROCESS_INIT;
BUG_ON_NON_EMPTY_PREFIX(prefix);
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(upload_archive_usage);

View 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;

View File

@ -213,21 +213,6 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
return 0;
}
/**
* Report that the option is unknown, so that other code can handle
* it. This can be used as a callback together with
* OPTION_LOWLEVEL_CALLBACK to allow an option to be documented in the
* "-h" output even if it's not being handled directly by
* parse_options().
*/
enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
const struct option *opt,
const char *arg, int unset)
{
BUG_ON_OPT_ARG(arg);
return PARSE_OPT_UNKNOWN;
}
/**
* Recreates the command-line option in the strbuf.
*/

View File

@ -479,9 +479,6 @@ int parse_opt_commit(const struct option *, const char *, int);
int parse_opt_tertiary(const struct option *, const char *, int);
int parse_opt_string_list(const struct option *, const char *, int);
int parse_opt_noop_cb(const struct option *, const char *, int);
enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
const struct option *,
const char *, int);
int parse_opt_passthru(const struct option *, const char *, int);
int parse_opt_passthru_argv(const struct option *, const char *, int);
/* value is enum branch_track* */

View File

@ -563,7 +563,7 @@ static int cmd_diagnose(int argc, const char **argv)
return res;
}
static int cmd_list(int argc, const char **argv)
static int cmd_list(int argc, const char **argv UNUSED)
{
if (argc != 1)
die(_("`scalar list` does not take arguments"));

View File

@ -47,7 +47,7 @@ static int is_in(const char *s, int ch)
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \
"\x7f"
int cmd__ctype(int argc, const char **argv)
int cmd__ctype(int argc UNUSED, const char **argv UNUSED)
{
TEST_CLASS(isdigit, DIGIT);
TEST_CLASS(isspace, " \n\r\t");

View File

@ -104,7 +104,7 @@ static void getnanos(const char **argv)
printf("%lf\n", seconds);
}
int cmd__date(int argc, const char **argv)
int cmd__date(int argc UNUSED, const char **argv)
{
const char *x;

View File

@ -155,7 +155,7 @@ static int cmd_dropcaches(void)
#endif
int cmd__drop_caches(int argc, const char **argv)
int cmd__drop_caches(int argc UNUSED, const char **argv UNUSED)
{
cmd_sync();
return cmd_dropcaches();

View File

@ -57,7 +57,7 @@ static int dump_cache_tree(struct cache_tree *it,
return errs;
}
int cmd__dump_cache_tree(int ac, const char **av)
int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
{
struct index_state istate;
struct cache_tree *another = cache_tree();

View File

@ -1,7 +1,7 @@
#include "test-tool.h"
#include "cache.h"
int cmd__dump_fsmonitor(int ac, const char **av)
int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED)
{
struct index_state *istate = the_repository->index;
int i;

View File

@ -10,7 +10,7 @@ static void show_bit(size_t pos, void *data)
printf(" %d", (int)pos);
}
int cmd__dump_split_index(int ac, const char **av)
int cmd__dump_split_index(int ac UNUSED, const char **av)
{
struct split_index *si;
int i;

View File

@ -41,7 +41,7 @@ static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
strbuf_setlen(base, len);
}
int cmd__dump_untracked_cache(int ac, const char **av)
int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
{
struct untracked_cache *uc;
struct strbuf base = STRBUF_INIT;

View File

@ -3,7 +3,7 @@
#include "object.h"
#include "decorate.h"
int cmd__example_decorate(int argc, const char **argv)
int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED)
{
struct decoration n;
struct object_id one_oid = { {1} };

View File

@ -11,7 +11,7 @@
#include "trace2.h"
#ifndef HAVE_FSMONITOR_DAEMON_BACKEND
int cmd__fsmonitor_client(int argc, const char **argv)
int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
{
die("fsmonitor--daemon not available on this platform");
}

View File

@ -4,7 +4,7 @@
/*
* Read stdin and print a hexdump to stdout.
*/
int cmd__hexdump(int argc, const char **argv)
int cmd__hexdump(int argc UNUSED, const char **argv UNUSED)
{
char buf[1024];
ssize_t i, len;

View File

@ -1,7 +1,7 @@
#include "test-tool.h"
#include "cache.h"
int cmd__index_version(int argc, const char **argv)
int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
{
struct cache_header hdr;
int version;

View File

@ -3,7 +3,7 @@
#include "hex.h"
#include "tree.h"
int cmd__match_trees(int ac, const char **av)
int cmd__match_trees(int ac UNUSED, const char **av)
{
struct object_id hash1, hash2, shifted;
struct tree *one, *two;

View File

@ -9,7 +9,7 @@ static int print_oid(const struct object_id *oid, void *data)
return 0;
}
int cmd__oid_array(int argc, const char **argv)
int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
{
struct oid_array array = OID_ARRAY_INIT;
struct strbuf line = STRBUF_INIT;

View File

@ -22,7 +22,7 @@ struct test_entry {
* iterate -> oidkey1 namevalue1\noidkey2 namevalue2\n...
*
*/
int cmd__oidmap(int argc, const char **argv)
int cmd__oidmap(int argc UNUSED, const char **argv UNUSED)
{
struct strbuf line = STRBUF_INIT;
struct oidmap map = OIDMAP_INIT;

View File

@ -3,13 +3,13 @@
#include "hex.h"
#include "oidtree.h"
static enum cb_next print_oid(const struct object_id *oid, void *data)
static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED)
{
puts(oid_to_hex(oid));
return CB_CONTINUE;
}
int cmd__oidtree(int argc, const char **argv)
int cmd__oidtree(int argc UNUSED, const char **argv UNUSED)
{
struct oidtree ot;
struct strbuf line = STRBUF_INIT;

View File

@ -2,7 +2,7 @@
#include "git-compat-util.h"
#include "thread-utils.h"
int cmd__online_cpus(int argc, const char **argv)
int cmd__online_cpus(int argc UNUSED, const char **argv UNUSED)
{
printf("%d\n", online_cpus());
return 0;

View File

@ -263,14 +263,14 @@ int cmd__parse_options_flags(int argc, const char **argv)
return parse_options_flags__cmd(argc, argv, test_flags);
}
static int subcmd_one(int argc, const char **argv, const char *prefix)
static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED)
{
printf("fn: subcmd_one\n");
print_args(argc, argv);
return 0;
}
static int subcmd_two(int argc, const char **argv, const char *prefix)
static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED)
{
printf("fn: subcmd_two\n");
print_args(argc, argv);

View File

@ -16,7 +16,7 @@ static void show(int *v)
free(v);
}
int cmd__prio_queue(int argc, const char **argv)
int cmd__prio_queue(int argc UNUSED, const char **argv)
{
struct prio_queue pq = { intcmp };

View File

@ -5,7 +5,7 @@
#include "object-store.h"
#include "bloom.h"
int cmd__read_graph(int argc, const char **argv)
int cmd__read_graph(int argc UNUSED, const char **argv UNUSED)
{
struct commit_graph *graph = NULL;
struct object_directory *odb;

View File

@ -201,7 +201,8 @@ static int cmd_verify_ref(struct ref_store *refs, const char **argv)
return ret;
}
static int cmd_for_each_reflog(struct ref_store *refs, const char **argv)
static int cmd_for_each_reflog(struct ref_store *refs,
const char **argv UNUSED)
{
return refs_for_each_reflog(refs, each_ref, NULL);
}
@ -323,7 +324,7 @@ static struct command commands[] = {
{ NULL, NULL }
};
int cmd__ref_store(int argc, const char **argv)
int cmd__ref_store(int argc UNUSED, const char **argv)
{
struct ref_store *refs;
const char *func;

View File

@ -5,7 +5,7 @@
#include "tree.h"
#include "cache-tree.h"
int cmd__scrap_cache_tree(int ac, const char **av)
int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
{
struct lock_file index_lock = LOCK_INIT;

View File

@ -13,7 +13,7 @@ X(two)
X(three)
#undef X
int cmd__sigchain(int argc, const char **argv)
int cmd__sigchain(int argc UNUSED, const char **argv UNUSED)
{
sigchain_push(SIGTERM, one);
sigchain_push(SIGTERM, two);

View File

@ -1,7 +1,7 @@
#include "test-tool.h"
#include "cache.h"
int cmd__strcmp_offset(int argc, const char **argv)
int cmd__strcmp_offset(int argc UNUSED, const char **argv)
{
int result;
size_t offset;

View File

@ -4,7 +4,7 @@
#include "submodule-config.h"
#include "submodule.h"
static void die_usage(int argc, const char **argv, const char *msg)
static void die_usage(int argc UNUSED, const char **argv, const char *msg)
{
fprintf(stderr, "%s\n", msg);
fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);

View File

@ -174,7 +174,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv)
usage_with_options(usage, options);
}
static int cmd__submodule_config_writeable(int argc, const char **argv)
static int cmd__submodule_config_writeable(int argc, const char **argv UNUSED)
{
struct option options[] = {
OPT_END()

View File

@ -208,7 +208,7 @@ static int ut_007BUG(int argc, const char **argv)
BUG("the bug message");
}
static int ut_008bug(int argc, const char **argv)
static int ut_008bug(int argc UNUSED, const char **argv UNUSED)
{
bug("a bug message");
bug("another bug message");
@ -216,7 +216,7 @@ static int ut_008bug(int argc, const char **argv)
return 0;
}
static int ut_009bug_BUG(int argc, const char **argv)
static int ut_009bug_BUG(int argc UNUSED, const char **argv UNUSED)
{
bug("a bug message");
bug("another bug message");
@ -224,7 +224,7 @@ static int ut_009bug_BUG(int argc, const char **argv)
return 0;
}
static int ut_010bug_BUG(int argc, const char **argv)
static int ut_010bug_BUG(int argc UNUSED, const char **argv UNUSED)
{
bug("a %s message", "bug");
BUG("a %s message", "BUG");

View File

@ -6,7 +6,7 @@ static const char *utf8_replace_character = "&#xfffd;";
* Encodes (possibly incorrect) UTF-8 on <stdin> to <stdout>, to be embedded
* in an XML file.
*/
int cmd__xml_encode(int argc, const char **argv)
int cmd__xml_encode(int argc UNUSED, const char **argv UNUSED)
{
unsigned char buf[1024], tmp[4], *tmp2 = NULL;
ssize_t cur = 0, len = 1, remaining = 0;

View File

@ -49,4 +49,33 @@ test_expect_success 'import with submodule mapping' '
test_cmp expect actual
'
test_expect_success 'paths adjusted for relative subdir' '
git init deep-dst &&
mkdir deep-dst/subdir &&
>deep-dst/subdir/empty-marks &&
git -C deep-dst/subdir fast-import \
--rewrite-submodules-from=sub:../../from \
--rewrite-submodules-to=sub:../../to \
--import-marks=empty-marks \
--export-marks=exported-marks \
--export-pack-edges=exported-edges \
<dump &&
# we do not bother checking resulting repo; we just care that nothing
# complained about failing to open files for reading, and that files
# for writing were created in the expected spot
test_path_is_file deep-dst/subdir/exported-marks &&
test_path_is_file deep-dst/subdir/exported-edges
'
test_expect_success 'relative marks are not affected by subdir' '
git init deep-relative &&
mkdir deep-relative/subdir &&
git -C deep-relative/subdir fast-import \
--relative-marks \
--export-marks=exported-marks \
<dump &&
test_path_is_missing deep-relative/subdir/exported-marks &&
test_path_is_file deep-relative/.git/info/fast-import/exported-marks
'
test_done