From patchwork Fri May 10 11:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661378 Received: from wfhigh2-smtp.messagingengine.com (wfhigh2-smtp.messagingengine.com [64.147.123.153]) (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 4487B17164B for ; Fri, 10 May 2024 11:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340328; cv=none; b=VKwNMBjEB6VkkZB6Fh320Jm2LhifFPAjmaqSE4DTL8QW6fpRlS+uh/O+L1s2Gwa8pnqPXrNJpyRCfokEW4HYbIBhA59k8mRXzo0L+fkcJoqO2MSF8SF633TF72QGd4cI8C3u+IItQn/KEC13N93KO+y+zTMAv9oroJE3vWI02Q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340328; c=relaxed/simple; bh=jXVDjUN1nrYYJZMQ0fa/b027PMfgBEKwLbx8MWB2qRc=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dBOwdEZfLAWxZkdkLcMmP6zsGfMIPhlQcxMPEiRJiEvdLTQ4b/pPx+eRk6LBYa5tRtuZ1uKpWyR8C/C8Od1zoX/lwL2Jn8T+h8hoVhjTXNRquBz7G+NazjiZDI7L41EgsxYfXFBKNVUQvKQRk6jBKEj8l69ppzEsUm08ndBVZio= 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=O5bAmswh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JBakioU9; arc=none smtp.client-ip=64.147.123.153 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="O5bAmswh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JBakioU9" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 9351D18000A0 for ; Fri, 10 May 2024 07:25:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 10 May 2024 07:25:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=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=1715340325; x=1715426725; bh=2+KdOU38XL uDpznGVM19P+VSpp8RlC9Vbmbr5VKq74g=; b=O5bAmswhMwhtQL2CKh8y9wLS6S turo4K6WUKyNLH7aUj1Z7hJ/Hvp4uM4P3yVXGaZFJC0WJwmXBdHJlyHX/MYJUpRD 9lcEpvQ7v3AM76UX/eG2hKxHfQufrUPsD8pavYKa9/O1jBNuL6ACyt0qKFKGSdu3 Kw8hk6nimI8JlFAmKc5uy34KC8ULYlB8kaNvXqF/A0RkTXM3vqtBbuRuMS9P8m2V OAbahcWnYL9Br+kud0tvwsy7BPGvLcgjNkqlJ+GfXtFntQiv5B1Qa53yGO835Dxv tEpxZ5EegzR+ybJBAaT7UJV/lcxGlOBXW9Wjgw9v0rrYSrS/J8pZxIoLMLzg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1715340325; x=1715426725; bh=2+KdOU38XLuDpznGVM19P+VSpp8R lC9Vbmbr5VKq74g=; b=JBakioU9TnSSITVqI8mW3HLyBKQ7yvSxGUwkbFyL8lm7 7/DV8V330KUPgQKxHeHbiMDWS9E8/DokT3JQFA0nrfGTpY8DDJgji1g1i4Qa9qrF 28Yze28k0DZGwKAHJ22E00hSA9elmm1A0Xtn+cOOzJyvNNpPGYjylh1klnTEHA37 lYF1dUl5EXgQ8qI/du1i2guQ51q3JADeDOc9OcShJrCzlhLGQI4EF5LA0ccE4K43 STtJXezWf4jmDvvwMZjYf/eUhXupzKOm3zVvm+hwapqih97lFO1U2fJYJZtsd/sN //fowI86CE/PLMb8QHSDdRpMUyCiBzanQ8+ps3qiMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepudenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 10 May 2024 07:25:24 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5d3f73d7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 10 May 2024 11:25:11 +0000 (UTC) Date: Fri, 10 May 2024 13:25:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 12/21] builtin/config: move default value into display options 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 default value is tracked via a global variable. Move it into the display options instead. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 1f864f71c4..eca5179f5f 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -107,6 +107,7 @@ struct config_display_options { int show_scope; int show_keys; int type; + char *default_value; /* Populated via `display_options_init()`. */ int term; int delim; @@ -125,7 +126,6 @@ static regex_t *regexp; static int use_key_regexp; static int do_all; static int do_not_match; -static char *default_value; static int respect_includes_opt = -1; static int fixed_value; @@ -415,7 +415,7 @@ static int get_value(const struct config_location_options *opts, &opts->source, the_repository, &opts->options); - if (!values.nr && default_value) { + if (!values.nr && display_opts->default_value) { struct key_value_info kvi = KVI_INIT; struct strbuf *item; @@ -423,9 +423,10 @@ static int get_value(const struct config_location_options *opts, ALLOC_GROW(values.items, values.nr + 1, values.alloc); item = &values.items[values.nr++]; strbuf_init(item, 0); - if (format_config(display_opts, item, key_, default_value, &kvi) < 0) + if (format_config(display_opts, item, key_, + display_opts->default_value, &kvi) < 0) die(_("failed to format default config value: %s"), - default_value); + display_opts->default_value); } ret = !values.nr; @@ -848,7 +849,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")), + OPT_STRING(0, "default", &display_opts.default_value, + N_("value"), N_("use default value when missing entry")), OPT_END(), }; int ret; @@ -859,7 +861,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); - if (default_value && (do_all || url)) + if (display_opts.default_value && (do_all || url)) die(_("--default= cannot be used with --all or --url=")); if (url && (do_all || use_key_regexp || value_pattern)) die(_("--url= cannot be used with --all, --regexp or --value")); @@ -1125,7 +1127,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_STRING(0, "default", &display_opts.default_value, + N_("value"), N_("with --get, use default value when missing entry")), OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), @@ -1170,7 +1173,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) exit(129); } - if (default_value && !(actions & ACTION_GET)) { + if (display_opts.default_value && !(actions & ACTION_GET)) { error(_("--default is only applicable to --get")); exit(129); }