git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 02/10] drop unused argc parameters
Date: Wed, 30 Sep 2020 08:28:18 -0400	[thread overview]
Message-ID: <20200930122818.GB1901279@coredump.intra.peff.net> (raw)
In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net>

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 <peff@peff.net>
---
 builtin/add.c                                |  4 ++--
 builtin/commit.c                             | 12 ++++++------
 commit.h                                     |  2 +-
 revision.c                                   |  6 +++---
 t/helper/test-submodule-nested-repo-config.c |  6 +++---
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index 26b6ced09e..a825887c50 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -239,7 +239,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
 	return status;
 }
 
-int interactive_add(int argc, const char **argv, const char *prefix, int patch)
+int interactive_add(const char **argv, const char *prefix, int patch)
 {
 	struct pathspec pathspec;
 
@@ -451,7 +451,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (add_interactive) {
 		if (pathspec_from_file)
 			die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
-		exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
+		exit(interactive_add(argv + 1, prefix, patch_interactive));
 	}
 	if (legacy_stash_p) {
 		struct pathspec pathspec;
diff --git a/builtin/commit.c b/builtin/commit.c
index 42b964e0ca..1dfd799ec5 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -326,7 +326,7 @@ static void refresh_cache_or_die(int refresh_flags)
 		die_resolve_conflict("commit");
 }
 
-static const char *prepare_index(int argc, const char **argv, const char *prefix,
+static const char *prepare_index(const char **argv, const char *prefix,
 				 const struct commit *current_head, int is_status)
 {
 	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
 		old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
 		setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
 
-		if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
+		if (interactive_add(argv, prefix, patch_interactive) != 0)
 			die(_("interactive add failed"));
 
 		the_repository->index_file = old_repo_index_file;
@@ -1241,13 +1241,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	return argc;
 }
 
-static int dry_run_commit(int argc, const char **argv, const char *prefix,
+static int dry_run_commit(const char **argv, const char *prefix,
 			  const struct commit *current_head, struct wt_status *s)
 {
 	int committable;
 	const char *index_file;
 
-	index_file = prepare_index(argc, argv, prefix, current_head, 1);
+	index_file = prepare_index(argv, prefix, current_head, 1);
 	committable = run_status(stdout, index_file, prefix, 0, s);
 	rollback_index_files();
 
@@ -1584,8 +1584,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
 
 	if (dry_run)
-		return dry_run_commit(argc, argv, prefix, current_head, &s);
-	index_file = prepare_index(argc, argv, prefix, current_head, 0);
+		return dry_run_commit(argv, prefix, current_head, &s);
+	index_file = prepare_index(argv, prefix, current_head, 0);
 
 	/* Set up everything for writing the commit object.  This includes
 	   running hooks, writing the trees, and interacting with the user.  */
diff --git a/commit.h b/commit.h
index e6f8f7c26f..5467786c7b 100644
--- a/commit.h
+++ b/commit.h
@@ -248,7 +248,7 @@ struct oid_array;
 struct ref;
 int for_each_commit_graft(each_commit_graft_fn, void *);
 
-int interactive_add(int argc, const char **argv, const char *prefix, int patch);
+int interactive_add(const char **argv, const char *prefix, int patch);
 int run_add_interactive(const char *revision, const char *patch_mode,
 			const struct pathspec *pathspec);
 
diff --git a/revision.c b/revision.c
index d9dc5781ac..aa62212040 100644
--- a/revision.c
+++ b/revision.c
@@ -2580,8 +2580,8 @@ static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void
 }
 
 static int handle_revision_pseudo_opt(const char *submodule,
-				struct rev_info *revs,
-				int argc, const char **argv, int *flags)
+				      struct rev_info *revs,
+				      const char **argv, int *flags)
 {
 	const char *arg = argv[0];
 	const char *optarg;
@@ -2752,7 +2752,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			int opts;
 
 			opts = handle_revision_pseudo_opt(submodule,
-						revs, argc - i, argv + i,
+						revs, argv + i,
 						&flags);
 			if (opts > 0) {
 				i += opts - 1;
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index bc97929bbc..c5fd4527dc 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -1,7 +1,7 @@
 #include "test-tool.h"
 #include "submodule-config.h"
 
-static void die_usage(int argc, const char **argv, const char *msg)
+static void die_usage(const char **argv, const char *msg)
 {
 	fprintf(stderr, "%s\n", msg);
 	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)
 	const struct submodule *sub;
 
 	if (argc < 3)
-		die_usage(argc, argv, "Wrong number of arguments.");
+		die_usage(argv, "Wrong number of arguments.");
 
 	setup_git_directory();
 
 	sub = submodule_from_path(the_repository, &null_oid, argv[1]);
 	if (repo_submodule_init(&subrepo, the_repository, sub)) {
-		die_usage(argc, argv, "Submodule not found.");
+		die_usage(argv, "Submodule not found.");
 	}
 
 	/* Read the config of _child_ submodules. */
-- 
2.28.0.1173.gad90222cf0


  parent reply	other threads:[~2020-09-30 12:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 12:27 [PATCH 0/10] dropping more unused parameters Jeff King
2020-09-30 12:27 ` [PATCH 01/10] convert: drop unused crlf_action from check_global_conv_flags_eol() Jeff King
2020-09-30 12:28 ` Jeff King [this message]
2020-09-30 12:28 ` [PATCH 03/10] env--helper: write to opt->value in parseopt helper Jeff King
2020-09-30 12:29 ` [PATCH 04/10] assert PARSE_OPT_NONEG in parse-options callbacks Jeff King
2020-09-30 12:29 ` [PATCH 05/10] push: drop unused repo argument to do_push() Jeff King
2020-09-30 12:29 ` [PATCH 06/10] sequencer: drop repository argument from run_git_commit() Jeff King
2020-09-30 12:30 ` [PATCH 07/10] sparse-checkout: fill in some options boilerplate Jeff King
2020-09-30 12:30 ` [PATCH 08/10] test-advise: check argument count with argc instead of argv Jeff King
2020-09-30 12:34 ` [PATCH 09/10] sequencer: handle ignore_footer when parsing trailers Jeff King
2020-09-30 12:35 ` [PATCH 10/10] dir.c: drop unused "untracked" from treat_path_fast() Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200930122818.GB1901279@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).