From patchwork Mon Jun 3 09:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13683493 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 58DB58565A for ; Mon, 3 Jun 2024 09:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407659; cv=none; b=LUbFVzHXPEcI1rtLI6VYOxPppDq8XqjwG24lC+KDa39z2gEH3Njfen53wtftRXQHJ43h5aQ9vYqeMOna/7Ovabd2EEW7MyIxaNbZ4P1zIE5DmkcDQSzaOLUtlgJ/ogMNhV/o+MbQ29O4+NWcdw546Fb9KyuH9+Xrel9IEd+mO1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407659; c=relaxed/simple; bh=gSABFHU3qEEE1AM/xwml1VKAlh4sKBR4xHhmkVjPjmM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AF7D3pxUN7kj6afKSs+bxRZyPd/NxyKfrLlaGhsZxxk+Jvb2WQdMUiRgxZDwhWPh1lESLT+DFObkNouJ3XdH7YT4lNhY5VXGVMUqK1J4mceQcJYDTfymGinPlkXKt0yW1EKapDSH+FAhie4xfibzXzWn8HEMVVXfL53nKsfgwcM= 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=pQneYuCr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Bh910Sv5; arc=none smtp.client-ip=64.147.123.147 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="pQneYuCr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Bh910Sv5" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 9B9B01C000D9; Mon, 3 Jun 2024 05:40:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 03 Jun 2024 05:40:57 -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=1717407657; x=1717494057; bh=PIhSsmpN2D bdHycRqSo6eX2QIxwomAU+bpr93CyHfJQ=; b=pQneYuCrIruKBDf8XDv8PqFVld p9TPTOlqGqC3b3+8KijksZm3cdC+pr/zH/Xw2KL6vEraA+7BC58Gb0jNM510v4Eh fSR6YMeqFgs1Is/ugVTxHHJcjHo18Fhe3lT64Pp4R40UyEwKTyxlKQs7TiCqzJuL NlJqIs4xHRFKMgiK2c5eZOPAUnHAD1c9EXYdtdnYZ3a6lsqlAPjUQ25ngNTRWuZc XBcwY8AY4Vcgat7NEYAAXN9Fbsces76e48skh7hOHaDtwacnYn+NumfM7SELPsB4 AkcZSilgXl14xLAB4Hpn13Kecr7nA8cryfk4y3eSOCjq2kbhD+sjYyCOEhIA== 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=1717407657; x=1717494057; bh=PIhSsmpN2DbdHycRqSo6eX2QIxwo mAU+bpr93CyHfJQ=; b=Bh910Sv5dONc2OZnl6MVyGvNFe+a/feTLm0rje0ph6ab KNwalwBah+TIpGBzRm+imCFZgAEfE2NxDWylT/dDXIL1Yv897rKrPgajmG3I1UV9 XIPYgDjxFSA9t+lTCfccN3AoflfdT+K+44UTiLl/frW8cAA0bkWDIkoLC+2FdKTd EhmOk/JWo6gWwJXdHwHACpo7uMPDYNgSMUKRgup8mopDC5wFn0XLwoqkZ6fZ3Hxn xmvmqt6ITvHexzC95YjcebJ53eNoFRhMWlgJLXXpfsfAsPziWuQRNsLP0tu6aoD3 bFBWrT0eUNsoLbdaxZZNcSiDt1YJE377+EBwiujAwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeegnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jun 2024 05:40:56 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f3f4ed40 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 3 Jun 2024 09:40:32 +0000 (UTC) Date: Mon, 3 Jun 2024 11:40:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v3 24/27] builtin/rebase: do not assign default backend to non-constant field Message-ID: <0a84d66e68b185b792ac3b3925d1bf7394e03362.1717402403.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;