Skip to content

Commit 955abf5

Browse files
committed
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
2 parents 9bc647a + 4a4d970 commit 955abf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+115
-74
lines changed

builtin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ void setup_auto_pager(const char *cmd, int def);
107107

108108
int is_builtin(const char *s);
109109

110+
/*
111+
* Builtins which do not use RUN_SETUP should never see
112+
* a prefix that is not empty; use this to protect downstream
113+
* code which is not prepared to call prefix_filename(), etc.
114+
*/
115+
#define BUG_ON_NON_EMPTY_PREFIX(prefix) do { \
116+
if ((prefix)) \
117+
BUG("unexpected prefix in builtin: %s", (prefix)); \
118+
} while (0)
119+
110120
int cmd_add(int argc, const char **argv, const char *prefix);
111121
int cmd_am(int argc, const char **argv, const char *prefix);
112122
int cmd_annotate(int argc, const char **argv, const char *prefix);

builtin/check-ref-format.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
6060
char *to_free = NULL;
6161
int ret = 1;
6262

63+
BUG_ON_NON_EMPTY_PREFIX(prefix);
64+
6365
if (argc == 2 && !strcmp(argv[1], "-h"))
6466
usage(builtin_check_ref_format_usage);
6567

builtin/credential.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
static const char usage_msg[] =
77
"git credential (fill|approve|reject)";
88

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)
1010
{
1111
const char *op;
1212
struct credential c = CREDENTIAL_INIT;

builtin/diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void stuff_change(struct diff_options *opt,
7474
}
7575

7676
static int builtin_diff_b_f(struct rev_info *revs,
77-
int argc, const char **argv,
77+
int argc, const char **argv UNUSED,
7878
struct object_array_entry **blob)
7979
{
8080
/* Blob vs file in the working tree*/
@@ -109,7 +109,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
109109
}
110110

111111
static int builtin_diff_blobs(struct rev_info *revs,
112-
int argc, const char **argv,
112+
int argc, const char **argv UNUSED,
113113
struct object_array_entry **blob)
114114
{
115115
const unsigned mode = canon_mode(S_IFREG | 0644);
@@ -209,7 +209,7 @@ static int builtin_diff_tree(struct rev_info *revs,
209209
}
210210

211211
static int builtin_diff_combined(struct rev_info *revs,
212-
int argc, const char **argv,
212+
int argc, const char **argv UNUSED,
213213
struct object_array_entry *ent,
214214
int ents, int first_non_parent)
215215
{

builtin/fast-import.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static FILE *pack_edges;
176176
static unsigned int show_stats = 1;
177177
static int global_argc;
178178
static const char **global_argv;
179+
static const char *global_prefix;
179180

180181
/* Memory pools */
181182
static struct mem_pool fi_mem_pool = {
@@ -3246,7 +3247,7 @@ static void parse_alias(void)
32463247
static char* make_fast_import_path(const char *path)
32473248
{
32483249
if (!relative_marks_paths || is_absolute_path(path))
3249-
return xstrdup(path);
3250+
return prefix_filename(global_prefix, path);
32503251
return git_pathdup("info/fast-import/%s", path);
32513252
}
32523253

@@ -3317,9 +3318,11 @@ static void option_cat_blob_fd(const char *fd)
33173318

33183319
static void option_export_pack_edges(const char *edges)
33193320
{
3321+
char *fn = prefix_filename(global_prefix, edges);
33203322
if (pack_edges)
33213323
fclose(pack_edges);
3322-
pack_edges = xfopen(edges, "a");
3324+
pack_edges = xfopen(fn, "a");
3325+
free(fn);
33233326
}
33243327

33253328
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)
33343337
f++;
33353338
CALLOC_ARRAY(ms, 1);
33363339

3340+
f = prefix_filename(global_prefix, f);
33373341
fp = fopen(f, "r");
33383342
if (!fp)
33393343
die_errno("cannot read '%s'", f);
33403344
read_mark_file(&ms, fp, insert_oid_entry);
33413345
fclose(fp);
3346+
free(f);
33423347

33433348
string_list_insert(list, s)->util = ms;
33443349
}
@@ -3552,6 +3557,7 @@ int cmd_fast_import(int argc, const char **argv, const char *prefix)
35523557

35533558
global_argc = argc;
35543559
global_argv = argv;
3560+
global_prefix = prefix;
35553561

35563562
rc_free = mem_pool_alloc(&fi_mem_pool, cmd_save * sizeof(*rc_free));
35573563
for (i = 0; i < (cmd_save - 1); i++)

builtin/fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
4242
(*sought)[*nr - 1] = ref;
4343
}
4444

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)
4646
{
4747
int i, ret;
4848
struct ref *ref = NULL;

builtin/fsmonitor--daemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
15751575
}
15761576

15771577
#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)
15791579
{
15801580
struct option options[] = {
15811581
OPT_END()

builtin/get-tar-commit-id.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static const char builtin_get_tar_commit_id_usage[] =
1414
#define RECORDSIZE (512)
1515
#define HEADERSIZE (2 * RECORDSIZE)
1616

17-
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
17+
int cmd_get_tar_commit_id(int argc, const char **argv UNUSED, const char *prefix)
1818
{
1919
char buffer[HEADERSIZE];
2020
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)
2424
long len;
2525
char *end;
2626

27+
BUG_ON_NON_EMPTY_PREFIX(prefix);
28+
2729
if (argc != 1)
2830
usage(builtin_get_tar_commit_id_usage);
2931

builtin/mailsplit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
277277
const char **argp;
278278
static const char *stdin_only[] = { "-", NULL };
279279

280+
BUG_ON_NON_EMPTY_PREFIX(prefix);
281+
280282
for (argp = argv+1; *argp; argp++) {
281283
const char *arg = *argp;
282284

builtin/merge-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void merge_all(void)
7171
}
7272
}
7373

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)
7575
{
7676
int i, force_file = 0;
7777

0 commit comments

Comments
 (0)