From: Jeff King <peff@peff.net>
To: Izzy via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>,
Izzy <winglovet@gmail.com>
Subject: Re: [PATCH v4] merge-tree: add -X strategy option
Date: Sat, 16 Sep 2023 02:11:14 -0400 [thread overview]
Message-ID: <20230916061114.GF13092@coredump.intra.peff.net> (raw)
In-Reply-To: <pull.1565.v4.git.1694836025469.gitgitgadget@gmail.com>
On Sat, Sep 16, 2023 at 03:47:05AM +0000, Izzy via GitGitGadget wrote:
> +static int option_parse_x(const struct option *opt,
> + const char *arg, int unset)
> +{
> + if (unset)
> + return 0;
> +
> + ALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc);
> + xopts[xopts_nr++] = xstrdup(arg);
> + return 0;
> +}
This callback was presumably copied from the one in builtin/merge.c, and
it suffers from the same "--no-strategy-option" bug. You should make a
similar change here to the one we did in dee02da826 (merge: make xopts a
strvec, 2023-08-31). And as a bonus, it will make your patch even
shorter. :)
It would also make it easier to get rid of the global variables, I
think. Something like (squashed into your patch):
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 2ec6ec0d39..e13dbc4c79 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -18,9 +18,8 @@
#include "quote.h"
#include "tree.h"
#include "config.h"
+#include "strvec.h"
-static const char **xopts;
-static size_t xopts_nr, xopts_alloc;
static int line_termination = '\n';
struct merge_list {
@@ -515,20 +514,10 @@ static int real_merge(struct merge_tree_options *o,
return !result.clean; /* result.clean < 0 handled above */
}
-static int option_parse_x(const struct option *opt,
- const char *arg, int unset)
-{
- if (unset)
- return 0;
-
- ALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc);
- xopts[xopts_nr++] = xstrdup(arg);
- return 0;
-}
-
int cmd_merge_tree(int argc, const char **argv, const char *prefix)
{
struct merge_tree_options o = { .show_messages = -1 };
+ struct strvec xopts = STRVEC_INIT;
int expected_remaining_argc;
int original_argc;
const char *merge_base = NULL;
@@ -564,10 +553,8 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
&merge_base,
N_("commit"),
N_("specify a merge-base for the merge")),
- OPT_CALLBACK('X', "strategy-option", &xopts,
- N_("option=value"),
- N_("option for selected merge strategy"),
- option_parse_x),
+ OPT_STRVEC('X', "strategy-option", &xopts, N_("option=value"),
+ N_("option for selected merge strategy")),
OPT_END()
};
@@ -576,9 +563,9 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, mt_options,
merge_tree_usage, PARSE_OPT_STOP_AT_NON_OPTION);
- for (int x = 0; x < xopts_nr; x++)
- if (parse_merge_opt(&o.merge_options, xopts[x]))
- die(_("unknown strategy option: -X%s"), xopts[x]);
+ for (int x = 0; x < xopts.nr; x++)
+ if (parse_merge_opt(&o.merge_options, xopts.v[x]))
+ die(_("unknown strategy option: -X%s"), xopts.v[x]);
/* Handle --stdin */
if (o.use_stdin) {
next prev parent reply other threads:[~2023-09-16 6:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-05 14:24 [PATCH] merge-tree: add -X strategy option Izzy via GitGitGadget
2023-08-07 2:10 ` Junio C Hamano
2023-08-12 5:33 ` [PATCH v2] " Izzy via GitGitGadget
2023-08-12 5:41 ` 唐宇奕
2023-09-03 1:31 ` 唐宇奕
2023-09-12 15:03 ` Elijah Newren
2023-09-16 2:14 ` [PATCH v3] " Izzy via GitGitGadget
2023-09-16 2:26 ` 唐宇奕
2023-09-16 3:21 ` Elijah Newren
2023-09-16 3:16 ` Elijah Newren
2023-09-16 3:47 ` [PATCH v4] " Izzy via GitGitGadget
2023-09-16 3:55 ` Elijah Newren
2023-09-16 4:04 ` 唐宇奕
2023-09-16 6:11 ` Jeff King [this message]
2023-09-16 8:37 ` [PATCH v5] " Izzy via GitGitGadget
2023-09-16 8:38 ` 唐宇奕
2023-09-18 9:53 ` Phillip Wood
2023-09-18 16:08 ` Junio C Hamano
2023-09-24 2:23 ` [PATCH v6] " Izzy via GitGitGadget
2023-09-24 2:26 ` 唐宇奕
2023-10-09 9:58 ` Phillip Wood
2023-10-09 15:53 ` Jeff King
2023-10-09 17:10 ` Junio C Hamano
2023-10-09 18:52 ` Jeff King
2023-10-11 19:38 ` Junio C Hamano
2023-10-11 21:43 ` Jeff King
2023-10-11 22:19 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230916061114.GF13092@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=newren@gmail.com \
--cc=winglovet@gmail.com \
/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.
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 NNTP newsgroup(s).