From patchwork Wed Sep 30 12:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF58B112C for ; Wed, 30 Sep 2020 12:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F38E207C3 for ; Wed, 30 Sep 2020 12:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729682AbgI3M1y (ORCPT ); Wed, 30 Sep 2020 08:27:54 -0400 Received: from cloud.peff.net ([104.130.231.41]:45282 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbgI3M1y (ORCPT ); Wed, 30 Sep 2020 08:27:54 -0400 Received: (qmail 23891 invoked by uid 109); 30 Sep 2020 12:27:54 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:27:54 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27894 invoked by uid 111); 30 Sep 2020 12:27:53 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:27:53 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:27:53 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 01/10] convert: drop unused crlf_action from check_global_conv_flags_eol() Message-ID: <20200930122753.GA1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The crlf_action parameter hasn't been used since a0ad53c181 (convert: Correct NNO tests and missing `LF will be replaced by CRLF`, 2016-08-13), where that part of the function was hoisted out to a separate will_convert_lf_to_crlf() helper. Let's drop the useless parameter. Signed-off-by: Jeff King --- convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convert.c b/convert.c index 8e6c292421..ee360c2f07 100644 --- a/convert.c +++ b/convert.c @@ -195,7 +195,7 @@ static enum eol output_eol(enum crlf_action crlf_action) return core_eol; } -static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_action, +static void check_global_conv_flags_eol(const char *path, struct text_stat *old_stats, struct text_stat *new_stats, int conv_flags) { @@ -547,7 +547,7 @@ static int crlf_to_git(const struct index_state *istate, new_stats.crlf += new_stats.lonelf; new_stats.lonelf = 0; } - check_global_conv_flags_eol(path, crlf_action, &stats, &new_stats, conv_flags); + check_global_conv_flags_eol(path, &stats, &new_stats, conv_flags); } if (!convert_crlf_into_lf) return 0; From patchwork Wed Sep 30 12:28:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 807EE6CA for ; Wed, 30 Sep 2020 12:28:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7130420789 for ; Wed, 30 Sep 2020 12:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729665AbgI3M2U (ORCPT ); Wed, 30 Sep 2020 08:28:20 -0400 Received: from cloud.peff.net ([104.130.231.41]:45288 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728294AbgI3M2U (ORCPT ); Wed, 30 Sep 2020 08:28:20 -0400 Received: (qmail 23905 invoked by uid 109); 30 Sep 2020 12:28:19 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:28:19 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27916 invoked by uid 111); 30 Sep 2020 12:28:18 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:28:18 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:28:18 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 02/10] drop unused argc parameters Message-ID: <20200930122818.GB1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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 \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. */ From patchwork Wed Sep 30 12:28:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A08146CA for ; Wed, 30 Sep 2020 12:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8846720789 for ; Wed, 30 Sep 2020 12:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728294AbgI3M2d (ORCPT ); Wed, 30 Sep 2020 08:28:33 -0400 Received: from cloud.peff.net ([104.130.231.41]:45294 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgI3M2d (ORCPT ); Wed, 30 Sep 2020 08:28:33 -0400 Received: (qmail 23915 invoked by uid 109); 30 Sep 2020 12:28:33 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:28:33 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27932 invoked by uid 111); 30 Sep 2020 12:28:32 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:28:32 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:28:32 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 03/10] env--helper: write to opt->value in parseopt helper Message-ID: <20200930122832.GC1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We use OPT_CALLBACK_F() to call the option_parse_type() callback, passing it the address of "cmdmode" as the value to write to. But the callback doesn't look at opt->value at all, and instead writes to a global variable. This works out because that's the same global variable we happen to pass in, but it's rather confusing. Let's use the passed-in value instead. We'll also make "cmdmode" a local variable of the main function, ensuring we can't make the same mistake again. Signed-off-by: Jeff King --- builtin/env--helper.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/env--helper.c b/builtin/env--helper.c index 23c214fff6..3aa4282114 100644 --- a/builtin/env--helper.c +++ b/builtin/env--helper.c @@ -7,18 +7,20 @@ static char const * const env__helper_usage[] = { NULL }; -static enum { +enum cmdmode { ENV_HELPER_TYPE_BOOL = 1, ENV_HELPER_TYPE_ULONG -} cmdmode = 0; +}; static int option_parse_type(const struct option *opt, const char *arg, int unset) { + enum cmdmode *cmdmode = opt->value; + if (!strcmp(arg, "bool")) - cmdmode = ENV_HELPER_TYPE_BOOL; + *cmdmode = ENV_HELPER_TYPE_BOOL; else if (!strcmp(arg, "ulong")) - cmdmode = ENV_HELPER_TYPE_ULONG; + *cmdmode = ENV_HELPER_TYPE_ULONG; else die(_("unrecognized --type argument, %s"), arg); @@ -33,6 +35,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix) int ret; int ret_int, default_int; unsigned long ret_ulong, default_ulong; + enum cmdmode cmdmode = 0; struct option opts[] = { OPT_CALLBACK_F(0, "type", &cmdmode, N_("type"), N_("value is given this type"), PARSE_OPT_NONEG, From patchwork Wed Sep 30 12:29:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 754D46CA for ; Wed, 30 Sep 2020 12:29:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E4D22076E for ; Wed, 30 Sep 2020 12:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729677AbgI3M3D (ORCPT ); Wed, 30 Sep 2020 08:29:03 -0400 Received: from cloud.peff.net ([104.130.231.41]:45300 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgI3M3D (ORCPT ); Wed, 30 Sep 2020 08:29:03 -0400 Received: (qmail 23929 invoked by uid 109); 30 Sep 2020 12:29:03 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:29:03 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27948 invoked by uid 111); 30 Sep 2020 12:29:02 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:29:02 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:29:02 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 04/10] assert PARSE_OPT_NONEG in parse-options callbacks Message-ID: <20200930122902.GD1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the spirit of 517fe807d6 (assert NOARG/NONEG behavior of parse-options callbacks, 2018-11-05), let's cover some parse-options callbacks which expect to be used with PARSE_OPT_NONEG but don't explicitly assert that this is the case. These callbacks are all used correctly in the current code, but this will help document their expectations and future-proof the code. As a bonus, it also silences -Wunused-parameters (these were added since the initial sweep of 517fe807d6, and we can't yet turn on -Wunused-parameters to remind people because it has too many existing false positives). Signed-off-by: Jeff King --- builtin/am.c | 2 ++ builtin/commit-graph.c | 2 ++ builtin/env--helper.c | 2 ++ parse-options-cb.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/builtin/am.c b/builtin/am.c index 7259186408..2c7673f74e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar }; int new_value = SHOW_PATCH_RAW; + BUG_ON_OPT_NEG(unset); + if (arg) { for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) { if (!strcmp(arg, valid_modes[new_value])) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 988445abdf..78fa08f43a 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg, { enum commit_graph_split_flags *flags = opt->value; + BUG_ON_OPT_NEG(unset); + opts.split = 1; if (!arg) return 0; diff --git a/builtin/env--helper.c b/builtin/env--helper.c index 3aa4282114..27349098b0 100644 --- a/builtin/env--helper.c +++ b/builtin/env--helper.c @@ -17,6 +17,8 @@ static int option_parse_type(const struct option *opt, const char *arg, { enum cmdmode *cmdmode = opt->value; + BUG_ON_OPT_NEG(unset); + if (!strcmp(arg, "bool")) *cmdmode = ENV_HELPER_TYPE_BOOL; else if (!strcmp(arg, "ulong")) diff --git a/parse-options-cb.c b/parse-options-cb.c index d9d3b0819f..4542d4d3f9 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset) struct commit *commit; struct commit **target = opt->value; + BUG_ON_OPT_NEG(unset); + if (!arg) return -1; if (get_oid(arg, &oid)) From patchwork Wed Sep 30 12:29:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0A95112C for ; Wed, 30 Sep 2020 12:29:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D225D20789 for ; Wed, 30 Sep 2020 12:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728296AbgI3M3L (ORCPT ); Wed, 30 Sep 2020 08:29:11 -0400 Received: from cloud.peff.net ([104.130.231.41]:45306 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgI3M3K (ORCPT ); Wed, 30 Sep 2020 08:29:10 -0400 Received: (qmail 23937 invoked by uid 109); 30 Sep 2020 12:29:10 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:29:10 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27964 invoked by uid 111); 30 Sep 2020 12:29:09 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:29:09 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:29:09 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 05/10] push: drop unused repo argument to do_push() Message-ID: <20200930122909.GE1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We stopped using the "repo" argument in 8e4c8af058 (push: disallow --all and refspecs when remote..mirror is set, 2019-09-02), which moved the pushremote handling to its caller. Signed-off-by: Jeff King --- builtin/push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/push.c b/builtin/push.c index 0eeb2c8dd5..6da3a8e5d3 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -379,7 +379,7 @@ static int push_with_options(struct transport *transport, struct refspec *rs, return 1; } -static int do_push(const char *repo, int flags, +static int do_push(int flags, const struct string_list *push_options, struct remote *remote) { @@ -629,7 +629,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) if (strchr(item->string, '\n')) die(_("push options must not have new line characters")); - rc = do_push(repo, flags, push_options, remote); + rc = do_push(flags, push_options, remote); string_list_clear(&push_options_cmdline, 0); string_list_clear(&push_options_config, 0); if (rc == -1) From patchwork Wed Sep 30 12:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83E22112C for ; Wed, 30 Sep 2020 12:29:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 698032071E for ; Wed, 30 Sep 2020 12:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729596AbgI3M3c (ORCPT ); Wed, 30 Sep 2020 08:29:32 -0400 Received: from cloud.peff.net ([104.130.231.41]:45316 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgI3M3c (ORCPT ); Wed, 30 Sep 2020 08:29:32 -0400 Received: (qmail 23951 invoked by uid 109); 30 Sep 2020 12:29:32 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:29:32 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 27998 invoked by uid 111); 30 Sep 2020 12:29:31 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:29:31 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:29:31 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 06/10] sequencer: drop repository argument from run_git_commit() Message-ID: <20200930122931.GF1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we switched to using an external git-commit call in b0a3186140 (sequencer: simplify root commit creation, 2019-08-19), this function didn't need to care about the repository object any more. Arguably we could be passing along the repository path to the external git-commit by using "--git-dir=r->path" here. But for the most part the sequencer code relies on sub-process finding the same repository we're already in (using the same environment variables or discovery process we did). But we don't have a convenient interface for doing so, and there's no indication that we need to. Let's just drop the unused parameter for now. Signed-off-by: Jeff King --- sequencer.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index e8676e965f..6e9aabaac1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -934,8 +934,7 @@ static int run_command_silent_on_success(struct child_process *cmd) * interactive rebase: in that case, we will want to retain the * author metadata. */ -static int run_git_commit(struct repository *r, - const char *defmsg, +static int run_git_commit(const char *defmsg, struct replay_opts *opts, unsigned int flags) { @@ -1545,7 +1544,7 @@ static int do_commit(struct repository *r, if (is_rebase_i(opts) && oid) if (write_rebase_head(oid)) return -1; - return run_git_commit(r, msg_file, opts, flags); + return run_git_commit(msg_file, opts, flags); } return res; @@ -2060,7 +2059,7 @@ static int do_pick_commit(struct repository *r, *check_todo = !!(flags & EDIT_MSG); if (!res && reword) { fast_forward_edit: - res = run_git_commit(r, NULL, opts, EDIT_MSG | + res = run_git_commit(NULL, opts, EDIT_MSG | VERIFY_MSG | AMEND_MSG | (flags & ALLOW_EMPTY)); *check_todo = 1; @@ -3748,7 +3747,7 @@ static int do_merge(struct repository *r, * command needs to be rescheduled). */ fast_forward_edit: - ret = !!run_git_commit(r, git_path_merge_msg(r), opts, + ret = !!run_git_commit(git_path_merge_msg(r), opts, run_commit_flags); leave_merge: @@ -4437,7 +4436,7 @@ static int commit_staged_changes(struct repository *r, return 0; } - if (run_git_commit(r, final_fixup ? NULL : rebase_path_message(), + if (run_git_commit(final_fixup ? NULL : rebase_path_message(), opts, flags)) return error(_("could not commit staged changes.")); unlink(rebase_path_amend()); From patchwork Wed Sep 30 12:30:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00E416CA for ; Wed, 30 Sep 2020 12:30:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E71862071E for ; Wed, 30 Sep 2020 12:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729798AbgI3MaL (ORCPT ); Wed, 30 Sep 2020 08:30:11 -0400 Received: from cloud.peff.net ([104.130.231.41]:45322 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729762AbgI3MaL (ORCPT ); Wed, 30 Sep 2020 08:30:11 -0400 Received: (qmail 23966 invoked by uid 109); 30 Sep 2020 12:30:11 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:30:11 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 28014 invoked by uid 111); 30 Sep 2020 12:30:10 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:30:10 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:30:10 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 07/10] sparse-checkout: fill in some options boilerplate Message-ID: <20200930123010.GG1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The sparse-checkout passes along argv and argc to its sub-command helper functions. Many of these sub-commands do not yet take any command-line options, and ignore those parameters. Let's instead add empty option lists and make sure we call parse_options(). That will give a useful error message for something like: git sparse-checkout list --nonsense which currently just silently ignores the unknown option. As a bonus, it also silences some -Wunused-parameter warnings. Signed-off-by: Jeff King --- builtin/sparse-checkout.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 4003f4d13a..e3140db2a0 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -46,12 +46,24 @@ static void write_patterns_to_file(FILE *fp, struct pattern_list *pl) } } +static char const * const builtin_sparse_checkout_list_usage[] = { + N_("git sparse-checkout list"), + NULL +}; + static int sparse_checkout_list(int argc, const char **argv) { + static struct option builtin_sparse_checkout_list_options[] = { + OPT_END(), + }; struct pattern_list pl; char *sparse_filename; int res; + argc = parse_options(argc, argv, NULL, + builtin_sparse_checkout_list_options, + builtin_sparse_checkout_list_usage, 0); + memset(&pl, 0, sizeof(pl)); pl.use_cone_patterns = core_sparse_checkout_cone; @@ -560,17 +572,42 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix, return modify_pattern_list(argc, argv, m); } +static char const * const builtin_sparse_checkout_reapply_usage[] = { + N_("git sparse-checkout reapply"), + NULL +}; + static int sparse_checkout_reapply(int argc, const char **argv) { + static struct option builtin_sparse_checkout_reapply_options[] = { + OPT_END(), + }; + + argc = parse_options(argc, argv, NULL, + builtin_sparse_checkout_reapply_options, + builtin_sparse_checkout_reapply_usage, 0); + repo_read_index(the_repository); return update_working_directory(NULL); } +static char const * const builtin_sparse_checkout_disable_usage[] = { + N_("git sparse-checkout disable"), + NULL +}; + static int sparse_checkout_disable(int argc, const char **argv) { + static struct option builtin_sparse_checkout_disable_options[] = { + OPT_END(), + }; struct pattern_list pl; struct strbuf match_all = STRBUF_INIT; + argc = parse_options(argc, argv, NULL, + builtin_sparse_checkout_disable_options, + builtin_sparse_checkout_disable_usage, 0); + repo_read_index(the_repository); memset(&pl, 0, sizeof(pl)); From patchwork Wed Sep 30 12:30:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEDDB6CA for ; Wed, 30 Sep 2020 12:30:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E11522071E for ; Wed, 30 Sep 2020 12:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729871AbgI3Ma2 (ORCPT ); Wed, 30 Sep 2020 08:30:28 -0400 Received: from cloud.peff.net ([104.130.231.41]:45328 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729762AbgI3Ma2 (ORCPT ); Wed, 30 Sep 2020 08:30:28 -0400 Received: (qmail 23980 invoked by uid 109); 30 Sep 2020 12:30:28 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:30:28 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 28030 invoked by uid 111); 30 Sep 2020 12:30:27 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:30:27 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:30:27 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 08/10] test-advise: check argument count with argc instead of argv Message-ID: <20200930123027.GH1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We complain if "test-tool advise" is not given an argument, but we quietly ignore any additional arguments it receives. Let's instead check that we got the expected number. As a bonus, this silences -Wunused-parameter, which notes that we don't ever look at argc. While we're here, we can also fix the indentation in the conditional. Signed-off-by: Jeff King --- t/helper/test-advise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c index 38cdc2884e..a7043df1d3 100644 --- a/t/helper/test-advise.c +++ b/t/helper/test-advise.c @@ -5,8 +5,8 @@ int cmd__advise_if_enabled(int argc, const char **argv) { - if (!argv[1]) - die("usage: %s ", argv[0]); + if (argc != 2) + die("usage: %s ", argv[0]); setup_git_directory(); git_config(git_default_config, NULL); From patchwork Wed Sep 30 12:34:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11808999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DFD392C for ; Wed, 30 Sep 2020 12:34:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FBD02071E for ; Wed, 30 Sep 2020 12:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729516AbgI3MeN (ORCPT ); Wed, 30 Sep 2020 08:34:13 -0400 Received: from cloud.peff.net ([104.130.231.41]:45334 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728042AbgI3MeM (ORCPT ); Wed, 30 Sep 2020 08:34:12 -0400 Received: (qmail 24039 invoked by uid 109); 30 Sep 2020 12:34:12 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:34:12 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 28121 invoked by uid 111); 30 Sep 2020 12:34:12 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:34:12 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:34:11 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 09/10] sequencer: handle ignore_footer when parsing trailers Message-ID: <20200930123411.GI1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The append_signoff() function takes an "ignore_footer" argument, which specifies a number of bytes at the end of the message buffer which should not be considered (they cannot contain trailers, and the trailer is spliced in before them). But to find the existing trailers, it calls into has_conforming_trailer(). That function takes an ignore_footer parameter, but since 967dfd4d56 (sequencer: use trailer's trailer layout, 2016-11-02) the parameter is completely ignored. The trailer interface we're using takes a single string, with no option to tell it to use part of the string. However, since we have a mutable strbuf, we can work around this by simply overwriting (and later restoring) the boundary with a NUL. I'm not sure if this can actually trigger a bug in practice. It's easy to get a non-zero ignore_footer by doing something like this: git commit -F - --cleanup=verbatim <<-EOF subject body Signed-off-by: me # this looks like a comment, but is actually in the # message! That makes the earlier s-o-b fake. EOF git commit --amend -s There git-commit calls ignore_non_trailer() to count up the "#" cruft, which becomes the ignore_footer header. But it works even without this patch! That's because the trailer code _also_ calls ignore_non_trailer() and skips the cruft, too. So it happens to work because the only callers with a non-zero ignore_footer are using the exact same function that the trailer parser uses internally. And that seems true for all of the current callers, but there's nothing guaranteeing it. We're better off only feeding the correct buffer to the trailer code in the first place. Signed-off-by: Jeff King --- This was actually posted as part of an earlier series: https://lore.kernel.org/git/20180824072629.GA11977@sigill.intra.peff.net/ It ended as: I think patch 9 is not hurting anything and may later help us, but I could take or leave it. and we left it. But now I have the ulterior motive of wanting to get rid of the unused parameter warning. :) Another option would be to leave the code as-is and just drop the ignored parameter. But I think this is probably a safe and reasonable patch (I've been running with it in my personal fork for 2 years, though perhaps I don't really exercise the trailer code's corner cases myself). sequencer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sequencer.c b/sequencer.c index 6e9aabaac1..e454264fbc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -249,11 +249,20 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob, struct trailer_info info; size_t i; int found_sob = 0, found_sob_last = 0; + char saved_char; opts.no_divider = 1; + if (ignore_footer) { + saved_char = sb->buf[sb->len - ignore_footer]; + sb->buf[sb->len - ignore_footer] = '\0'; + } + trailer_info_get(&info, sb->buf, &opts); + if (ignore_footer) + sb->buf[sb->len - ignore_footer] = saved_char; + if (info.trailer_start == info.trailer_end) return 0; From patchwork Wed Sep 30 12:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11809001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E40292C for ; Wed, 30 Sep 2020 12:35:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9E402076E for ; Wed, 30 Sep 2020 12:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729666AbgI3MfC (ORCPT ); Wed, 30 Sep 2020 08:35:02 -0400 Received: from cloud.peff.net ([104.130.231.41]:45340 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbgI3MfB (ORCPT ); Wed, 30 Sep 2020 08:35:01 -0400 Received: (qmail 24050 invoked by uid 109); 30 Sep 2020 12:35:01 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 30 Sep 2020 12:35:01 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 28138 invoked by uid 111); 30 Sep 2020 12:35:01 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 30 Sep 2020 08:35:01 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 30 Sep 2020 08:35:00 -0400 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 10/10] dir.c: drop unused "untracked" from treat_path_fast() Message-ID: <20200930123500.GJ1901279@coredump.intra.peff.net> References: <20200930122732.GA1901036@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200930122732.GA1901036@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We don't use the untracked_cache_dir parameter that is passed in, but instead look at the untracked_cache_dir inside the cached_dir struct we are passed. It's been this way since the introduction of treat_path_fast() in 91a2288b5f (untracked cache: record/validate dir mtime and reuse cached output, 2015-03-08). Signed-off-by: Jeff King --- This is the one I'm least sure of (not that it makes anything worse, but that it might be hiding a bug; I'm pretty sure I just don't understand how the untracked-cache code works, though). dir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dir.c b/dir.c index 3018a657b0..78387110e6 100644 --- a/dir.c +++ b/dir.c @@ -2105,7 +2105,6 @@ static int resolve_dtype(int dtype, struct index_state *istate, } static enum path_treatment treat_path_fast(struct dir_struct *dir, - struct untracked_cache_dir *untracked, struct cached_dir *cdir, struct index_state *istate, struct strbuf *path, @@ -2153,7 +2152,7 @@ static enum path_treatment treat_path(struct dir_struct *dir, int has_path_in_index, dtype, excluded; if (!cdir->d_name) - return treat_path_fast(dir, untracked, cdir, istate, path, + return treat_path_fast(dir, cdir, istate, path, baselen, pathspec); if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git")) return path_none;