From patchwork Mon May 13 10:23:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13663272 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 4544F146D76 for ; Mon, 13 May 2024 10:23:25 +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=1715595806; cv=none; b=oq68SQP+EzcfW8CZ7eRpl8ZPyfEmNNWbmoJppMMf+7eA8DeuzKc6w9EEf4Gb58UhoUgM+WYisjE11pcNelgZNsC988QoyERyhiNs9J2cuCDCrjwqQ0UbGGcr2+jFRVtRxX5Bprl/puePM5fAncsgBxzgwulhB1LXXmnmkd+xpgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715595806; c=relaxed/simple; bh=ctAyA9tsAXCcSNCEOaQf83JWUgXOijoj53K3UmWY3mY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Uaq1oOtqM/FBfrS7WHRjqYM9cqx6Zt8DQHgPTuBlJZxUmPXtXjTZtyEvVSO8eI0uEUV5lD7cgQLmQd3bwXKE7YqcsN6mx+S6SIzmXkmMNJywsm4PqW9XQP0XbJEOlyA3w0XGoLyDcNIQY/POvXQe6UWAEzQTt9GJDfCMvrI6vb8= 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=POkGRJHs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q1erpRQZ; 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="POkGRJHs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q1erpRQZ" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 933B31800103; Mon, 13 May 2024 06:23:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 13 May 2024 06:23:24 -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=fm3; t=1715595804; x=1715682204; bh=C6bFk9ENLL roUqHc9D4tejsxeOcr6tdqhusZeUl4+KI=; b=POkGRJHsaCsMXHpGMxdtd+TOBK kddlegA+QUOKYP51HOlNHSJmmb0oj+LbRiee+i2dcHa2KVCeqeKXNi+vJ2AnX7eG cHjKTa8BRTc7QhHHaot2xdbAjVi3Al6yQ5yD9tnWx6cqD6NWVSlzc8P7DDTNYCbp gO0m0OosVt0wgS+a3eBYnd0vjngb8g1H2z4hu8VB+DfJG4bg7rCv/5FlxfU+dTRP hYCTQ9nXKKE5Rkg/xMpzDBU+m0cRqCe8bQwSaYRM3iWVakzjgULpDGk7GWzdSn+B Wd8D+CTEvatQeTJzSciL00Mg5jRR2OS4h3RMOixRDIXGa0IRCpOvH2rK5jvg== 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= fm3; t=1715595804; x=1715682204; bh=C6bFk9ENLLroUqHc9D4tejsxeOcr 6tdqhusZeUl4+KI=; b=Q1erpRQZA5z2G5ccYmVRkecDO3W3BlCfNi2/d1G/MgJq OvaC/BRm1O9yQv/Qf9158h72v6kZe7OSwDa3C9U/cTEuApdMtnAfmq/Wwk7XwE4M cjpiULES2AT8OpMSVAlFznrY+qHU8jP4eNKa3dtM3kU764XXDbUFPlDshwP71xOk qDmEBNTPz+M1H4YntLXySGWAytaFWQ3qcQSw11uIbJFlkozIOsEx/HTdB5Z/gkBe PSRD7oHlNb9SjyqGphrMjt6Jn59w4n7KaXserUilCoXU1kypDlaP406D2Fl5PTNW MvErdDY0fBPBdKIhUNFvDfp3767UBk+qgi3JFp/H1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeggedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 May 2024 06:23:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 36018e40 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 May 2024 10:23:04 +0000 (UTC) Date: Mon, 13 May 2024 12:23:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v2 16/21] builtin/config: convert `regexp` to a local variable Message-ID: 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 `regexp` variable is used by the `format_config()` callback when `CONFIG_FLAGS_FIXED_VALUE` is not set. It is only ever set up by its only caller, `collect_config()` and can thus easily be moved into the `collect_config_data` structure. Do so to remove our reliance on global state. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index a17e274ece..1909de22fc 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -124,7 +124,6 @@ struct config_display_options { static char *key; static regex_t *key_regexp; -static regex_t *regexp; static int use_key_regexp; static int do_all; static int fixed_value; @@ -326,6 +325,7 @@ struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; const char *value_pattern; + regex_t *regexp; int do_not_match; }; @@ -342,8 +342,8 @@ static int collect_config(const char *key_, const char *value_, return 0; if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) return 0; - if (regexp != NULL && - (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) + if (data->regexp && + (data->do_not_match ^ !!regexec(data->regexp, (value_?value_:""), 0, NULL, 0))) return 0; ALLOC_GROW(values->items, values->nr + 1, values->alloc); @@ -404,10 +404,10 @@ static int get_value(const struct config_location_options *opts, regex_++; } - regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(regexp, regex_, REG_EXTENDED)) { + data.regexp = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(data.regexp, regex_, REG_EXTENDED)) { error(_("invalid pattern: %s"), regex_); - FREE_AND_NULL(regexp); + FREE_AND_NULL(data.regexp); ret = CONFIG_INVALID_PATTERN; goto free_strings; } @@ -447,9 +447,9 @@ static int get_value(const struct config_location_options *opts, regfree(key_regexp); free(key_regexp); } - if (regexp) { - regfree(regexp); - free(regexp); + if (data.regexp) { + regfree(data.regexp); + free(data.regexp); } return ret;