From patchwork Wed May 29 12:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13678804 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (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 4AD02FC18 for ; Wed, 29 May 2024 12:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986729; cv=none; b=HiKTDNU0UVdvN+5FPbkMil4lNTcp6KYcDYvd2skFg8QS+g4kP6VM/iIy3fu8MTDrMcYSi9XitPLoGrDeg4XImb59DpFfPg3qMu4k2XrB6N5AopSD8YW2YuBcUaW/RZrbyA9csiU3+cxGGn0fRq6bUVH1LZF5RXNgW/eNgqaLJAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716986729; c=relaxed/simple; bh=a4UYU5oTgOdRXsPQfQWNDAejQS+pdoVEoMz8Oa7xOYo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WEaX5wvDPp0NMLAaoHKgIVjxors1e0aLo3b+3dQoER/lB0yv7bAhi0cnWbFT+WUsuyc0i7hihoXZraEgDVrN9hRWMRuYvtfcpl5HfLe8aJyZIcKeFgEBxuc32ckPe1Dq14EN3aHaGjQSIKX4cYh0tj/aXfmqV+DxL9wUXJsPIJE= 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=dPyAR9zs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Gb/rcT1N; arc=none smtp.client-ip=64.147.123.157 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="dPyAR9zs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Gb/rcT1N" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 86FB81800116; Wed, 29 May 2024 08:45:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 29 May 2024 08:45:27 -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=1716986727; x=1717073127; bh=eSG9/Sv/aP tLLKOoKAsckCx3k9HlNGqhzRzpg3U8b5U=; b=dPyAR9zsL/EbzteLw7FoHJ/bmG uRGO7PvxMY8rpyULhrB/rEub5MLj8AyCARFl34vmkOPENNiiyNBr10D272xot22O V8NYxBZS3FujkQtIGyybYIfefqyjFBhTYwIaHZkxpLiERw1r241PQzV1tmjyGLVA bwlZIyvfHeGciZhTdGQxMSLjcC9W+KV7hfVcCdtqooC6K53aa7BzZNmJVU9mFlhN 9EkoWyobACczfbLLfu1sQlGxAMC4KA66uDlwzpOrVuc7vtcsfj3yafJuX9siSbhR KkSjvu2dxRcH5Y9z/0Ujl5tI/FYT8HXf2hiPTzknr4vKwBEg03yKwQrBQing== 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=1716986727; x=1717073127; bh=eSG9/Sv/aPtLLKOoKAsckCx3k9Hl NGqhzRzpg3U8b5U=; b=Gb/rcT1NuPzmcIZcKGzauy0JsbB01oCEbjljQvvBclVj iwL3vA1e2jPY64h5k8R8uPLxAmT8IfzvAu7teccJPkbiNr91NNqKJC5jhGEMH5mJ izTTok0ZFrfOSvhvPJOLwoKTqiHEUmP2dyJ+FzMN/NddDbwdulSHBBPW+hmtTK6K y1oWTqh+D5GMHzArJ9FVpgiUMRdZ1U7B7eB8rWTbWCliwLA6aqmRvAz6bpes67dt TrCK+5IPzE+PflLtpfx6602VY+ddOQhF642wIYWQE0IG4i5B4vAOfnuvFULNhMqu NeoxvP3Nkw4CXI+u7WCkr0eiSRioJeBCUjGJ7YQBHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekuddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpefgfedvfefffedvffefudeiuddtteeggf duieeuvdefiedtjeeufeeuieelueekfeenucffohhmrghinhepshhtrhgrthgvghihpgho phhtshdrnhhrnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 May 2024 08:45:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e25543a6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 May 2024 12:45:11 +0000 (UTC) Date: Wed, 29 May 2024 14:45:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH 17/19] builtin/rebase: adapt code to not assign string constants to non-const Message-ID: <16d3d28243a0480c929ae3740db92ade238dd325.1716983704.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: When computing the rebase strategy we temporarily assign a string constant to `options.strategy` before we call `xstrdup()` on it. Furthermore, the default backend is being assigned a string constant via `REBASE_OPTIONS_INIT`. Both of these will cause warnings once we enable `-Wwrite-strings`. Adapt the code such that we only store allocated strings in those variables. Signed-off-by: Patrick Steinhardt --- builtin/rebase.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 14d4f0a5e6..b05c3b6be3 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -135,7 +135,6 @@ struct rebase_options { .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, \ @@ -796,6 +795,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); } @@ -1471,12 +1471,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (options.strategy_opts.nr && !options.strategy) - options.strategy = "ort"; - - if (options.strategy) { - options.strategy = xstrdup(options.strategy); + options.strategy = xstrdup("ort"); + else + options.strategy = xstrdup_or_null(options.strategy); + if (options.strategy) imply_merge(&options, "--strategy"); - } if (options.root && !options.onto_name) imply_merge(&options, "--root without --onto"); @@ -1522,7 +1521,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (options.type == REBASE_UNSPECIFIED) { - if (!strcmp(options.default_backend, "merge")) + if (!options.default_backend) + options.type = REBASE_MERGE; + else if (!strcmp(options.default_backend, "merge")) options.type = REBASE_MERGE; else if (!strcmp(options.default_backend, "apply")) options.type = REBASE_APPLY; @@ -1833,6 +1834,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) cleanup: strbuf_release(&buf); strbuf_release(&revisions); + free(options.default_backend); free(options.reflog_action); free(options.head_name); strvec_clear(&options.git_am_opts);