Skip to content

Commit e885a84

Browse files
peffgitster
authored andcommitted
drop unused argc parameters
Many functions take an argv/argc pair, but never actually look at argc. This makes it useless at best (we use the NULL sentinel in argv to find the end of the array), and misleading at worst (what happens if the argc count does not match the argv NULL?). In each of these instances, the argv NULL does match the argc count, so there are no bugs here. But let's tighten the interfaces to make it harder to get wrong (and to reduce some -Wunused-parameter complaints). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 185e865 commit e885a84

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
239239
return status;
240240
}
241241

242-
int interactive_add(int argc, const char **argv, const char *prefix, int patch)
242+
int interactive_add(const char **argv, const char *prefix, int patch)
243243
{
244244
struct pathspec pathspec;
245245

@@ -451,7 +451,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
451451
if (add_interactive) {
452452
if (pathspec_from_file)
453453
die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
454-
exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
454+
exit(interactive_add(argv + 1, prefix, patch_interactive));
455455
}
456456
if (legacy_stash_p) {
457457
struct pathspec pathspec;

builtin/commit.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static void refresh_cache_or_die(int refresh_flags)
326326
die_resolve_conflict("commit");
327327
}
328328

329-
static const char *prepare_index(int argc, const char **argv, const char *prefix,
329+
static const char *prepare_index(const char **argv, const char *prefix,
330330
const struct commit *current_head, int is_status)
331331
{
332332
struct string_list partial = STRING_LIST_INIT_DUP;
@@ -378,7 +378,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
378378
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
379379
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
380380

381-
if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
381+
if (interactive_add(argv, prefix, patch_interactive) != 0)
382382
die(_("interactive add failed"));
383383

384384
the_repository->index_file = old_repo_index_file;
@@ -1241,13 +1241,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
12411241
return argc;
12421242
}
12431243

1244-
static int dry_run_commit(int argc, const char **argv, const char *prefix,
1244+
static int dry_run_commit(const char **argv, const char *prefix,
12451245
const struct commit *current_head, struct wt_status *s)
12461246
{
12471247
int committable;
12481248
const char *index_file;
12491249

1250-
index_file = prepare_index(argc, argv, prefix, current_head, 1);
1250+
index_file = prepare_index(argv, prefix, current_head, 1);
12511251
committable = run_status(stdout, index_file, prefix, 0, s);
12521252
rollback_index_files();
12531253

@@ -1584,8 +1584,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
15841584
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
15851585

15861586
if (dry_run)
1587-
return dry_run_commit(argc, argv, prefix, current_head, &s);
1588-
index_file = prepare_index(argc, argv, prefix, current_head, 0);
1587+
return dry_run_commit(argv, prefix, current_head, &s);
1588+
index_file = prepare_index(argv, prefix, current_head, 0);
15891589

15901590
/* Set up everything for writing the commit object. This includes
15911591
running hooks, writing the trees, and interacting with the user. */

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ struct oid_array;
248248
struct ref;
249249
int for_each_commit_graft(each_commit_graft_fn, void *);
250250

251-
int interactive_add(int argc, const char **argv, const char *prefix, int patch);
251+
int interactive_add(const char **argv, const char *prefix, int patch);
252252
int run_add_interactive(const char *revision, const char *patch_mode,
253253
const struct pathspec *pathspec);
254254

revision.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,8 +2580,8 @@ static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void
25802580
}
25812581

25822582
static int handle_revision_pseudo_opt(const char *submodule,
2583-
struct rev_info *revs,
2584-
int argc, const char **argv, int *flags)
2583+
struct rev_info *revs,
2584+
const char **argv, int *flags)
25852585
{
25862586
const char *arg = argv[0];
25872587
const char *optarg;
@@ -2752,7 +2752,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
27522752
int opts;
27532753

27542754
opts = handle_revision_pseudo_opt(submodule,
2755-
revs, argc - i, argv + i,
2755+
revs, argv + i,
27562756
&flags);
27572757
if (opts > 0) {
27582758
i += opts - 1;

t/helper/test-submodule-nested-repo-config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test-tool.h"
22
#include "submodule-config.h"
33

4-
static void die_usage(int argc, const char **argv, const char *msg)
4+
static void die_usage(const char **argv, const char *msg)
55
{
66
fprintf(stderr, "%s\n", msg);
77
fprintf(stderr, "Usage: %s <submodulepath> <config name>\n", argv[0]);
@@ -14,13 +14,13 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
1414
const struct submodule *sub;
1515

1616
if (argc < 3)
17-
die_usage(argc, argv, "Wrong number of arguments.");
17+
die_usage(argv, "Wrong number of arguments.");
1818

1919
setup_git_directory();
2020

2121
sub = submodule_from_path(the_repository, &null_oid, argv[1]);
2222
if (repo_submodule_init(&subrepo, the_repository, sub)) {
23-
die_usage(argc, argv, "Submodule not found.");
23+
die_usage(argv, "Submodule not found.");
2424
}
2525

2626
/* Read the config of _child_ submodules. */

0 commit comments

Comments
 (0)