From patchwork Thu May 30 12:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13680373 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA29D183980 for ; Thu, 30 May 2024 12:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073514; cv=none; b=hAc3w384NoJuhwqG+OgVXZAqAulRKjqXagSkkkWBZj7StwBrrJ6LyHq10jALWsnxDzehAzE8tDRPvg2qe08WiWNZ5knX07ZzLnT6Lx/zt1wgN0/MtRG08bWbpzUfrF03hkV2/6Neo68SrSXSR3hC7HGwce/hrMk+oClhK+aOUFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073514; c=relaxed/simple; bh=jcEJzlGJqnFfHSv556k2aQTmvGJDBagBgx42CPRjB/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m1OBRivdWk/L7rOdNbGD/BEcfZ78+GmY1XuFD+4/8gF0Ns+ekYBtrHJ1HZVIx7Ca4FtCfhbZ6ECQrFJHZCj3JKhhLgVlye4NibNvfGLaxn49JK68aLxyYIMbAOnUgsX8d0A8/6u27tsKkix+0MXzV4W3M4/1V+GKCSdFAskseV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=BoOTE6M0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZzJ/VhEC; arc=none smtp.client-ip=103.168.172.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="BoOTE6M0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZzJ/VhEC" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id D8D3E13800D8; Thu, 30 May 2024 08:51:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 30 May 2024 08:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1717073511; x=1717159911; bh=J2CWK+/Okc C2V2enrJhjEesPiGjKfAdqmcDJOBNpRCo=; b=BoOTE6M09XnEtOhaaeomJ6DXWG r4p3ORbpS/KC9LgFb/oZ3V1IjNs7xKNi90ebbCHkA+XsI7vPQNzwNSxc5vgWyuiA DEi5usQUxh2xQCLJgSjipjK9KAH3fQ3Ci3AXJ+wiYexva/Pg4w1+6fVm7Yi/zjH8 Jx5m5pACRLWyU8f2hThkT4WmmnpVSUb+Fxke+jvGc9ghl6ZjXcjm2jTt8jIp/TpS tsFaIGCKUiOKmc29KH8Q8fCG5vXoHPyNhjB39PRy3QQK2/D67FGpAKeAeDvxKuLY 8ZBDF7LUowLhgwy7xegDwH8YP6Ma1OvblkElysNNMDzA+30KU5E0LmC9mfyQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717073511; x=1717159911; bh=J2CWK+/OkcC2V2enrJhjEesPiGjK fAdqmcDJOBNpRCo=; b=ZzJ/VhECHpBALHcGBnCuyuuG5S/HdCFprlfZ4GjXKH/9 JozB5zkkAEWOm1CG59ztXxxQnet7GOubfjx5K29zEn0gsFQ4GpNkEhNDjqsiKRFE ESdPEhDKyiCGqFVhitw/Uh6o5qKHWL2gqPMQ5G4+dbDqcy1sVo8YpEUNqUXkj+Fn jxZy7I8+zDi364I8z2/oxpQbjtab9+vRdhLbkPNQlHQUT7CB3QOMklWpKcv94W7u C6NgvA+lYQiJ6dpGEM65bDEhuKTQ6rSIoSSUNrarsOOkan2N+J2suzSvJDGUM5DZ JtSt6KZjbCYakiB2XB+FYYOSu5HOZvKZUAfYv8hF3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekgedgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 May 2024 08:51:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2928d956 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 30 May 2024 12:51:34 +0000 (UTC) Date: Thu, 30 May 2024 14:51:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 16/19] builtin/rebase: do not assign default backend to non-constant field Message-ID: <36a7b0a4b074e71dc07412d6d7c509dd4d90723e.1717073346.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `struct rebase_options::default_backend` field is a non-constant string, but is being assigned a constant via `REBASE_OPTIONS_INIT`. Refactor the code to initialize and release options via two functions `rebase_options_init()` and `rebase_options_release()`. Like this, we can easily adapt the former funnction to use `xstrdup()` on the default value without hiding it away in a macro. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 67 ++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 14d4f0a5e6..11f276012c 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -131,25 +131,40 @@ struct rebase_options { int config_update_refs; }; -#define REBASE_OPTIONS_INIT { \ - .type = REBASE_UNSPECIFIED, \ - .empty = EMPTY_UNSPECIFIED, \ - .keep_empty = 1, \ - .default_backend = "merge", \ - .flags = REBASE_NO_QUIET, \ - .git_am_opts = STRVEC_INIT, \ - .exec = STRING_LIST_INIT_NODUP, \ - .git_format_patch_opt = STRBUF_INIT, \ - .fork_point = -1, \ - .reapply_cherry_picks = -1, \ - .allow_empty_message = 1, \ - .autosquash = -1, \ - .rebase_merges = -1, \ - .config_rebase_merges = -1, \ - .update_refs = -1, \ - .config_update_refs = -1, \ - .strategy_opts = STRING_LIST_INIT_NODUP,\ - } +static void rebase_options_init(struct rebase_options *opts) +{ + memset(opts, 0, sizeof(*opts)); + opts->type = REBASE_UNSPECIFIED; + opts->empty = EMPTY_UNSPECIFIED; + opts->default_backend = xstrdup("merge"); + opts->keep_empty = 1; + opts->flags = REBASE_NO_QUIET; + strvec_init(&opts->git_am_opts); + string_list_init_nodup(&opts->exec); + strbuf_init(&opts->git_format_patch_opt, 0); + opts->fork_point = -1; + opts->reapply_cherry_picks = -1; + opts->allow_empty_message = 1; + opts->autosquash = -1; + opts->rebase_merges = -1; + opts->config_rebase_merges = -1; + opts->update_refs = -1; + opts->config_update_refs = -1; + string_list_init_nodup(&opts->strategy_opts); +} + +static void rebase_options_release(struct rebase_options *opts) +{ + free(opts->default_backend); + free(opts->reflog_action); + free(opts->head_name); + strvec_clear(&opts->git_am_opts); + free(opts->gpg_sign_opt); + string_list_clear(&opts->exec, 0); + free(opts->strategy); + string_list_clear(&opts->strategy_opts, 0); + strbuf_release(&opts->git_format_patch_opt); +} static struct replay_opts get_replay_opts(const struct rebase_options *opts) { @@ -796,6 +811,7 @@ static int rebase_config(const char *var, const char *value, } if (!strcmp(var, "rebase.backend")) { + FREE_AND_NULL(opts->default_backend); return git_config_string(&opts->default_backend, var, value); } @@ -1045,7 +1061,7 @@ static int check_exec_cmd(const char *cmd) int cmd_rebase(int argc, const char **argv, const char *prefix) { - struct rebase_options options = REBASE_OPTIONS_INIT; + struct rebase_options options; const char *branch_name; int ret, flags, total_argc, in_progress = 0; int keep_base = 0; @@ -1178,6 +1194,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) }; int i; + rebase_options_init(&options); + if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_rebase_usage, builtin_rebase_options); @@ -1833,14 +1851,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) cleanup: strbuf_release(&buf); strbuf_release(&revisions); - free(options.reflog_action); - free(options.head_name); - strvec_clear(&options.git_am_opts); - free(options.gpg_sign_opt); - string_list_clear(&options.exec, 0); - free(options.strategy); - string_list_clear(&options.strategy_opts, 0); - strbuf_release(&options.git_format_patch_opt); + rebase_options_release(&options); free(squash_onto_name); free(keep_base_onto_name); return !!ret;