From patchwork Wed Mar 27 08:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605949 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 4BD1E1EEFD for ; Wed, 27 Mar 2024 08:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529180; cv=none; b=ICjyaaS7SQaYQ2U+OCVDrADekiYaGJlAIm12bxp8CNIbixkvUrD+ZFejNbQSzHn1+t7BbpxMEbnrWvF5PDL4ZWENxLn7ryn/HE6A9Ct3WyABRYGC3VVlt3nmmrwTr6e9n01pNVWAmqya7jBlbAaRib4cradwmfXdBvMu3as8fYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529180; c=relaxed/simple; bh=I5G3vy94qRTplxMvGyrt5OCUoTDI3ZLETSYfbGsZaJE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=miubbVZvEJHUtS8c2V8rJUxaOoUZfHElFyu9YoSEWfJoObLr7LBgd21ih0hUSMsH7/uUixFCXlYCS0BiI0ol7oL4TyqNKfsSPzdTBerPxYOz7mNs9RUTBcWwXzGd8Ai5ZqDhw0w9CDyYkDtE7UZPymcXpPK8vkV5zbv6azrSRFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=R9TBwe0I; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FdyuQQwK; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="R9TBwe0I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FdyuQQwK" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 3116A138015B; Wed, 27 Mar 2024 04:46:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 27 Mar 2024 04:46:17 -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=fm2; t=1711529177; x=1711615577; bh=Sjjwz46dNi ONI7G9MAMbHWoh51Pu1/RkOVdp9xTFylU=; b=R9TBwe0IuPcvsfZD6R1ZxBAytx pOAgc33XawSTOS2Z9TEVxWb8zacGL/jotPZG08i+4KdaIW01PHVKQjBYgabgiq0s T2aapUbZKkNRtK86S+SSUQC4fvFx5N8YsYQfxRkywz5rYmsNBGEWqH4esx0+Qm5L 0FA8XcKmI5YAKyOgJ++qWOVpYOJROPGD+AFDhyGtvn8LdEByR1DW/c7Ld17Glmv8 BS9npvRkOAqwOcxQDmrfV+pPlsMzhDVHWHiDRVjhoKK4Q83RWssglrtG2E+HA5Qu 4eQtKnCIpuMuunqtvMU5jRRYrJFVewX/fN1kdnfEkDFPzVC3CVC36ys/3SCQ== 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= fm2; t=1711529177; x=1711615577; bh=Sjjwz46dNiONI7G9MAMbHWoh51Pu 1/RkOVdp9xTFylU=; b=FdyuQQwKsBtaagkd2EKOYe4qrZgyhJ9q10mnauVASEYt vS0472Hgb/IaVdklJFYYmb1AmO/zEAfkKksMtSSF4yY2mhLtf4iSf3wL3ylxgrYd DXVfEPd9i2wUzz5aPtmmNrJAVamTwTBraSJJ7ePFhi6iI0BOe7GWzVjWxAQ442Hs mXMkXT2SMR3DXbBxlGd76jkpO3BbIMeiOtvg/2zVYN2LZ08J7+Pd+tdkQtWYpDW/ Wlo+ymM5s2M+ZUAMOuGgvupXoeTEhfCLoLsyaz1eI0ZJSFJFisRDF5t/sAhNohfb tNp96Gf3HjccjYkNsSFLmt+ac8R1fPQzWiI0lXcJtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:15 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 77862b8b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:02 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:13 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 01/13] builtin/config: move option array around 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: Move around the option array. This will help us with a follow-up commit that introduces subcommands to git-config(1). Signed-off-by: Patrick Steinhardt --- builtin/config.c | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index b55bfae7d6..6eb6aff917 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -134,53 +134,6 @@ static int option_parse_type(const struct option *opt, const char *arg, return 0; } -static struct option builtin_config_options[] = { - OPT_GROUP(N_("Config file location")), - OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), - OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), - OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), - OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), - OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), - OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), - OPT_GROUP(N_("Action")), - OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), - OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), - OPT_GROUP(N_("Type")), - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), - OPT_GROUP(N_("Other")), - OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), - OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), - OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), - OPT_END(), -}; - -static NORETURN void usage_builtin_config(void) -{ - usage_with_options(builtin_config_usage, builtin_config_options); -} - static void check_argc(int argc, int min, int max) { if (argc >= min && argc <= max) @@ -669,6 +622,53 @@ static char *default_user_config(void) return strbuf_detach(&buf, NULL); } +static struct option builtin_config_options[] = { + OPT_GROUP(N_("Config file location")), + OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), + OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), + OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), + OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), + OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), + OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), + OPT_GROUP(N_("Action")), + OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), + OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), + OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), + OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), + OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), + OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), + OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), + OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), + OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_GROUP(N_("Type")), + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), + OPT_GROUP(N_("Other")), + OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), + OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), + OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), + OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_END(), +}; + +static NORETURN void usage_builtin_config(void) +{ + usage_with_options(builtin_config_usage, builtin_config_options); +} + int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; From patchwork Wed Mar 27 08:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605950 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 D260D36AF2 for ; Wed, 27 Mar 2024 08:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529183; cv=none; b=a2WgM4MbaK40lteiXpu0OW0m55IVxTATlPZ8+wzsfHTYAQxr2O9YnANyFbh3Tz6KKRibT33JHiNFJ920fcDf0/al0BLq4H4HCHvME4SrFHSZ1v3WvwkfI2Yblui+qnPOB8REyg4BoKUQPjfOMtVFQCAaerAH/jjMeSKi0XM+XCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529183; c=relaxed/simple; bh=/rLmN3QTBnLEvYSi2snJW9OwpBF5jH9k+YW3/JrgSDs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WQ+9qKoTDkd1vfoH45Gy3QYize/Oy6HQASgdoj4nxGVZAzojt1SY4Y7ozIPDDTc3l+K3OAKOzYlyGXed4L8lui42Nqu3KYYeL4av9oaJ/fUgPueY1gnFH7nUUSjsYY9jN8RnTv+nvDhIV+idW6wCGOxqynbjmYOcEntGOV99XV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=DIyc914N; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=wpURbxTJ; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="DIyc914N"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wpURbxTJ" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id D6715138015D; Wed, 27 Mar 2024 04:46:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 27 Mar 2024 04:46:20 -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=fm2; t=1711529180; x=1711615580; bh=VTT50xVHGw /CuyLD27jjlSMxuLO3OB4s+fDOaHqTI2Y=; b=DIyc914NpKdoNHnUODfC9j/dLS SH524ZFO8iWoQ7ZBM1upVzIk/+ErOKQvD+niqcnXgJNzML5N8zugLFc9gsdY7BgY mdrY48tKTymsAG5LcHdK7fi7xmHxRKGRMN38blgOpPduM0e60fXAs356HRN6vDoN D05N57gc5e/Pq53UAetrcfC5ZOSxHiOME6wrMvcQ4t54y65Jd012BkoRhMqGWCBs LLzwUkfaiLi/O4sdklatGy4DAtl6Ivn/zXXU8gP57k2g7a9LdxRant7/zdny+WIv y8CV1e6iyQhVMT0KxnxjcEYc2zqI0mCtx5h/zjNFYX0n5HayG6imwy9c247Q== 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= fm2; t=1711529180; x=1711615580; bh=VTT50xVHGw/CuyLD27jjlSMxuLO3 OB4s+fDOaHqTI2Y=; b=wpURbxTJ5FNRX5XTwaqYEMPz1Y1TvilRwnWZhMPSS0Iz W0LiSoA27z0dlMvCvaLmmHY0jYwkN4BJHJBGb8igUqnRh0m6XPih5S9ftUOPwkFJ u3Oph3mFtiRno3tYuGPf+Dnf5UjQKFQ5UYqkJY6WssOCVt3tAgSyywYrTqxbLdUh 67TEaaBMWkg7AV9ztccS6wVwmIXWDug6M7EDl586tHlI4RWE+hWCiRTf6AzM7i5/ AK8phS5Mu2V+75khWZHL40gkdR+BvpPJa1YQQTCgbRfmFNEAm/rnywtDalZzqZwk yQgPOzptjjQzWon7+Rk1gJfeNKNkdO5xNPwBHd8lGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:19 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1362d847 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:06 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:17 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 02/13] builtin/config: move "fixed-value" option to correct group 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 `--fixed-value` option can be used to alter how the value-pattern parameter is interpreted for the various submodes of git-config(1). But while it is an option, it is currently listed as part of the submodes group the command, which is wrong. Move the option to the "Other" group, which hosts the various options known to git-config(1). Signed-off-by: Patrick Steinhardt --- builtin/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/config.c b/builtin/config.c index 6eb6aff917..fcd6190f12 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -642,7 +642,6 @@ static struct option builtin_config_options[] = { OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), @@ -661,6 +660,7 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), OPT_END(), }; From patchwork Wed Mar 27 08:46: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: 13605951 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.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 5B9A8364AC for ; Wed, 27 Mar 2024 08:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529188; cv=none; b=NyWOd4IP76KyiBQggzpfp0oPTEnphBzg+KaDVkJa+u/NVo7RISxyzNg7nlaaL7BY6QOXTXDzcZRjGqka2ZBn9AUuwqLuEg02yncqmr/9CzI7jS/to6zDvOadcZx2ifSGceV2/XlE4bHNeAED3AxRZZLceWLkrJAXRHOSME7S+L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529188; c=relaxed/simple; bh=bQ3VDhldcKiE5scyIFs2vKzLMUfb8yOTjYZaKyzh9J0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nx5G9CTfCOo0+AuJVSMACgN0hrh11LoDIR9cWfPvYsqCAv6l4+Pb1e2VPr4/DvshwouS1gYjcqJca+LQncgXH1w/zIn4xROM/83NgQY/G9Z7JBOuhkow0vpp+4vup/0RgFktMNQPHGWResy5ezO7Mnpd4N6cWK2Jay//jGGwf/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=OocniTLm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pSGg4BUy; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="OocniTLm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pSGg4BUy" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7F2BA11400CE; Wed, 27 Mar 2024 04:46:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 04:46:25 -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=fm2; t=1711529185; x=1711615585; bh=sAm3/vWkR4 LQpQhBEHnpuznP7FrbTC9ZZeGJHD4lOUM=; b=OocniTLmfeel8ZZg4wynj0uPxV vE7xeO1PUlPMdWHnXJreauuJ0ZSD7GoanwcnnExV5Q/R+y9urz9LnRBt/l94hnl5 F536axJko11RzSBxPq5Fb1sy6gdwr1urfbeVO4ZjurXx0YmN+cJVTU9DSetZ8sDs HNUKZYJcV4HAhmPpjSpNMPdzve8RgymdJjbabOKOBZv5is1Z8QnhJCjvL9MXpPoL zqlMFZh9kScvPZIgRHciwB3sdog3NXQdSR/PQBnFzqytv1j0116K2+N+TFLIMSPn evHE4iLrVJujhauYPEfGqM76iK3co1Og/19dHNiBAvHiC0Y/vt4lphIFxHGw== 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= fm2; t=1711529185; x=1711615585; bh=sAm3/vWkR4LQpQhBEHnpuznP7Frb TC9ZZeGJHD4lOUM=; b=pSGg4BUyts19O8aMKOFHeemp6J+ls5FUwgVmj0o0bk0+ BUmjnaZh+L2O0A673WhqGZeAtMIet5f0h/v/KIRmK/Ij/Ablax61XjNqokUaPCKB S17gz2kYtR5B6hv28Pd7PRM/LWmBGjWCgacJQPRBlFopjhLxMO952TD7RAcMWEnl J6LX1kfeKd2Ju09wd6tkROx3OOga+9PrEBQ9TirSyOzzC2zBlNgGkHia54mWIcRm gYFsFT/cTsMWlDGCHc8dvsqbwhtqNgDo31CDPJrTT9jA8idjP9Y+DzpevW3q4zB+ I6S9VwYPSwL6ZJlkPGGCYIiFf+KAC1Dyw59O1Iz1sw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bc988da0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:10 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:22 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 03/13] builtin/config: use `OPT_CMDMODE()` to specify modes 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 git-config(1) command has various different modes which are accessible via e.g. `--get-urlmatch` or `--unset-all`. These modes are declared with `OPT_BIT()`, which causes two minor issues: - The respective modes also have a negated form `--no-get-urlmatch`, which is unintended. - We have to manually handle exclusiveness of the modes. Switch these options to instead use `OPT_CMDMODE()`, which is made exactly for this usecase. Remove the now-unneeded check that only a single mode is given, which is now handled by the parse-options interface. While at it, format optional placeholders for arguments to conform to our style guidelines by using `[]`. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 32 ++++++++++++++------------------ t/t1300-config.sh | 13 +++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index fcd6190f12..a293161be4 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -631,20 +631,20 @@ static struct option builtin_config_options[] = { OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), OPT_GROUP(N_("Action")), - OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), + OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), + OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex []"), ACTION_GET_REGEXP), + OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value []"), ACTION_REPLACE_ALL), + OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name []"), ACTION_UNSET), + OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name []"), ACTION_UNSET_ALL), + OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), + OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot []"), ACTION_GET_COLOR), + OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), OPT_GROUP(N_("Type")), OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), @@ -767,10 +767,6 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } - if (HAS_MULTI_BITS(actions)) { - error(_("only one action at a time")); - usage_builtin_config(); - } if (actions == 0) switch (argc) { case 1: actions = ACTION_GET; break; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 31c3878687..2d1bc1e27e 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2612,4 +2612,17 @@ test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err ' +test_expect_success 'negated mode causes failure' ' + test_must_fail git config --no-get 2>err && + grep "unknown option \`no-get${SQ}" err +' + +test_expect_success 'specifying multiple modes causes failure' ' + cat >expect <<-EOF && + error: options ${SQ}--get-all${SQ} and ${SQ}--get${SQ} cannot be used together + EOF + test_must_fail git config --get --get-all 2>err && + test_cmp expect err +' + test_done From patchwork Wed Mar 27 08:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605952 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.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 E7EA5381B8 for ; Wed, 27 Mar 2024 08:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529191; cv=none; b=KisIF3F3kkrYR/luwFMjqMriBgeLEFW6f4zci7fr9KZf0xbtfSmM0WOd2x25brJ+Duyl76TKOse1LoWHvHsdJyU+drqXKUP0JQRugGTpH3vAvimdjty+aRZpL/1xH7ALzWTmEVyerLjF9bw3uLJXWhiC/KLGxNiCgKzml3NolkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529191; c=relaxed/simple; bh=BJo0S9sbmc2A11PNOO8XgikMn8UE5aLI17aEYDewSPo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Qro3b+AErJJY6KPTkm2IBBNEvZZ8qcLxAPrCQGVuoZ6b/yXPW8z++2BHDxxmaRp3nttw1aCEYD2+pWtP0VIyTJXshhrN0wdyJ8d0RAEOfChbZTENqYkn8OXuUxhQfo+PN3x92W3ZGqd4BNavOj85Y/f0eIYBJsMp0KISwbLVGsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=F1rJjv8j; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HoRxgGSL; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="F1rJjv8j"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HoRxgGSL" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1E5E411400E2; Wed, 27 Mar 2024 04:46:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 27 Mar 2024 04:46:29 -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=fm2; t=1711529189; x=1711615589; bh=2bF1uVyF4R 8um/vS+ql3ea8MhMM8x7bsyenzVUSazsE=; b=F1rJjv8jTLtyB8w1XMiGVI+stF XGEuF0uV8Hc0/sx9Dbc/CT8h9z1mhLcCFqnGUtYbKsKY+bgp0UlSOt4GEJFn8P+U cS8Vw0v/hGW4idanQZ1xMyeALQRq/mYPUQ7eCE3OhoTc4y7C1yUy9uodUSYJ5RDA gs9w7ct+RtdgzSqIujg1ZT4Fm1hjhFs5vL1gNE/zx53biSaInI4lOxxgIs+aa+XT z6+4Q4KNTvQQpHS/+EH3lp8Si8ahNB2l4xO4LhrTE6IHb2WMQkXRa8P2jsZLtRLS YRg00r2RqB0MC/zkYxY0aGR3zW6UtQPTbCDE1bMFJ341K2Es1cFoRATpQ8mg== 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= fm2; t=1711529189; x=1711615589; bh=2bF1uVyF4R8um/vS+ql3ea8MhMM8 x7bsyenzVUSazsE=; b=HoRxgGSLXwLyAKxB2FIJRX713MKZWRI5cCgQmI+GvyUs Usa2vBJXzg6hETXG14wdVF5/EK9GYFbrTrQjYUjb1mWQ2jz9mNk1QTXXkfja1UsW NSf77tKQ1FkXZ6gBHV8/QZjc5f71KcikRzYZ+nfT+CWxrHuPovD0T+BKb/TZsqbf Coc9JFApsaWvHW4k27ZDwrO+EUHlGEKWcRA/TjgYUUdpg4GqoRYxy/PafW8Njv1d cqiim625P1eQzUapC5KnfVA+kL0HV3DtrcCKpAp1gmBw7fkcA2TyF1NLVIzMnWqv FcsdtrFY1vBdZwhODhMPruVKFZicKZnXdKcrG6Tyvg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d2c870a4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:14 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:26 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 04/13] builtin/config: pull out function to handle config location Message-ID: <41585803bf30f329f546616bd27b10da4df047c5.1711527812.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: There's quite a bunch of options to git-config(1) that allow the user to specify which config location to use when reading or writing config options. The logic to handle this is thus by necessity also quite involved. Pull it out into a separate function so that we can reuse it in subsequent commits which introduce proper subcommands. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 131 ++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index a293161be4..693df32526 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -622,67 +622,8 @@ static char *default_user_config(void) return strbuf_detach(&buf, NULL); } -static struct option builtin_config_options[] = { - OPT_GROUP(N_("Config file location")), - OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), - OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), - OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), - OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), - OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), - OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), - OPT_GROUP(N_("Action")), - OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), - OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), - OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex []"), ACTION_GET_REGEXP), - OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value []"), ACTION_REPLACE_ALL), - OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name []"), ACTION_UNSET), - OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name []"), ACTION_UNSET_ALL), - OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot []"), ACTION_GET_COLOR), - OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), - OPT_GROUP(N_("Type")), - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), - OPT_GROUP(N_("Other")), - OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), - OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), - OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), - OPT_END(), -}; - -static NORETURN void usage_builtin_config(void) -{ - usage_with_options(builtin_config_usage, builtin_config_options); -} - -int cmd_config(int argc, const char **argv, const char *prefix) +static void handle_config_location(const char *prefix) { - int nongit = !startup_info->have_repository; - char *value = NULL; - int flags = 0; - int ret = 0; - struct key_value_info default_kvi = KVI_INIT; - - given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); - - argc = parse_options(argc, argv, prefix, builtin_config_options, - builtin_config_usage, - PARSE_OPT_STOP_AT_NON_OPTION); - if (use_global_config + use_system_config + use_local_config + use_worktree_config + !!given_config_source.file + !!given_config_source.blob > 1) { @@ -690,14 +631,13 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } - if (nongit) { + if (!startup_info->have_repository) { if (use_local_config) die(_("--local can only be used inside a git repository")); if (given_config_source.blob) die(_("--blob can only be used inside a git repository")); if (use_worktree_config) die(_("--worktree can only be used inside a git repository")); - } if (given_config_source.file && @@ -751,10 +691,73 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_options.respect_includes = !given_config_source.file; else config_options.respect_includes = respect_includes_opt; - if (!nongit) { + if (startup_info->have_repository) { config_options.commondir = get_git_common_dir(); config_options.git_dir = get_git_dir(); } +} + +static struct option builtin_config_options[] = { + OPT_GROUP(N_("Config file location")), + OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), + OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), + OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), + OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), + OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), + OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), + OPT_GROUP(N_("Action")), + OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), + OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), + OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex []"), ACTION_GET_REGEXP), + OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value []"), ACTION_REPLACE_ALL), + OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name []"), ACTION_UNSET), + OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name []"), ACTION_UNSET_ALL), + OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), + OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot []"), ACTION_GET_COLOR), + OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), + OPT_GROUP(N_("Type")), + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), + OPT_GROUP(N_("Other")), + OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), + OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), + OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), + OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), + OPT_END(), +}; + +static NORETURN void usage_builtin_config(void) +{ + usage_with_options(builtin_config_usage, builtin_config_options); +} + +int cmd_config(int argc, const char **argv, const char *prefix) +{ + char *value = NULL; + int flags = 0; + int ret = 0; + struct key_value_info default_kvi = KVI_INIT; + + given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); + + argc = parse_options(argc, argv, prefix, builtin_config_options, + builtin_config_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + + handle_config_location(prefix); if (end_nul) { term = '\0'; @@ -848,7 +851,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) char *config_file; check_argc(argc, 0, 0); - if (!given_config_source.file && nongit) + if (!given_config_source.file && !startup_info->have_repository) die(_("not in a git directory")); if (given_config_source.use_stdin) die(_("editing stdin is not supported")); From patchwork Wed Mar 27 08:46:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605953 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.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 B99BA3418B for ; Wed, 27 Mar 2024 08:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529196; cv=none; b=Bsr51qqZVVG9SZjK9lVelCLJ2193lqvCzzsaB9WjT7/KEX+meaVwc8iFGKBqaSINini73o5gi2NLDDR5p8RU3jsFIrQH4asOHThNNDp7f855UBu2bsIocYuKs+D7T30tigfS7GCQXWFuyOcZzx642JIhS92x8A2E2j5nHemnSj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529196; c=relaxed/simple; bh=BuSBGGbGoFsSV8KSdx2bY8joA0YYjEuMpD3ySWeE/WA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g4j9UnbVmt/HZX5tfZWbmUhSpspVflavxbLsPC4GfF1TJWkPT3SvgWw74WPN9hpzkwGjgKz2eLSguMHH4shsBWW5LliLYZrFIFxpWOhpvw27SHS2c2lcN6aD9psN6JIbAjTkBABtCRY0DA8uRBlm7N4K5/sBIlw8BjIudZOoA/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=LhB7Am3K; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MrWP5ETi; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="LhB7Am3K"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MrWP5ETi" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C801D1140111; Wed, 27 Mar 2024 04:46:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 27 Mar 2024 04:46:33 -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=fm2; t=1711529193; x=1711615593; bh=e76GNnmVxT pUVXc8YYFJplLjsRBs0vXhnZ1y3w4VLTc=; b=LhB7Am3Kpph6FBGEnojQdfuxuw OemknIN0xsCPQ8HyDvkfmYUq+eZbyloHmb/jXhJpuDaF4f3KfRlALmeGKtT7gx9V IPDon4IHOlhLDaJlk3iEIFNejbK7W5uwAhtQemoYti+ktuARZq0/hMFb8EegryXT DJCYolYy4zI84o3SvOVd3POnICe0tnJQjjHt7IPszzkRSMbBHxxh15VFNPP7QsJ5 UG1vIm6/XI6NdenuWT3VNlGCWJb5MU+Pk+f5FPCyhvYTNkjjzZ86UhjvXPHN2TDM m54ngu+78c2SZU9bRZI7TYa2Ffuq47TMuySyN6reE4go6KETk2nTL56dIHSA== 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= fm2; t=1711529193; x=1711615593; bh=e76GNnmVxTpUVXc8YYFJplLjsRBs 0vXhnZ1y3w4VLTc=; b=MrWP5ETiZg2bwm3+jZmT56Qf74RjHe7IaQd6JmJjNsG3 wLLDXNbi1aVojxhJyqGnTL40k6dNrZVpVQm8tA/++YNP4bR02niKX9KTAksNV8P3 89A05gkf3HfsPoMDOXzB4SMnD9zC+48Bf3qpK0xrSfYQIJ4at/25nuNA/++T0llF 6UK+8t7cjWf7bwjtcu72lKuZ1fJ5nRhsW1gSIi0f/wk38nlCNF1gAh3OMO5wRUaU Z04eGHp1vGgq5YtetUgAbUmVB0bC4NzMDhi1MA5rmam4VMjXdfxl3Awt57+77qSq teQIn+D9r4YIIAlVo82aTt/PNeLtp0E9xZUbGRu2FA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9389027d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:18 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:30 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 05/13] builtin/config: pull out function to handle `--null` Message-ID: <95f661f267ddd55a387b1c5ef078cbad639fd95d.1711527812.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: Pull out function to handle the `--null` option, which we are about to reuse in subsequent commits. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 693df32526..ce2d3fecd4 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -697,6 +697,14 @@ static void handle_config_location(const char *prefix) } } +static void handle_nul(void) { + if (end_nul) { + term = '\0'; + delim = '\n'; + key_delim = '\n'; + } +} + static struct option builtin_config_options[] = { OPT_GROUP(N_("Config file location")), OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), @@ -758,12 +766,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) PARSE_OPT_STOP_AT_NON_OPTION); handle_config_location(prefix); - - if (end_nul) { - term = '\0'; - delim = '\n'; - key_delim = '\n'; - } + handle_nul(); if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { error(_("--get-color and variable type are incoherent")); From patchwork Wed Mar 27 08:46:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605954 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.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 24F4D36B17 for ; Wed, 27 Mar 2024 08:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529201; cv=none; b=t//BuviDGwRVyjCfiTEomZyEvSfoS4c5geLDHpkEhHi6MxumtLNA9f5TkVy92BNZd1Uw4//rReLzH/ntE1gNOfUs2JkchBmCwYLL1VZgbfNy4p1HqtkVDlEnRik3AwKbp+ZernTgL4d3m74/2TcOZeuu3oqpHUuSbvKvuaRQiO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529201; c=relaxed/simple; bh=uN5oIhbfJfpHPrEqnFTAu2diYY2STOqQ1lKKaXNYWUA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KJvcqGBXh/KvF4BEFpv9q7AbdxCNQXH7+G9eEZNPHGvWF4xwYTLOa6Wp24Ffs1DKyRp3OAOSYODoWiz/i9dYypgeuyQ0pUGPQkQEoGNo3Pj7DmyX7+9S3oZwZQcddJz+RxYyLOMZwTkRu+F70Gqi/drMLvFcqbjZfjavb+eojug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=Meda+mAk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CFhwNu4Z; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="Meda+mAk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CFhwNu4Z" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 783F311400CD; Wed, 27 Mar 2024 04:46:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 04:46:38 -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=fm2; t=1711529198; x=1711615598; bh=rKLqOVbsvl UCxzdYv6BNwRih4vGrBLuxV7Kxuh5W8wo=; b=Meda+mAkoO6wMPRAOKoNoviIZd euUGSyg80ssF5RG2VC97ZPFbF0aa6XYO4ZJPHPk6lkFVTxX5l2XPb9HtdUnEFVph 0cu6MfcJVEuR1hPFQXbqKQJgS+wlqndbVQcmjd4HRRhl0i+FI9blhqSYnG3mQIvt N8tI8shgGsEt1Y4flmPB82vMWzblXOPA0MlSkytvIMWyUDXLX6+HYEy6hZiJ0YgU TRT2v9fWGjKlCM968iuNfqjPfuepEf363zeKHBP50rj8BW0fwWNxgyfwX5pX0MpP 0DSCOkouI7gacWlpOnd3c709rVZ7fAhaVccS6olCtVTaG0TVF62aIJ7BEzcw== 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= fm2; t=1711529198; x=1711615598; bh=rKLqOVbsvlUCxzdYv6BNwRih4vGr BLuxV7Kxuh5W8wo=; b=CFhwNu4Zz/syKDpy1YeHoJlzUrdefHn4ivrCA5eJYSvl z1SVgNynK+9hO3/5xUI+I/ryzY1JqnuuXrZZs0hCCef07jn0soBOZupDBWzIEt6z VZg8qMNBwYS3xxGvN/oXN7KFxyLZKyLBNNc81n2AAk72pdmUAo7YIP/o/b14vFNo 7CMfDuKQi7vvYQ2JlSCPKp/8Pf23K/bfjfjDQCCtsbGsrp9rrbqW+fpueI0azfri rsLRhF4HUUHV8DKISxQVL1y2+uVFKq1uRsRiTV5OssdSutAiIof78vwnlXm1v1+u qQ7jjufmZastrOxzJF6G+jzy3uJBz/uGm6ny+qmHpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:36 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bdfd174e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:23 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:34 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 06/13] builtin/config: introduce "list" subcommand 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: While git-config(1) has several modes, those modes are not exposed with subcommands but instead by specifying e.g. `--unset` or `--list`. This user interface is not really in line with how our more modern commands work, where it is a lot more customary to say e.g. `git remote list`. Furthermore, to add to the confusion, git-config(1) also allows the user to request modes implicitly by just specifying the correct number of arguments. Thus, `git config foo.bar` will retrieve the value of "foo.bar" while `git config foo.bar baz` will set it to "baz". Overall, this makes for a confusing interface that could really use a makeover. It hurts discoverability of what you can do with git-config(1) and is comparatively easy to get wrong. Converting the command to have subcommands instead would go a long way to help address these issues. One concern in this context is backwards compatibility. Luckily, we can introduce subcommands without breaking backwards compatibility at all. This is because all the implicit modes of git-config(1) require that the first argument is a properly formatted config key. And as config keys _must_ have a dot in their name, any value without a dot would have been discarded by git-config(1) previous to this change. Thus, given that none of the subcommands do have a dot, they are unambiguous. Introduce the first such new subcommand, which is "git config list". To retain backwards compatibility we only conditionally use subcommands and will fall back to the old syntax in case no subcommand was detected. This should help to transition to the new-style syntax until we eventually deprecate and remove the old-style syntax. Note that the way we handle this we're duplicating some functionality across old and new syntax. While this isn't pretty, it helps us to ensure that there really is no change in behaviour for the old syntax. Amend tests such that we run them both with old and new style syntax. As tests are now run twice, state from the first run may be still be around in the second run and thus cause tests to fail. Add cleanup logic as required to fix such tests. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 26 ++++++--- builtin/config.c | 90 ++++++++++++++++++++++++---- t/t1300-config.sh | 110 +++++++++++++++++++++-------------- 3 files changed, 162 insertions(+), 64 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index a6e82b871b..485e84cd0f 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,6 +9,7 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] +'git config list' [] [] [--includes] 'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] 'git config' [] [--type=] --add 'git config' [] [--type=] [--fixed-value] --replace-all [] @@ -20,7 +21,6 @@ SYNOPSIS 'git config' [] [--fixed-value] --unset-all [] 'git config' [] --rename-section 'git config' [] --remove-section -'git config' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list 'git config' [] --get-color [] 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -74,6 +74,12 @@ On success, the command returns the exit code 0. A list of all available configuration variables can be obtained using the `git help --config` command. +COMMANDS +-------- + +list:: + List all variables set in config file, along with their values. + [[OPTIONS]] OPTIONS ------- @@ -178,10 +184,6 @@ See also <>. --unset-all:: Remove all lines matching the key from config file. --l:: ---list:: - List all variables set in config file, along with their values. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -236,7 +238,7 @@ Valid ``'s include: contain line breaks. --name-only:: - Output only the names of config variables for `--list` or + Output only the names of config variables for `list` or `--get-regexp`. --show-origin:: @@ -288,10 +290,20 @@ Valid ``'s include: When using `--get`, and the requested variable is not found, behave as if were the value assigned to that variable. +DEPRECATED MODES +---------------- + +The following modes have been deprecated in favor of subcommands. It is +recommended to migrate to the new syntax. + +-l:: +--list:: + Replaced by `git config list`. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when -using `--list` or any of the `--get-*` which may return multiple results. +using `list` or any of the `--get-*` which may return multiple results. The default is to use a pager. [[FILES]] diff --git a/builtin/config.c b/builtin/config.c index ce2d3fecd4..7dd588a622 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -16,10 +16,16 @@ #include "worktree.h" static const char *const builtin_config_usage[] = { + N_("git config list [] [] [--includes]"), N_("git config []"), NULL }; +static const char *const builtin_config_list_usage[] = { + N_("git config list [] [] [--includes]"), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -33,6 +39,7 @@ static char delim = '='; static char key_delim = ' '; static char term = '\n'; +static parse_opt_subcommand_fn *subcommand; static int use_global_config, use_system_config, use_local_config; static int use_worktree_config; static struct git_config_source given_config_source; @@ -705,14 +712,24 @@ static void handle_nul(void) { } } +#define CONFIG_LOCATION_OPTIONS \ + OPT_GROUP(N_("Config file location")), \ + OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), \ + OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), \ + OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), \ + OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), \ + OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), \ + OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")) + +#define CONFIG_DISPLAY_OPTIONS \ + OPT_GROUP(N_("Display options")), \ + OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), \ + OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), \ + OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), \ + OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")) + static struct option builtin_config_options[] = { - OPT_GROUP(N_("Config file location")), - OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), - OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), - OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), - OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), - OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), - OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), + CONFIG_LOCATION_OPTIONS, OPT_GROUP(N_("Action")), OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), @@ -736,14 +753,11 @@ static struct option builtin_config_options[] = { OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), + CONFIG_DISPLAY_OPTIONS, OPT_GROUP(N_("Other")), - OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), - OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), - OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), 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")), OPT_END(), }; @@ -752,6 +766,42 @@ static NORETURN void usage_builtin_config(void) usage_with_options(builtin_config_usage, builtin_config_options); } +static int cmd_config_list(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + CONFIG_DISPLAY_OPTIONS, + OPT_GROUP(N_("Other")), + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_END(), + }; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_list_usage, 0); + check_argc(argc, 0, 0); + + handle_config_location(prefix); + handle_nul(); + + setup_auto_pager("config", 1); + + if (config_with_options(show_all_config, NULL, + &given_config_source, the_repository, + &config_options) < 0) { + if (given_config_source.file) + die_errno(_("unable to read config file '%s'"), + given_config_source.file); + else + die(_("error processing config file(s)")); + } + + return 0; +} + +static struct option builtin_subcommand_options[] = { + OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), + OPT_END(), +}; + int cmd_config(int argc, const char **argv, const char *prefix) { char *value = NULL; @@ -761,6 +811,22 @@ int cmd_config(int argc, const char **argv, const char *prefix) given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); + /* + * This is somewhat hacky: we first parse the command line while + * keeping all args intact in order to determine whether a subcommand + * has been specified. If so, we re-parse it a second time, but this + * time we drop KEEP_ARGV0. This is so that we don't munge the command + * line in case no subcommand was given, which would otherwise confuse + * us when parsing the legacy-style modes that don't use subcommands. + */ + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_NO_INTERNAL_HELP|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); + if (subcommand) { + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_NO_INTERNAL_HELP|PARSE_OPT_KEEP_UNKNOWN_OPT); + return subcommand(argc, argv, prefix); + } + argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 2d1bc1e27e..b140674293 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -11,6 +11,20 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +for mode in legacy subcommands +do + +case "$mode" in +legacy) + mode_prefix="--" + ;; +subcommands) + mode_prefix="" + ;; +*) + BUG "unknown mode $mode";; +esac + test_expect_success 'clear default config' ' rm -f .git/config ' @@ -350,11 +364,11 @@ version.1.2.3eX.alpha=beta EOF test_expect_success 'working --list' ' - git config --list > output && + git config ${mode_prefix}list > output && test_cmp expect output ' test_expect_success '--list without repo produces empty output' ' - git --git-dir=nonexistent config --list >output && + git --git-dir=nonexistent config ${mode_prefix}list >output && test_must_be_empty output ' @@ -366,7 +380,7 @@ version.1.2.3eX.alpha EOF test_expect_success '--name-only --list' ' - git config --name-only --list >output && + git config ${mode_prefix}list --name-only >output && test_cmp expect output ' @@ -504,17 +518,17 @@ ein.bahn=strasse EOF test_expect_success 'alternative GIT_CONFIG' ' - GIT_CONFIG=other-config git config --list >output && + GIT_CONFIG=other-config git config ${mode_prefix}list >output && test_cmp expect output ' test_expect_success 'alternative GIT_CONFIG (--file)' ' - git config --file other-config --list >output && + git config ${mode_prefix}list --file other-config >output && test_cmp expect output ' test_expect_success 'alternative GIT_CONFIG (--file=-)' ' - git config --file - --list output && + git config ${mode_prefix}list --file - output && test_cmp expect output ' @@ -527,6 +541,7 @@ test_expect_success 'editing stdin is an error' ' ' test_expect_success 'refer config from subdirectory' ' + test_when_finished "rm -r x" && mkdir x && test_cmp_config -C x strasse --file=../other-config --get ein.bahn ' @@ -737,7 +752,7 @@ test_expect_success 'line number is reported correctly' ' ' test_expect_success 'invalid stdin config' ' - echo "[broken" | test_must_fail git config --list --file - >output 2>&1 && + echo "[broken" | test_must_fail git config ${mode_prefix}list --file - >output 2>&1 && test_grep "bad config line 1 in standard input" output ' @@ -1029,7 +1044,7 @@ section.quotecont=cont;inued EOF test_expect_success 'value continued on next line' ' - git config --list > result && + git config ${mode_prefix}list > result && test_cmp expect result ' @@ -1053,7 +1068,7 @@ Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF test_expect_success '--null --list' ' - git config --null --list >result.raw && + git config ${mode_prefix}list --null >result.raw && nul_to_q result && echo >>result && test_cmp expect result @@ -1072,6 +1087,7 @@ test_expect_success 'inner whitespace kept verbatim' ' ' test_expect_success SYMLINKS 'symlinked configuration' ' + test_when_finished "rm myconfig" && ln -s notyet myconfig && git config --file=myconfig test.frotz nitfol && test -h myconfig && @@ -1092,10 +1108,11 @@ test_expect_success SYMLINKS 'symlinked configuration' ' ' test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' + test_when_finished "rm linktonada linktolinktonada" && ln -s doesnotexist linktonada && ln -s linktonada linktolinktonada && - test_must_fail git config --file=linktonada --list && - test_must_fail git config --file=linktolinktonada --list + test_must_fail git config ${mode_prefix}list --file=linktonada && + test_must_fail git config ${mode_prefix}list --file=linktolinktonada ' test_expect_success 'check split_cmdline return' ' @@ -1352,7 +1369,7 @@ do done test_expect_success 'git -c is not confused by empty environment' ' - GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list + GIT_CONFIG_PARAMETERS="" git -c x.one=1 config ${mode_prefix}list ' test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' ' @@ -1543,31 +1560,31 @@ test_expect_success 'git config ignores pairs with empty count' ' ' test_expect_success 'git config fails with invalid count' ' - test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error && + test_must_fail env GIT_CONFIG_COUNT=10a git config ${mode_prefix}list 2>error && test_grep "bogus count" error && - test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error && + test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config ${mode_prefix}list 2>error && test_grep "too many entries" error ' test_expect_success 'git config fails with missing config key' ' test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \ - git config --list 2>error && + git config ${mode_prefix}list 2>error && test_grep "missing config key" error ' test_expect_success 'git config fails with missing config value' ' test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \ - git config --list 2>error && + git config ${mode_prefix}list 2>error && test_grep "missing config value" error ' test_expect_success 'git config fails with invalid config pair key' ' test_must_fail env GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \ - git config --list && + git config ${mode_prefix}list && test_must_fail env GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \ - git config --list + git config ${mode_prefix}list ' test_expect_success 'environment overrides config file' ' @@ -1607,7 +1624,7 @@ test_expect_success 'git config --edit works' ' git config -f tmp test.value no && echo test.value=yes >expect && GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit && - git config -f tmp --list >actual && + git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' @@ -1616,7 +1633,7 @@ test_expect_success 'git config --edit respects core.editor' ' echo test.value=yes >expect && test_config core.editor "echo [test]value=yes >" && git config -f tmp --edit && - git config -f tmp --list >actual && + git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' @@ -1967,7 +1984,7 @@ test_expect_success '--show-origin with --list' ' command line: user.cmdline=true EOF GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\ - git -c user.cmdline=true config --list --show-origin >output && + git -c user.cmdline=true config ${mode_prefix}list --show-origin >output && test_cmp expect output ' @@ -1984,7 +2001,7 @@ test_expect_success '--show-origin with --list --null' ' includeQcommand line:Quser.cmdline trueQ EOF - git -c user.cmdline=true config --null --list --show-origin >output.raw && + git -c user.cmdline=true config ${mode_prefix}list --null --show-origin >output.raw && nul_to_q output && # The here-doc above adds a newline that the --null output would not # include. Add it here to make the two comparable. @@ -1998,7 +2015,7 @@ test_expect_success '--show-origin with single file' ' file:.git/config user.override=local file:.git/config include.path=../include/relative.include EOF - git config --local --list --show-origin >output && + git config ${mode_prefix}list --local --show-origin >output && test_cmp expect output ' @@ -2036,7 +2053,7 @@ test_expect_success !MINGW '--show-origin escape special file name characters' ' cat >expect <<-\EOF && file:"file\" (dq) and spaces.conf" user.custom=true EOF - git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output && + git config ${mode_prefix}list --file "$WEIRDLY_NAMED_FILE" --show-origin >output && test_cmp expect output ' @@ -2044,7 +2061,7 @@ test_expect_success '--show-origin stdin' ' cat >expect <<-\EOF && standard input: user.custom=true EOF - git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output && + git config ${mode_prefix}list --file - --show-origin <"$CUSTOM_CONFIG_FILE" >output && test_cmp expect output ' @@ -2071,7 +2088,7 @@ test_expect_success '--show-origin blob' ' cat >expect <<-EOF && blob:$blob user.custom=true EOF - git config --blob=$blob --show-origin --list >output && + git config ${mode_prefix}list --blob=$blob --show-origin >output && test_cmp expect output ) ' @@ -2087,7 +2104,7 @@ test_expect_success '--show-origin blob ref' ' cp "$CUSTOM_CONFIG_FILE" custom.conf && git add custom.conf && git commit -m "new config file" && - git config --blob=main:custom.conf --show-origin --list >output && + git config ${mode_prefix}list --blob=main:custom.conf --show-origin >output && test_cmp expect output ) ' @@ -2113,13 +2130,14 @@ test_expect_success '--show-scope with --list' ' worktree user.worktree=true command user.cmdline=true EOF + test_when_finished "git worktree remove wt1" && git worktree add wt1 && # We need these to test for worktree scope, but outside of this # test, this is just noise test_config core.repositoryformatversion 1 && test_config extensions.worktreeConfig true && git config --worktree user.worktree true && - git -c user.cmdline=true config --list --show-scope >output && + git -c user.cmdline=true config ${mode_prefix}list --show-scope >output && test_cmp expect output ' @@ -2128,7 +2146,7 @@ test_expect_success !MINGW '--show-scope with --blob' ' cat >expect <<-EOF && command user.custom=true EOF - git config --blob=$blob --show-scope --list >output && + git config ${mode_prefix}list --blob=$blob --show-scope >output && test_cmp expect output ' @@ -2138,7 +2156,7 @@ test_expect_success '--show-scope with --local' ' local user.override=local local include.path=../include/relative.include EOF - git config --local --list --show-scope >output && + git config ${mode_prefix}list --local --show-scope >output && test_cmp expect output ' @@ -2162,7 +2180,7 @@ test_expect_success '--show-scope with --show-origin' ' local file:.git/../include/relative.include user.relative=include command command line: user.cmdline=true EOF - git -c user.cmdline=true config --list --show-origin --show-scope >output && + git -c user.cmdline=true config ${mode_prefix}list --show-origin --show-scope >output && test_cmp expect output ' @@ -2203,7 +2221,7 @@ test_expect_success 'override global and system config' ' global home.config=true local local.config=true EOF - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output && cat >expect <<-EOF && @@ -2212,20 +2230,20 @@ test_expect_success 'override global and system config' ' local local.config=true EOF GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \ - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output && cat >expect <<-EOF && local local.config=true EOF GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \ - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output ' test_expect_success 'override global and system config with missing file' ' - test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list && - test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list && + test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config ${mode_prefix}list --global && + test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config ${mode_prefix}list --system && GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version ' @@ -2352,7 +2370,7 @@ test_expect_success 'set all config with value-pattern' ' # no match => add new entry cp initial config && git config --file=config abc.key two a+ && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2365,7 +2383,7 @@ test_expect_success 'set all config with value-pattern' ' # multiple values, no match => add git config --file=config abc.key three a+ && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2375,7 +2393,7 @@ test_expect_success 'set all config with value-pattern' ' # single match => replace git config --file=config abc.key four h+ && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2390,7 +2408,7 @@ test_expect_success '--replace-all and value-pattern' ' git config --file=config --add abc.key two && git config --file=config --add abc.key three && git config --file=config --replace-all abc.key four "o+" && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=four abc.key=three @@ -2408,7 +2426,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && test_must_fail git config --file=config --fixed-value --rename-section dev null && test_must_fail git config --file=config --fixed-value --remove-section dev && - test_must_fail git config --file=config --fixed-value --list && + test_must_fail git config ${mode_prefix}list --file=config --fixed-value && test_must_fail git config --file=config --fixed-value --get-color dev.null && test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && @@ -2429,7 +2447,7 @@ test_expect_success '--fixed-value uses exact string matching' ' cp initial config && git config --file=config fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=$META fixed.test=bogus @@ -2438,7 +2456,7 @@ test_expect_success '--fixed-value uses exact string matching' ' cp initial config && git config --file=config --fixed-value fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && fixed.test=bogus EOF @@ -2456,7 +2474,7 @@ test_expect_success '--fixed-value uses exact string matching' ' cp initial config && git config --file=config --replace-all fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=$META fixed.test=bogus @@ -2464,7 +2482,7 @@ test_expect_success '--fixed-value uses exact string matching' ' test_cmp expect actual && git config --file=config --fixed-value --replace-all fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=bogus fixed.test=bogus @@ -2625,4 +2643,6 @@ test_expect_success 'specifying multiple modes causes failure' ' test_cmp expect err ' +done + test_done From patchwork Wed Mar 27 08:46:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605955 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 09A8D374C6 for ; Wed, 27 Mar 2024 08:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529205; cv=none; b=t0rovrrxa+yK9rMNS3FgBfIodRAxj0njLpd2CZckJ2AwS/1tztagJJzIH5ByteNkqXuqLO6KgMJLjRhnQ3n4QAM1A3MGmLMNj/DDV4VBd7isOPReWvRm+ud0/UWy6FOBGUyh7/yfHzwC8WNdClJMwk5ZZMGe08k1uvNxqG6xgfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529205; c=relaxed/simple; bh=cvwcpb1wcOarcI90jr6M3/toZn/mT5kU7Ao8Vwnlxus=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p8fTXgsb3dYdRmYuALm/+mhyMKirs7KUKIJjoCfer8H+0yiib4IuSTCvc318r5W8C+gsSe26AXdIangu24eswg6POVfQI5orCtQvV34vbFSIejFygL42kI0FIcXHlI7yTWpG2Sy/B6vLis2htHEGhRixfVL4GEpySqHzk/WaSxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=iIr60Cn9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mYSz77jK; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="iIr60Cn9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mYSz77jK" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 1E8E9138015E; Wed, 27 Mar 2024 04:46:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 27 Mar 2024 04:46:42 -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=fm2; t=1711529202; x=1711615602; bh=c+ljrOO8Os yGcBCFz3+CRPvsnf6ONPvzwOo4/v03E8k=; b=iIr60Cn9RQlx5YUG5/ys0e3pjt dblHy/LtmLGSsfQO74U/7D2JVcMQdjuI4/4bBPcVmB7h2i/5gClG4p571JD+ovZU 28qFfD4ZSU0nEJ9IauO/KlJmceiPyYdGwtUwkFM6ziEGXKGY3ZBorOk0Jpo6GHs2 353n4jkTlPANOnn+oCWHNSqud4ydr4f3AHLzuLe7dqKRCUIx2tMqUvdRWpBpR7zD 8SqQQJKDw8gNvYXn3fgkZPBk4Qwxksr4x9SOFZ4sLVRHWt83LGAwfsAEbwBYPCUi FPJs74zV2pmRYt7ztHmuyOHcWkTc/Qp3O+eNLaHt6zBgnFaiAcetoWs2oSRw== 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= fm2; t=1711529202; x=1711615602; bh=c+ljrOO8OsyGcBCFz3+CRPvsnf6O NPvzwOo4/v03E8k=; b=mYSz77jKMgs0/eT+ayPDTkKiZwPH4NN/vl+1NlPWr6a3 pS+h4oQFsLErQueyXrX1f4fBi8dSOU9TOlENPx8TU8W2O7OlGkNb3bp1pr9u+gA7 BMXV3u2yaElDYkBEGCbhVAyQshLXLQn/K2N1hTik/KQPvjFCggmXU4MbPDNQzmMB F2tG7fTttQRFAWA433jNjE5V7MFVwu0fEJzkh51S56xylHlxx9DYkLnNdk+NZkVA 0EnqugoKfxWSbimklZwRXa32mE5VJ4vHNt/sC3bUkAG6ztv2d71XCBazYjkIna4M NxJEozR99nXi44sP7T89tPKIclA1VV2jW+63RqK3gQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enuhhsvghruchinhculhhinhhkucdliedtmdenucfjughrpeffhffvvefukfhfgggtuggj sehgtderredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoe hpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpedugfeltdeutddvhfelhfeffeej gffgjedvhefhkeegveellefhheeiiefftdfgudenucffohhmrghinhepughifhhfrdhnvg ifpdhkvghrnhgvlhdrohhrghdpvgigrghmphhlvgdrtghomhdpvgigrghmphhlvgdrohhr ghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5b148de9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:27 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:38 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 07/13] builtin/config: introduce "get" subcommand 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: Introduce a new "get" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 93 +++++++++++++------------- builtin/config.c | 69 ++++++++++++++++--- t/t1300-config.sh | 125 ++++++++++++++++++++++++----------- 3 files changed, 191 insertions(+), 96 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 485e84cd0f..4a7d6b7543 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -10,18 +10,14 @@ SYNOPSIS -------- [verse] 'git config list' [] [] [--includes] +'git config get' [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] 'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] 'git config' [] [--type=] --add 'git config' [] [--type=] [--fixed-value] --replace-all [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp [] -'git config' [] [--type=] [-z|--null] --get-urlmatch 'git config' [] [--fixed-value] --unset [] 'git config' [] [--fixed-value] --unset-all [] 'git config' [] --rename-section 'git config' [] --remove-section -'git config' [] --get-color [] 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -80,6 +76,12 @@ COMMANDS list:: List all variables set in config file, along with their values. +get:: + Emits the value of the specified key. If key is present multiple times + in the configuration, emits the last value. If `--all` is specified, + emits all values associated with key. Returns error code 1 if key is + not present. + [[OPTIONS]] OPTIONS ------- @@ -93,22 +95,16 @@ OPTIONS values. This is the same as providing '^$' as the `value-pattern` in `--replace-all`. ---get:: - Get the value for a given key (optionally filtered by a regex - matching the value). Returns error code 1 if the key was not - found and the last value if multiple key values were found. - ---get-all:: - Like get, but returns all values for a multi-valued key. +--all:: + With `get`, Return all values for a multi-valued key. ---get-regexp:: - Like --get-all, but interprets the name as a regular expression and - writes out the key names. Regular expression matching is currently - case-sensitive and done against a canonicalized version of the key - in which section and variable names are lowercased, but subsection - names are not. +---regexp:: + With `get`, interpret the name as a regular expression. Regular + expression matching is currently case-sensitive and done against a + canonicalized version of the key in which section and variable names + are lowercased, but subsection names are not. ---get-urlmatch :: +--url=:: When given a two-part as
., the value for
.. whose part matches the best to the given URL is returned (if no such key exists, the value for @@ -239,7 +235,7 @@ Valid ``'s include: --name-only:: Output only the names of config variables for `list` or - `--get-regexp`. + `get`. --show-origin:: Augment the output of all queried config options with the @@ -263,17 +259,6 @@ Valid ``'s include: When the color setting for `name` is undefined, the command uses `color.ui` as fallback. ---get-color []:: - - Find the color configured for `name` (e.g. `color.diff.new`) and - output it as the ANSI color escape sequence to the standard - output. The optional `default` parameter is used instead, if - there is no color configured for `name`. -+ -`--type=color [--default=]` is preferred over `--get-color` -(but note that `--get-color` will omit the trailing newline printed by -`--type=color`). - -e:: --edit:: Opens an editor to modify the specified config file; either @@ -287,7 +272,7 @@ Valid ``'s include: config files. --default :: - When using `--get`, and the requested variable is not found, behave as if + When using `get`, and the requested variable is not found, behave as if were the value assigned to that variable. DEPRECATED MODES @@ -296,15 +281,33 @@ DEPRECATED MODES The following modes have been deprecated in favor of subcommands. It is recommended to migrate to the new syntax. +'git config ':: + Replaced by `git config get `. + -l:: --list:: Replaced by `git config list`. +--get []:: + Replaced by `git config get [--value=] `. + +--get-all []:: + Replaced by `git config get [--value=] --all --show-names `. + +--get-regexp :: + Replaced by `git config get --all --show-names --regexp `. + +--get-urlmatch :: + Replaced by `git config get --all --show-names --url= `. + +--get-color []:: + Replaced by `git config get --type=color [--default=] `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when -using `list` or any of the `--get-*` which may return multiple results. -The default is to use a pager. +using `list` or `get` which may return multiple results. The default is to use +a pager. [[FILES]] FILES @@ -507,25 +510,19 @@ you have to provide a regex matching the value of exactly one line. To query the value for a given key, do ------------ -% git config --get core.filemode ------------- - -or - ------------- -% git config core.filemode +% git config get core.filemode ------------ or, to query a multivar: ------------ -% git config --get core.gitproxy "for kernel.org$" +% git config get --value="for kernel.org$" core.gitproxy ------------ If you want to know all the values for a multivar, do: ------------ -% git config --get-all core.gitproxy +% git config get --all --show-names core.gitproxy ------------ If you like to live dangerously, you can replace *all* core.gitproxy by a @@ -559,8 +556,8 @@ script: ------------ #!/bin/sh -WS=$(git config --get-color color.diff.whitespace "blue reverse") -RESET=$(git config --get-color "" "reset") +WS=$(git config get --type=color --default="blue reverse" color.diff.whitespace) +RESET=$(git config get --type=color --default="reset" "") echo "${WS}your whitespace color or blue reverse${RESET}" ------------ @@ -568,11 +565,11 @@ For URLs in `https://weak.example.com`, `http.sslVerify` is set to false, while it is set to `true` for all others: ------------ -% git config --type=bool --get-urlmatch http.sslverify https://good.example.com +% git config get --type=bool --url=https://good.example.com http.sslverify true -% git config --type=bool --get-urlmatch http.sslverify https://weak.example.com +% git config get --type=bool --url=https://weak.example.com http.sslverify false -% git config --get-urlmatch http https://weak.example.com +% git config get --url=https://weak.example.com http http.cookieFile /tmp/cookie.txt http.sslverify false ------------ diff --git a/builtin/config.c b/builtin/config.c index 7dd588a622..447500dbd2 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -17,7 +17,7 @@ static const char *const builtin_config_usage[] = { N_("git config list [] [] [--includes]"), - N_("git config []"), + N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), NULL }; @@ -26,6 +26,11 @@ static const char *const builtin_config_list_usage[] = { NULL }; +static const char *const builtin_config_get_usage[] = { + N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -721,6 +726,16 @@ static void handle_nul(void) { OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), \ OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")) +#define CONFIG_TYPE_OPTIONS \ + OPT_GROUP(N_("Type")), \ + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \ + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), \ + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), \ + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), \ + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), \ + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), \ + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE) + #define CONFIG_DISPLAY_OPTIONS \ OPT_GROUP(N_("Display options")), \ OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), \ @@ -745,14 +760,7 @@ static struct option builtin_config_options[] = { OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot []"), ACTION_GET_COLOR), OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), - OPT_GROUP(N_("Type")), - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), + CONFIG_TYPE_OPTIONS, CONFIG_DISPLAY_OPTIONS, OPT_GROUP(N_("Other")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), @@ -797,8 +805,51 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix) return 0; } +static int cmd_config_get(int argc, const char **argv, const char *prefix) +{ + const char *value_pattern = NULL, *url = NULL; + int flags = 0; + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + CONFIG_TYPE_OPTIONS, + OPT_GROUP(N_("Filter options")), + OPT_BOOL(0, "all", &do_all, N_("return all values for multi-valued config options")), + OPT_BOOL(0, "regexp", &use_key_regexp, N_("interpret the name as a regular expression")), + OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), + OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), + OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")), + CONFIG_DISPLAY_OPTIONS, + OPT_BOOL(0, "show-names", &show_keys, N_("show config keys in addition to their values")), + 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_END(), + }; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_get_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_argc(argc, 1, 1); + + if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) + die(_("--fixed-value only applies with 'value-pattern'")); + if (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")); + + handle_config_location(prefix); + handle_nul(); + + setup_auto_pager("config", 1); + + if (url) + return get_urlmatch(argv[0], url); + return get_value(argv[0], value_pattern, flags); +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), + OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index b140674293..f1547921c6 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -17,9 +17,15 @@ do case "$mode" in legacy) mode_prefix="--" + mode_get="" + mode_get_all="--get-all" + mode_get_regexp="--get-regexp" ;; subcommands) mode_prefix="" + mode_get="get" + mode_get_all="get --all" + mode_get_regexp="get --regexp --all --show-names" ;; *) BUG "unknown mode $mode";; @@ -288,7 +294,7 @@ test_expect_success 'multi-valued get-all returns all' ' wow wow2 for me EOF - git config --get-all nextsection.nonewline >actual && + git config ${mode_get_all} nextsection.nonewline >actual && test_cmp expect actual ' @@ -390,7 +396,7 @@ nextsection.nonewline wow2 for me EOF test_expect_success '--get-regexp' ' - git config --get-regexp in >output && + git config ${mode_get_regexp} in >output && test_cmp expect output ' @@ -400,7 +406,7 @@ nextsection.nonewline EOF test_expect_success '--name-only --get-regexp' ' - git config --name-only --get-regexp in >output && + git config ${mode_get_regexp} --name-only in >output && test_cmp expect output ' @@ -411,7 +417,7 @@ EOF test_expect_success '--add' ' git config --add nextsection.nonewline "wow4 for you" && - git config --get-all nextsection.nonewline > output && + git config ${mode_get_all} nextsection.nonewline > output && test_cmp expect output ' @@ -433,21 +439,21 @@ test_expect_success 'get variable with empty value' ' echo novalue.variable > expect test_expect_success 'get-regexp variable with no value' ' - git config --get-regexp novalue > output && + git config ${mode_get_regexp} novalue > output && test_cmp expect output ' echo 'novalue.variable true' > expect test_expect_success 'get-regexp --bool variable with no value' ' - git config --bool --get-regexp novalue > output && + git config ${mode_get_regexp} --bool novalue > output && test_cmp expect output ' echo 'emptyvalue.variable ' > expect test_expect_success 'get-regexp variable with empty value' ' - git config --get-regexp emptyvalue > output && + git config ${mode_get_regexp} emptyvalue > output && test_cmp expect output ' @@ -1021,7 +1027,7 @@ test_expect_success 'quoting' ' ' test_expect_success 'key with newline' ' - test_must_fail git config "key.with + test_must_fail git config ${mode_get} "key.with newline" 123' test_expect_success 'value with newline' 'git config key.sub value.with\\\ @@ -1075,7 +1081,7 @@ test_expect_success '--null --list' ' ' test_expect_success '--null --get-regexp' ' - git config --null --get-regexp "val[0-9]" >result.raw && + git config ${mode_get_regexp} --null "val[0-9]" >result.raw && nul_to_q result && echo >>result && test_cmp expect result @@ -1157,11 +1163,11 @@ test_expect_success 'git -c can represent empty string' ' ' test_expect_success 'key sanity-checking' ' - test_must_fail git config foo=bar && - test_must_fail git config foo=.bar && - test_must_fail git config foo.ba=r && - test_must_fail git config foo.1bar && - test_must_fail git config foo."ba + test_must_fail git config ${mode_get} foo=bar && + test_must_fail git config ${mode_get} foo=.bar && + test_must_fail git config ${mode_get} foo.ba=r && + test_must_fail git config ${mode_get} foo.1bar && + test_must_fail git config ${mode_get} foo."ba z".bar && test_must_fail git config . false && test_must_fail git config .foo false && @@ -1210,7 +1216,7 @@ test_expect_success 'git -c complains about empty key and value' ' ' test_expect_success 'multiple git -c appends config' ' - test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" && + test_config alias.x "!git -c x.two=2 config ${mode_get_regexp} ^x\.*" && cat >expect <<-\EOF && x.one 1 x.two 2 @@ -1376,7 +1382,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' ' v="${SQ}key.one=foo${SQ}" && v="$v ${SQ}key.two=bar${SQ}" && v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual && cat >expect <<-EOF && key.one foo key.two bar @@ -1389,7 +1395,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' ' v="${SQ}key.one${SQ}=${SQ}foo${SQ}" && v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" && v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual && cat >expect <<-EOF && key.one foo key.two bar @@ -1403,7 +1409,7 @@ test_expect_success 'old and new-style entries can mix' ' v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" && v="$v ${SQ}key.oldtwo=oldbar${SQ}" && v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual && cat >expect <<-EOF && key.oldone oldfoo key.newone newfoo @@ -1416,7 +1422,7 @@ test_expect_success 'old and new-style entries can mix' ' test_expect_success 'old and new bools with ambiguous subsection' ' v="${SQ}key.with=equals.oldbool${SQ}" && v="$v ${SQ}key.with=equals.newbool${SQ}=" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual && cat >expect <<-EOF && key.with equals.oldbool key.with=equals.newbool @@ -1430,7 +1436,7 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' env.two two EOF GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" >actual && + git config ${mode_get_regexp} "env.*" >actual && test_cmp expect actual && cat >expect <<-EOF && @@ -1438,12 +1444,12 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' env.two two EOF GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" >actual && + git config ${mode_get_regexp} "env.*" >actual && test_cmp expect actual && test_must_fail env \ GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" + git config ${mode_get_regexp} "env.*" ' test_expect_success 'git --config-env=key=envvar support' ' @@ -1491,7 +1497,7 @@ test_expect_success 'git -c and --config-env work together' ' ENVVAR=env-value git \ -c bar.cmd=cmd-value \ --config-env=bar.env=ENVVAR \ - config --get-regexp "^bar.*" >actual && + config ${mode_get_regexp} "^bar.*" >actual && test_cmp expect actual ' @@ -1519,7 +1525,7 @@ test_expect_success 'git config handles environment config pairs' ' GIT_CONFIG_COUNT=2 \ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \ - git config --get-regexp "pair.*" >actual && + git config ${mode_get_regexp} "pair.*" >actual && cat >expect <<-EOF && pair.one foo pair.two bar @@ -1529,7 +1535,7 @@ test_expect_success 'git config handles environment config pairs' ' test_expect_success 'git config ignores pairs without count' ' test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ - git config pair.one 2>error && + git config ${mode_get} pair.one 2>error && test_must_be_empty error ' @@ -1537,7 +1543,7 @@ test_expect_success 'git config ignores pairs exceeding count' ' GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \ - git config --get-regexp "pair.*" >actual 2>error && + git config ${mode_get_regexp} "pair.*" >actual 2>error && cat >expect <<-EOF && pair.one value EOF @@ -1548,14 +1554,14 @@ test_expect_success 'git config ignores pairs exceeding count' ' test_expect_success 'git config ignores pairs with zero count' ' test_must_fail env \ GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ - git config pair.one 2>error && + git config ${mode_get} pair.one 2>error && test_must_be_empty error ' test_expect_success 'git config ignores pairs with empty count' ' test_must_fail env \ GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ - git config pair.one 2>error && + git config ${mode_get} pair.one 2>error && test_must_be_empty error ' @@ -1594,7 +1600,7 @@ test_expect_success 'environment overrides config file' ' one = value EOF GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \ - git config pair.one >actual && + git config ${mode_get} pair.one >actual && cat >expect <<-EOF && override EOF @@ -1604,7 +1610,7 @@ test_expect_success 'environment overrides config file' ' test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' ' GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \ GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \ - git config pair.one >actual && + git config ${mode_get} pair.one >actual && cat >expect <<-EOF && override EOF @@ -1679,20 +1685,28 @@ test_expect_success 'urlmatch' ' test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && test_must_be_empty actual && + test_expect_code 1 git config get --url=https://good.example.com --bool doesnt.exist >actual && + test_must_be_empty actual && echo true >expect && git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual && test_cmp expect actual && + git config get --bool --url=https://good.example.com http.SSLverify >actual && + test_cmp expect actual && echo false >expect && git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual && test_cmp expect actual && + git config get --bool --url=https://weak.example.com http.sslverify >actual && + test_cmp expect actual && { echo http.cookiefile /tmp/cookie.txt && echo http.sslverify false } >expect && git config --get-urlmatch HTTP https://weak.example.com >actual && + test_cmp expect actual && + git config get --url=https://weak.example.com HTTP >actual && test_cmp expect actual ' @@ -1708,6 +1722,8 @@ test_expect_success 'urlmatch with --show-scope' ' local http.sslverify false EOF git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual && + test_cmp expect actual && + git config get --url=https://weak.example.com --show-scope HTTP >actual && test_cmp expect actual ' @@ -1740,45 +1756,67 @@ test_expect_success 'urlmatch favors more specific URLs' ' echo http.cookiefile /tmp/root.txt >expect && git config --get-urlmatch HTTP https://example.com >actual && test_cmp expect actual && + git config get --url=https://example.com HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && git config --get-urlmatch HTTP https://example.com/subdirectory >actual && test_cmp expect actual && + git config get --url=https://example.com/subdirectory HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual && test_cmp expect actual && + git config get --url=https://example.com/subdirectory/nested HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/user.txt >expect && git config --get-urlmatch HTTP https://user@example.com/ >actual && test_cmp expect actual && + git config get --url=https://user@example.com/ HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual && test_cmp expect actual && + git config get --url=https://averylonguser@example.com/subdirectory HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/preceding.txt >expect && git config --get-urlmatch HTTP https://preceding.example.com >actual && test_cmp expect actual && + git config get --url=https://preceding.example.com HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/wildcard.txt >expect && git config --get-urlmatch HTTP https://wildcard.example.com >actual && test_cmp expect actual && + git config get --url=https://wildcard.example.com HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/sub.txt >expect && git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual && test_cmp expect actual && + git config get --url=https://sub.example.com/wildcardwithsubdomain HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/trailing.txt >expect && git config --get-urlmatch HTTP https://trailing.example.com >actual && test_cmp expect actual && + git config get --url=https://trailing.example.com HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/sub.txt >expect && git config --get-urlmatch HTTP https://user@sub.example.com >actual && test_cmp expect actual && + git config get --url=https://user@sub.example.com HTTP >actual && + test_cmp expect actual && echo http.cookiefile /tmp/multiwildcard.txt >expect && git config --get-urlmatch HTTP https://wildcard.example.org >actual && + test_cmp expect actual && + git config get --url=https://wildcard.example.org HTTP >actual && test_cmp expect actual ' @@ -1901,7 +1939,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [one] EOF git config --unset two.subsection.key && - test "not [two subsection]" = "$(git config one.key)" && + test "not [two subsection]" = "$(git config ${mode_get} one.key)" && test_line_count = 3 .git/config ' @@ -2024,7 +2062,7 @@ test_expect_success '--show-origin with --get-regexp' ' file:$HOME/.gitconfig user.global true file:.git/config user.local true EOF - git config --show-origin --get-regexp "user\.[g|l].*" >output && + git config ${mode_get_regexp} --show-origin "user\.[g|l].*" >output && test_cmp expect output ' @@ -2032,7 +2070,7 @@ test_expect_success '--show-origin getting a single key' ' cat >expect <<-\EOF && file:.git/config local EOF - git config --show-origin user.override >output && + git config ${mode_get} --show-origin user.override >output && test_cmp expect output ' @@ -2164,7 +2202,7 @@ test_expect_success '--show-scope getting a single value' ' cat >expect <<-\EOF && local true EOF - git config --show-scope --get user.local >output && + git config ${mode_get} --show-scope user.local >output && test_cmp expect output ' @@ -2433,9 +2471,9 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' # These modes complain when --fixed-value has no value-pattern test_must_fail git config --file=config --fixed-value dev.null bogus && test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && - test_must_fail git config --file=config --fixed-value --get dev.null && - test_must_fail git config --file=config --fixed-value --get-all dev.null && - test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" && + test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null && + test_must_fail git config ${mode_get_all} --file=config --fixed-value dev.null && + test_must_fail git config ${mode_get_regexp} --file=config --fixed-value "dev.*" && test_must_fail git config --file=config --fixed-value --unset dev.null && test_must_fail git config --file=config --fixed-value --unset-all dev.null ' @@ -2465,12 +2503,12 @@ test_expect_success '--fixed-value uses exact string matching' ' cp initial config && test_must_fail git config --file=config --unset fixed.test "$META" && git config --file=config --fixed-value --unset fixed.test "$META" && - test_must_fail git config --file=config fixed.test && + test_must_fail git config ${mode_get} --file=config fixed.test && cp initial config && test_must_fail git config --file=config --unset-all fixed.test "$META" && git config --file=config --fixed-value --unset-all fixed.test "$META" && - test_must_fail git config --file=config fixed.test && + test_must_fail git config ${mode_get} --file=config fixed.test && cp initial config && git config --file=config --replace-all fixed.test bogus "$META" && @@ -2497,18 +2535,27 @@ test_expect_success '--get and --get-all with --fixed-value' ' git config --file=config --add fixed.test "$META" && git config --file=config --get fixed.test bogus && + git config get --file=config --value=bogus fixed.test && test_must_fail git config --file=config --get fixed.test "$META" && + test_must_fail git config get --file=config --value="$META" fixed.test && git config --file=config --get --fixed-value fixed.test "$META" && + git config get --file=config --fixed-value --value="$META" fixed.test && test_must_fail git config --file=config --get --fixed-value fixed.test non-existent && git config --file=config --get-all fixed.test bogus && + git config get --all --file=config --value=bogus fixed.test && test_must_fail git config --file=config --get-all fixed.test "$META" && + test_must_fail git config get --all --file=config --value="$META" fixed.test && git config --file=config --get-all --fixed-value fixed.test "$META" && + git config get --all --file=config --value="$META" --fixed-value fixed.test && test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent && git config --file=config --get-regexp fixed+ bogus && + git config get --regexp --file=config --value=bogus fixed+ && test_must_fail git config --file=config --get-regexp fixed+ "$META" && + test_must_fail git config get --regexp --file=config --value="$META" fixed+ && git config --file=config --get-regexp --fixed-value fixed+ "$META" && + git config get --regexp --file=config --fixed-value --value="$META" fixed+ && test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent ' From patchwork Wed Mar 27 08:46:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605956 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.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 971B6374D3 for ; Wed, 27 Mar 2024 08:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529209; cv=none; b=l3lzOTE6FgpI5f57BBLOYPWs+75PbRn2vFwQrnyhKvaT9CoN2QCiaJUhv9vAMHMLyHeha+VrZmAAVeTSLmUs+bRUsjyx/o62FZVaKkEIFuQpXYRW2jb3qxVZ54Ab7CM1bqHUSmf+v8MzVRO1usbKlbDqljd5xnPJ13ev6wEEz08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529209; c=relaxed/simple; bh=vT6a5ul5oNJGkcQ4EdQSYlryxsNMfNUObwSrvqIRzNc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DLnbB+BMDcvDFGFBV5lIqAWXAtwQfJ7dDINA2Ow+Y1RIh/PjICorH62pIadzsgJOCPTtCmKuGWUrBMcjPnzbG3kBY+Mi9TM2ietjFpvZbN9fBA/n7VrChQ9OEd5EAhYL5xKZ2dumH9bomYfqkzNJwv/xgmgIBDu156OO8BRH11E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=fjqIkHHm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Yzvu9a/j; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="fjqIkHHm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Yzvu9a/j" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B40AB11400CD; Wed, 27 Mar 2024 04:46:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 27 Mar 2024 04:46:46 -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=fm2; t=1711529206; x=1711615606; bh=MfHmB5RcO4 vX7VaUwVtaWS+zV40OnkxDPPYTva+YZKQ=; b=fjqIkHHm4lb83jcS6D9aTyCP4v yD8J0ZIZgqEknsmG334+xiNBnspU4MjMW/K+oZhBZvJCpi+BGwJ8niEYot4UdPI3 RKEE1wqRUk7K7EqHsu6Q2S3nGiTvdUdxd/PiloheJkbsBk2wwm4lBC4+ZkI8glHV 4o0jbWwB3/w8Ih9aaOh1CulPTldYLLQLMQyV4bkUQYDUyyXY68TY2DL7lSiHbnUA ZSDpm8ZGTOcbMCe7CXVMNFVVqP/Sjzeiyqas1tzO+wTjUX1dXHCz6q2mqChYDTab PKFECg0Azr2DnLFUKigGy0fiBZDj+vrVqtgDAsu6mtFSzbWD8f9Ia2Km5Luw== 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= fm2; t=1711529206; x=1711615606; bh=MfHmB5RcO4vX7VaUwVtaWS+zV40O nkxDPPYTva+YZKQ=; b=Yzvu9a/j0tBBSrD63XHjLb6JQNa2S3shcd8RqzDV4J+E gynjJQs104ZxhTxB7fQpBeTFf8QYJ8ONjIGN0noPPbWp1Q+9xbBcVOwepYw9qkET JnOMmTpwuaYveO27swU/ARnxx2QHWNOxPm7VFd1WdNY28MB5ikJDWIY5QttY6g2f h0lx7ZvClLgj7Cb43a8ARYlZHplVgqJH7mwFC4hwuwJVZohU7WTHRy2Rcq81rxLq Or6ggBTV0/RgxlF6+vyu6bZsNkrNKZXUWiMGgP/9i0scTtosH8/xvglXjpH5lQ2C KoVJ8uPJwMjBuWwY2wIx7f/2muFa8OzFtdomN2dq+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeujeeitefggeelheejleetjeevtdetleetkedtgfeuvdehtddvfeelvdetjeeu vdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgpdhunhhithdrihhnnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a25e1896 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:31 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:43 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 08/13] builtin/config: introduce "set" subcommand 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: Introduce a new "set" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 38 +++++++++------ builtin/config.c | 57 ++++++++++++++++++++++ t/t1300-config.sh | 92 +++++++++++++++++++----------------- 3 files changed, 129 insertions(+), 58 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 4a7d6b7543..7fdf9b434e 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -11,9 +11,7 @@ SYNOPSIS [verse] 'git config list' [] [] [--includes] 'git config get' [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] -'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] -'git config' [] [--type=] --add -'git config' [] [--type=] [--fixed-value] --replace-all [] +'git config set' [] [--type=] [--all] [--value=] [--fixed-value] 'git config' [] [--fixed-value] --unset [] 'git config' [] [--fixed-value] --unset-all [] 'git config' [] --rename-section @@ -27,7 +25,7 @@ You can query/set/replace/unset options with this command. The name is actually the section and the key separated by a dot, and the value will be escaped. -Multiple lines can be added to an option by using the `--add` option. +Multiple lines can be added to an option by using the `--append` option. If you want to update or unset an option which can occur on multiple lines, a `value-pattern` (which is an extended regular expression, unless the `--fixed-value` option is given) needs to be given. Only the @@ -82,6 +80,13 @@ get:: emits all values associated with key. Returns error code 1 if key is not present. +set:: + Set value for one or more config options. By default, this command + refuses to write multi-valued config options. Passing `--all` will + replace all multi-valued config options with the new value, whereas + `--value=` will replace all config options whose values match the given + pattern. + [[OPTIONS]] OPTIONS ------- @@ -90,10 +95,9 @@ OPTIONS Default behavior is to replace at most one line. This replaces all lines matching the key (and optionally the `value-pattern`). ---add:: +--append:: Adds a new line to the option without altering any existing - values. This is the same as providing '^$' as the `value-pattern` - in `--replace-all`. + values. This is the same as providing '--value=^$' in `set`. --all:: With `get`, Return all values for a multi-valued key. @@ -284,6 +288,9 @@ recommended to migrate to the new syntax. 'git config ':: Replaced by `git config get `. +'git config []':: + Replaced by `git config set [--value=] `. + -l:: --list:: Replaced by `git config list`. @@ -303,6 +310,9 @@ recommended to migrate to the new syntax. --get-color []:: Replaced by `git config get --type=color [--default=] `. +--add :: + Replaced by `git config set --append `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when @@ -349,7 +359,7 @@ precedence over values read earlier. When multiple values are taken then all values of a key from all files will be used. By default, options are only written to the repository specific -configuration file. Note that this also affects options like `--replace-all` +configuration file. Note that this also affects options like `set` and `--unset`. *'git config' will only ever change one file at a time*. You can limit which configuration sources are read from or written to by @@ -485,7 +495,7 @@ Given a .git/config like this: you can set the filemode to true with ------------ -% git config core.filemode true +% git config set core.filemode true ------------ The hypothetical proxy command entries actually have a postfix to discern @@ -493,7 +503,7 @@ what URL they apply to. Here is how to change the entry for kernel.org to "ssh". ------------ -% git config core.gitproxy '"ssh" for kernel.org' 'for kernel.org$' +% git config set --value='for kernel.org$' core.gitproxy '"ssh" for kernel.org' ------------ This makes sure that only the key/value pair for kernel.org is replaced. @@ -529,26 +539,26 @@ If you like to live dangerously, you can replace *all* core.gitproxy by a new one with ------------ -% git config --replace-all core.gitproxy ssh +% git config set --all core.gitproxy ssh ------------ However, if you really only want to replace the line for the default proxy, i.e. the one without a "for ..." postfix, do something like this: ------------ -% git config core.gitproxy ssh '! for ' +% git config set --value='! for ' core.gitproxy ssh ------------ To actually match only values with an exclamation mark, you have to ------------ -% git config section.key value '[!]' +% git config set --value='[!]' section.key value ------------ To add a new proxy, without altering any of the existing ones, use ------------ -% git config --add core.gitproxy '"proxy-command" for example.com' +% git config set --append core.gitproxy '"proxy-command" for example.com' ------------ An example to use customized color from the configuration in your diff --git a/builtin/config.c b/builtin/config.c index 447500dbd2..eec57fbd17 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -18,6 +18,7 @@ static const char *const builtin_config_usage[] = { N_("git config list [] [] [--includes]"), N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), + N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), NULL }; @@ -31,6 +32,11 @@ static const char *const builtin_config_get_usage[] = { NULL }; +static const char *const builtin_config_set_usage[] = { + N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -847,9 +853,60 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) return get_value(argv[0], value_pattern, flags); } +static int cmd_config_set(int argc, const char **argv, const char *prefix) +{ + const char *value_pattern = NULL; + int flags = 0, append = 0; + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + CONFIG_TYPE_OPTIONS, + OPT_GROUP(N_("Filter")), + OPT_BIT(0, "all", &flags, N_("replace multi-valued config option with new value"), CONFIG_FLAGS_MULTI_REPLACE), + OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), + OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), + OPT_GROUP(N_("Other")), + OPT_BOOL(0, "append", &append, N_("add a new line without altering any existing values")), + OPT_END(), + }; + struct key_value_info default_kvi = KVI_INIT; + char *value; + int ret; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_set_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 2, 2); + + if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) + die(_("--fixed-value only applies with --value=")); + if (append && value_pattern) + die(_("--append cannot be used with --value=")); + if (append) + value_pattern = CONFIG_REGEX_NONE; + + handle_config_location(prefix); + + value = normalize_value(argv[0], argv[1], &default_kvi); + + if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) { + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], value, value_pattern, + flags); + } else { + ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value); + if (ret == CONFIG_NOTHING_SET) + error(_("cannot overwrite multiple values with a single value\n" + " Use a regexp, --add or --replace-all to change %s."), argv[0]); + } + + free(value); + return ret; +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), + OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f1547921c6..f435b8f194 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -20,12 +20,16 @@ legacy) mode_get="" mode_get_all="--get-all" mode_get_regexp="--get-regexp" + mode_set="" + mode_replace_all="--replace-all" ;; subcommands) mode_prefix="" mode_get="get" mode_get_all="get --all" mode_get_regexp="get --regexp --all --show-names" + mode_set="set" + mode_replace_all="set --all" ;; *) BUG "unknown mode $mode";; @@ -40,7 +44,7 @@ cat > expect << EOF penguin = little blue EOF test_expect_success 'initial' ' - git config section.penguin "little blue" && + git config ${mode_set} section.penguin "little blue" && test_cmp expect .git/config ' @@ -50,7 +54,7 @@ cat > expect << EOF Movie = BadPhysics EOF test_expect_success 'mixed case' ' - git config Section.Movie BadPhysics && + git config ${mode_set} Section.Movie BadPhysics && test_cmp expect .git/config ' @@ -62,7 +66,7 @@ cat > expect << EOF WhatEver = Second EOF test_expect_success 'similar section' ' - git config Sections.WhatEver Second && + git config ${mode_set} Sections.WhatEver Second && test_cmp expect .git/config ' @@ -75,7 +79,7 @@ cat > expect << EOF WhatEver = Second EOF test_expect_success 'uppercase section' ' - git config SECTION.UPPERCASE true && + git config ${mode_set} SECTION.UPPERCASE true && test_cmp expect .git/config ' @@ -191,14 +195,14 @@ test_expect_success 'multiple unset is correct' ' cp .git/config2 .git/config test_expect_success '--replace-all missing value' ' - test_must_fail git config --replace-all beta.haha && + test_must_fail git config ${mode_replace_all} beta.haha && test_cmp .git/config2 .git/config ' rm .git/config2 test_expect_success '--replace-all' ' - git config --replace-all beta.haha gamma + git config ${mode_replace_all} beta.haha gamma ' cat > expect << EOF @@ -225,7 +229,7 @@ noIndent= sillyValue ; 'nother silly comment [nextSection] noNewline = ouch EOF test_expect_success 'really mean test' ' - git config beta.haha alpha && + git config ${mode_set} beta.haha alpha && test_cmp expect .git/config ' @@ -240,7 +244,7 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow EOF test_expect_success 'really really mean test' ' - git config nextsection.nonewline wow && + git config ${mode_set} nextsection.nonewline wow && test_cmp expect .git/config ' @@ -714,16 +718,16 @@ EOF test_expect_success 'section ending' ' rm -f .git/config && - git config gitcvs.enabled true && - git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && - git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && + git config ${mode_set} gitcvs.enabled true && + git config ${mode_set} gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && + git config ${mode_set} gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && test_cmp expect .git/config ' test_expect_success numbers ' - git config kilo.gram 1k && - git config mega.ton 1m && + git config ${mode_set} kilo.gram 1k && + git config ${mode_set} mega.ton 1m && echo 1024 >expect && echo 1048576 >>expect && git config --int --get kilo.gram >actual && @@ -732,20 +736,20 @@ test_expect_success numbers ' ' test_expect_success '--int is at least 64 bits' ' - git config giga.watts 121g && + git config ${mode_set} giga.watts 121g && echo >expect && test_cmp_config 129922760704 --int --get giga.watts ' test_expect_success 'invalid unit' ' - git config aninvalid.unit "1auto" && + git config ${mode_set} aninvalid.unit "1auto" && test_cmp_config 1auto aninvalid.unit && test_must_fail git config --int --get aninvalid.unit 2>actual && test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual ' test_expect_success 'invalid unit boolean' ' - git config commit.gpgsign "1true" && + git config ${mode_set} commit.gpgsign "1true" && test_cmp_config 1true commit.gpgsign && test_must_fail git config --bool --get commit.gpgsign 2>actual && test_grep "bad boolean config value .1true. for .commit.gpgsign." actual @@ -775,14 +779,14 @@ EOF test_expect_success bool ' - git config bool.true1 01 && - git config bool.true2 -1 && - git config bool.true3 YeS && - git config bool.true4 true && - git config bool.false1 000 && - git config bool.false2 "" && - git config bool.false3 nO && - git config bool.false4 FALSE && + git config ${mode_set} bool.true1 01 && + git config ${mode_set} bool.true2 -1 && + git config ${mode_set} bool.true3 YeS && + git config ${mode_set} bool.true4 true && + git config ${mode_set} bool.false1 000 && + git config ${mode_set} bool.false2 "" && + git config ${mode_set} bool.false3 nO && + git config ${mode_set} bool.false4 FALSE && rm -f result && for i in 1 2 3 4 do @@ -793,7 +797,7 @@ test_expect_success bool ' test_expect_success 'invalid bool (--get)' ' - git config bool.nobool foobar && + git config ${mode_set} bool.nobool foobar && test_must_fail git config --bool --get bool.nobool' test_expect_success 'invalid bool (set)' ' @@ -982,7 +986,7 @@ test_expect_success 'get --expiry-date' ' test_expect_success 'get --type=color' ' rm .git/config && - git config foo.color "red" && + git config ${mode_set} foo.color "red" && git config --get --type=color foo.color >actual.raw && test_decode_color actual && echo "" >expect && @@ -1019,10 +1023,10 @@ cat > expect << EOF EOF test_expect_success 'quoting' ' rm -f .git/config && - git config quote.leading " test" && - git config quote.ending "test " && - git config quote.semicolon "test;test" && - git config quote.hash "test#test" && + git config ${mode_set} quote.leading " test" && + git config ${mode_set} quote.ending "test " && + git config ${mode_set} quote.semicolon "test;test" && + git config ${mode_set} quote.hash "test#test" && test_cmp expect .git/config ' @@ -1030,7 +1034,7 @@ test_expect_success 'key with newline' ' test_must_fail git config ${mode_get} "key.with newline" 123' -test_expect_success 'value with newline' 'git config key.sub value.with\\\ +test_expect_success 'value with newline' 'git config ${mode_set} key.sub value.with\\\ newline' cat > .git/config <<\EOF @@ -1088,7 +1092,7 @@ test_expect_success '--null --get-regexp' ' ' test_expect_success 'inner whitespace kept verbatim' ' - git config section.val "foo bar" && + git config ${mode_set} section.val "foo bar" && test_cmp_config "foo bar" section.val ' @@ -1126,12 +1130,12 @@ test_expect_success 'check split_cmdline return' ' git init repo && ( cd repo && - git config alias.split-cmdline-fix "echo \"" && + git config ${mode_set} alias.split-cmdline-fix "echo \"" && test_must_fail git split-cmdline-fix && echo foo >foo && git add foo && git commit -m "initial commit" && - git config branch.main.mergeoptions "echo \"" && + git config ${mode_set} branch.main.mergeoptions "echo \"" && test_must_fail git merge main ) ' @@ -1169,12 +1173,12 @@ test_expect_success 'key sanity-checking' ' test_must_fail git config ${mode_get} foo.1bar && test_must_fail git config ${mode_get} foo."ba z".bar && - test_must_fail git config . false && - test_must_fail git config .foo false && - test_must_fail git config foo. false && - test_must_fail git config .foo. false && - git config foo.bar true && - git config foo."ba =z".bar false + test_must_fail git config ${mode_set} . false && + test_must_fail git config ${mode_set} .foo false && + test_must_fail git config ${mode_set} foo. false && + test_must_fail git config ${mode_set} .foo. false && + git config ${mode_set} foo.bar true && + git config ${mode_set} foo."ba =z".bar false ' test_expect_success 'git -c works with aliases of builtins' ' @@ -2397,7 +2401,7 @@ test_expect_success '--replace-all does not invent newlines' ' [abc] Qkey = b EOF - git config --replace-all abc.key b && + git config ${mode_replace_all} abc.key b && test_cmp expect .git/config ' @@ -2469,8 +2473,8 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && # These modes complain when --fixed-value has no value-pattern - test_must_fail git config --file=config --fixed-value dev.null bogus && - test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && + test_must_fail git config ${mode_set} --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_replace_all} --file=config --fixed-value dev.null bogus && test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null && test_must_fail git config ${mode_get_all} --file=config --fixed-value dev.null && test_must_fail git config ${mode_get_regexp} --file=config --fixed-value "dev.*" && @@ -2511,7 +2515,7 @@ test_expect_success '--fixed-value uses exact string matching' ' test_must_fail git config ${mode_get} --file=config fixed.test && cp initial config && - git config --file=config --replace-all fixed.test bogus "$META" && + git config --file=config fixed.test bogus "$META" && git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=$META From patchwork Wed Mar 27 08:46:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605957 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 3C0071E869 for ; Wed, 27 Mar 2024 08:46:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529213; cv=none; b=lEUGY406NsztZYC8hAqLfOvgpyGkO0Vv9cE32kNNUA0ekWT6djv4VSLY3I1N7Lo+DfxDsgnvmC2ldrrzgAo18XzPlUb/M8HZgrX9oadBWuF/e/XIAQG0pj84v7GI2P1s14XRWz9/MXuy1LcjU7gfhZJjUTMWNeAu2bLUrKujJ6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529213; c=relaxed/simple; bh=s8F6yFuoIxBrmUcu3PYJNR/fLqP9IuqXKG/m2SOAJVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VjMTA5u08XFzUjIg6GddkLmqgkPm2U4cK9uklZfEHpjSHWZIzbJhcWN7Dr21vm4pQfxZCc2+DAsKRE8dQ52fHyrIfPPnLuXk2Am9PIHoJPaa2TcEMjRnjkVbKqC9oMOqf0IDLQZgQTC/6ld+u6mnIPntq28t5ceOL5oUlC51MP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=gLdcc3Ps; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TsMyuwR2; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="gLdcc3Ps"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TsMyuwR2" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 5759B138015E; Wed, 27 Mar 2024 04:46:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 27 Mar 2024 04:46:50 -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=fm2; t=1711529210; x=1711615610; bh=9tq7zqU4dr EYmiQokqR9Sm3A7sqwiigTEcYDUbLbeGg=; b=gLdcc3PsNc0yFKxS42N9YOMjqI FZV1QPIbP48LkzSS/tKrrUNNG1OU3zcEBSUqd8FHDqKKWlCVY+R3EB2Qr/IIKwyj BYIXM6mUDsv2dL5+1mhjMiZPJRQWTn53UbS1cuFp+5WRC3KGiLO3COStQ0+nV8J4 53BDkHovse5CrBRqukr3jmmNMWfSXkAuMpLr1IP8rzVi5rkZUrPPXczvyQEDxV6b sK2FIqwwttZKz8cM0vC5IRzIPXUHa5EYwjjy+U+n3kbIdi7RAc/ZnQEm9Rpq8K9O bv5XoMr4Q54/NTQiFuvaoaetzHebO2FANuxix+98sQaZQlcNtA4VuTVNj5vA== 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= fm2; t=1711529210; x=1711615610; bh=9tq7zqU4drEYmiQokqR9Sm3A7sqw iigTEcYDUbLbeGg=; b=TsMyuwR2q/9NlXf5dsBNpS9zSIgTAKHBdbr+8pJ6PE2k izcJ1k7xN4eUBRQfwUmWcS87OQbcDxvCrX5rguLRuXFNY1dt6/ao0S2DDefunWel FWrE6tpBLEuvwW0HWmgSjvLpRNpIM+/Pzc4qUhyK9/OmdDI6TdhXEiCK+LDqmFag llb/dPQtk+xlvSua2KLrBS7vEoRO3DuTQP8IgruAPVIRaqTHcU2jueDsMX7aG7Uy KoCA0bq4VY4E3SMSLZSdzuNwR+ltIwX9s/FMJ7UsaS52+7MNRih0ZCINweUop0mI G8ZmKrxQUAXgJ6F1thoOO+8rZ8tesWvT91gQhnr+eA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeiveektdfggfeluefgvdelvdeftdfhgeeugeefveejleeufeekgeefffehgfel gfenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9c381e8f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:35 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:47 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 09/13] builtin/config: introduce "unset" subcommand Message-ID: <90f055ae1d9e735560b66dc9aac534fafaf27c23.1711527812.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: Introduce a new "unset" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 25 ++++++++++++-------- builtin/config.c | 38 +++++++++++++++++++++++++++++++ t/t1300-config.sh | 44 ++++++++++++++++++++++++------------ 3 files changed, 82 insertions(+), 25 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 7fdf9b434e..4fbc73a19e 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -12,8 +12,7 @@ SYNOPSIS 'git config list' [] [] [--includes] 'git config get' [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] 'git config set' [] [--type=] [--all] [--value=] [--fixed-value] -'git config' [] [--fixed-value] --unset [] -'git config' [] [--fixed-value] --unset-all [] +'git config unset' [] [--all] [--value=] [--fixed-value] 'git config' [] --rename-section 'git config' [] --remove-section 'git config' [] --get-colorbool [] @@ -87,6 +86,12 @@ set:: `--value=` will replace all config options whose values match the given pattern. +unset:: + Unset value for one or more config options. By default, this command + refuses to unset multi-valued keys. Passing `--all` will unset all + multi-valued config options, whereas `--value` will unset all config + options whose values match the given pattern. + [[OPTIONS]] OPTIONS ------- @@ -178,12 +183,6 @@ See also <>. --rename-section:: Rename the given section to a new name. ---unset:: - Remove the line matching the key from config file. - ---unset-all:: - Remove all lines matching the key from config file. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -313,6 +312,12 @@ recommended to migrate to the new syntax. --add :: Replaced by `git config set --append `. +--unset []:: + Replaced by `git config unset [--value=] `. + +--unset-all []:: + Replaced by `git config unset [--value=] --all `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when @@ -360,7 +365,7 @@ values of a key from all files will be used. By default, options are only written to the repository specific configuration file. Note that this also affects options like `set` -and `--unset`. *'git config' will only ever change one file at a time*. +and `unset`. *'git config' will only ever change one file at a time*. You can limit which configuration sources are read from or written to by specifying the path of a file with the `--file` option, or by specifying a @@ -511,7 +516,7 @@ This makes sure that only the key/value pair for kernel.org is replaced. To delete the entry for renames, do ------------ -% git config --unset diff.renames +% git config unset diff.renames ------------ If you want to delete an entry for a multivar (like core.gitproxy above), diff --git a/builtin/config.c b/builtin/config.c index eec57fbd17..c53b68887e 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -19,6 +19,7 @@ static const char *const builtin_config_usage[] = { N_("git config list [] [] [--includes]"), N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), + N_("git config unset [] [--all] [--value=] [--fixed-value] "), NULL }; @@ -37,6 +38,11 @@ static const char *const builtin_config_set_usage[] = { NULL }; +static const char *const builtin_config_unset_usage[] = { + N_("git config unset [] [--all] [--value=] [--fixed-value] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -903,10 +909,42 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) return ret; } +static int cmd_config_unset(int argc, const char **argv, const char *prefix) +{ + const char *value_pattern = NULL; + int flags = 0; + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_GROUP(N_("Filter")), + OPT_BIT(0, "all", &flags, N_("replace multi-valued config option with new value"), CONFIG_FLAGS_MULTI_REPLACE), + OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), + OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), + OPT_END(), + }; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_unset_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 1, 1); + + if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) + die(_("--fixed-value only applies with 'value-pattern'")); + + handle_config_location(prefix); + + if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) + return git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, value_pattern, + flags); + else + return git_config_set_in_file_gently(given_config_source.file, argv[0], NULL); +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), + OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f435b8f194..c9610a1f5b 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -22,6 +22,8 @@ legacy) mode_get_regexp="--get-regexp" mode_set="" mode_replace_all="--replace-all" + mode_unset="--unset" + mode_unset_all="--unset-all" ;; subcommands) mode_prefix="" @@ -30,6 +32,8 @@ subcommands) mode_get_regexp="get --regexp --all --show-names" mode_set="set" mode_replace_all="set --all" + mode_unset="unset" + mode_unset_all="unset --all" ;; *) BUG "unknown mode $mode";; @@ -149,7 +153,7 @@ foo = bar EOF test_expect_success 'unset with cont. lines' ' - git config --unset beta.baz + git config ${mode_unset} beta.baz ' cat > expect <<\EOF @@ -176,7 +180,7 @@ EOF cp .git/config .git/config2 test_expect_success 'multiple unset' ' - git config --unset-all beta.haha + git config ${mode_unset_all} beta.haha ' cat > expect << EOF @@ -262,7 +266,7 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow EOF test_expect_success 'unset' ' - git config --unset beta.haha && + git config ${mode_unset} beta.haha && test_cmp expect .git/config ' @@ -318,11 +322,11 @@ test_expect_success 'multivar replace' ' ' test_expect_success 'ambiguous unset' ' - test_must_fail git config --unset nextsection.nonewline + test_must_fail git config ${mode_unset} nextsection.nonewline ' test_expect_success 'invalid unset' ' - test_must_fail git config --unset somesection.nonewline + test_must_fail git config ${mode_unset} somesection.nonewline ' cat > expect << EOF @@ -336,7 +340,12 @@ noIndent= sillyValue ; 'nother silly comment EOF test_expect_success 'multivar unset' ' - git config --unset nextsection.nonewline "wow3$" && + case "$mode" in + legacy) + git config --unset nextsection.nonewline "wow3$";; + subcommands) + git config unset --value="wow3$" nextsection.nonewline;; + esac && test_cmp expect .git/config ' @@ -1887,7 +1896,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' # please be careful when you update the above variable EOF - git config --unset section.key && + git config ${mode_unset} section.key && test_cmp expect .git/config && cat >.git/config <<-\EOF && @@ -1900,7 +1909,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [next-section] EOF - git config --unset section.key && + git config ${mode_unset} section.key && test_cmp expect .git/config && q_to_tab >.git/config <<-\EOF && @@ -1910,7 +1919,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [two] key = true EOF - git config --unset two.key && + git config ${mode_unset} two.key && ! grep two .git/config && q_to_tab >.git/config <<-\EOF && @@ -1920,7 +1929,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [one] key = true EOF - git config --unset-all one.key && + git config ${mode_unset_all} one.key && test_line_count = 0 .git/config && q_to_tab >.git/config <<-\EOF && @@ -1930,7 +1939,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [two] Qkey = true EOF - git config --unset two.key && + git config ${mode_unset} two.key && grep two .git/config && q_to_tab >.git/config <<-\EOF && @@ -1942,7 +1951,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [TWO "subsection"] [one] EOF - git config --unset two.subsection.key && + git config ${mode_unset} two.subsection.key && test "not [two subsection]" = "$(git config ${mode_get} one.key)" && test_line_count = 3 .git/config ' @@ -1954,7 +1963,7 @@ test_expect_success '--unset-all removes section if empty & uncommented' ' key = value2 EOF - git config --unset-all section.key && + git config ${mode_unset_all} section.key && test_line_count = 0 .git/config ' @@ -2478,8 +2487,8 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null && test_must_fail git config ${mode_get_all} --file=config --fixed-value dev.null && test_must_fail git config ${mode_get_regexp} --file=config --fixed-value "dev.*" && - test_must_fail git config --file=config --fixed-value --unset dev.null && - test_must_fail git config --file=config --fixed-value --unset-all dev.null + test_must_fail git config ${mode_unset} --file=config --fixed-value dev.null && + test_must_fail git config ${mode_unset_all} --file=config --fixed-value dev.null ' test_expect_success '--fixed-value uses exact string matching' ' @@ -2509,6 +2518,11 @@ test_expect_success '--fixed-value uses exact string matching' ' git config --file=config --fixed-value --unset fixed.test "$META" && test_must_fail git config ${mode_get} --file=config fixed.test && + cp initial config && + test_must_fail git config unset --file=config --value="$META" fixed.test && + git config unset --file=config --fixed-value --value="$META" fixed.test && + test_must_fail git config ${mode_get} --file=config fixed.test && + cp initial config && test_must_fail git config --file=config --unset-all fixed.test "$META" && git config --file=config --fixed-value --unset-all fixed.test "$META" && From patchwork Wed Mar 27 08:46:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605958 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 E60671E869 for ; Wed, 27 Mar 2024 08:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529217; cv=none; b=VMP5IiL8qwWBviyft8OVRd6MoBmyAkfYvopPqKM4lCNAec7/xSbp1eAUxaHMlVT94uT/xag8c7/U1fkuZf0d5NWEHiPMtTMjt6LHVrQDJN8lTUMZMPsokORcO84b1WyGfOKcU/ZFwaSRx1bvZ2nDtznIgGfj0OSl6xO/pKG89J0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529217; c=relaxed/simple; bh=Pn3cjL/fHExJa2XZDRCqYm6LqCZBITD6FL+h+avHmig=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OwNN8fjRBSiDDZzBxB3OAUSvdpXkpjd0EST9hhjWL8BFMJNQMhsC9PDJoUroNRIS1g1qQOunSDzBVEAHor+lfXB6ZO1RmwVums0HKoXtMmkEv+7VDlcwGu555BKabO+s134JPcdpLfZf1PCA2LOGI7dTlGnttaAsOp/wXedjjHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=KGJyzwIa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bWbvWj2m; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="KGJyzwIa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bWbvWj2m" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id F0DBB138015F; Wed, 27 Mar 2024 04:46:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 04:46:54 -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=fm2; t=1711529214; x=1711615614; bh=JmOtyj9GKM dPQf3jgL3fNBI9u8HjlJb4gaDQwYp11Co=; b=KGJyzwIa+OqP0okxGkiMtxEqog 79MsuKpA8WemKXBntExxymZxAS5Ah5FASmv1B0vP0pJt24Sxa3SF0/Mpv+BVMOdV oiGeQv1MBQ2H7lQLlncPWtpLZuknjtrHxYFt39vr+PMgn0UGx8w85LNiviSLmaHX 1BXxGdrzive9puix5wMgW+KuC6JgPdQ2ocGcSVHrsls2T+8HmR8sEbNOlaSAtVj7 2/0pUcRZGAZXhd1OT0Qcg9BDS50lr36oxl8hvBmZN1D7HuPO151RjK9upbi2X4qc BXKpJ5djyBpxozj4jNvm00VziKlx5Zf2CdZIaTVHyQyTENZ4JoQGBzNLEUVg== 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= fm2; t=1711529214; x=1711615614; bh=JmOtyj9GKMdPQf3jgL3fNBI9u8Hj lJb4gaDQwYp11Co=; b=bWbvWj2mPhI+Xog7IejNszv80B+FtxpL8MrP6Z4VOU4C VjJSjoJsjsqYqOqYWT96B3Jq8oExxWtyxMFzTrNIx4yT2zeNPUnAfpdq5dWoQix/ 5kuUuHJYLU/A33DoM882zC89Zerf6z4bPhE3BvfxwJ7pwwf/I7DjoVSni0QrmGVd irwJ1k7GLatoPyEnFP0H5GW93kdaUY8/c9/bmHOsYzQOt/n0LCqVL1B+ZVh+xZNs pL1m2G0fKbVEf3rVLfhW2kv1iNWDXBEwC6vz5V01Vj3tWjoNtXoCjEJTMcRCGwrs NFaezpjdmj/voX+eQ1HvfF1V/7Y9SWZqeZ6p0wXr4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e3f36a74 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:39 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:51 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 10/13] builtin/config: introduce "rename-section" subcommand Message-ID: <3e360b1f47864ebe738889fd46ea414829f8daf4.1711527812.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: Introduce a new "rename-section" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 11 +++++++---- builtin/config.c | 32 ++++++++++++++++++++++++++++++++ t/t1300-config.sh | 22 +++++++++++----------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 4fbc73a19e..0695eeae22 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -13,7 +13,7 @@ SYNOPSIS 'git config get' [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] 'git config set' [] [--type=] [--all] [--value=] [--fixed-value] 'git config unset' [] [--all] [--value=] [--fixed-value] -'git config' [] --rename-section +'git config rename-section' [] 'git config' [] --remove-section 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -92,6 +92,9 @@ unset:: multi-valued config options, whereas `--value` will unset all config options whose values match the given pattern. +rename-section:: + Rename the given section to a new name. + [[OPTIONS]] OPTIONS ------- @@ -180,9 +183,6 @@ See also <>. --remove-section:: Remove the given section from the configuration file. ---rename-section:: - Rename the given section to a new name. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -318,6 +318,9 @@ recommended to migrate to the new syntax. --unset-all []:: Replaced by `git config unset [--value=] --all `. +--rename-section :: + Replaced by `git config rename-section `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when diff --git a/builtin/config.c b/builtin/config.c index c53b68887e..99d9ac6341 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -20,6 +20,7 @@ static const char *const builtin_config_usage[] = { N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), N_("git config unset [] [--all] [--value=] [--fixed-value] "), + N_("git config rename-section [] "), NULL }; @@ -43,6 +44,11 @@ static const char *const builtin_config_unset_usage[] = { NULL }; +static const char *const builtin_config_rename_section_usage[] = { + N_("git config rename-section [] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -940,11 +946,37 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) return git_config_set_in_file_gently(given_config_source.file, argv[0], NULL); } +static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_rename_section_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 2, 2); + + handle_config_location(prefix); + + ret = git_config_rename_section_in_file(given_config_source.file, + argv[0], argv[1]); + if (ret < 0) + return ret; + else if (!ret) + die(_("no such section: %s"), argv[0]); + + return 0; +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), + OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index c9610a1f5b..4818c495bd 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -589,7 +589,7 @@ weird EOF test_expect_success 'rename section' ' - git config --rename-section branch.eins branch.zwei + git config ${mode_prefix}rename-section branch.eins branch.zwei ' cat > expect << EOF @@ -608,7 +608,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename non-existing section' ' - test_must_fail git config --rename-section \ + test_must_fail git config ${mode_prefix}rename-section \ branch."world domination" branch.drei ' @@ -617,7 +617,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename another section' ' - git config --rename-section branch."1 234 blabl/a" branch.drei + git config ${mode_prefix}rename-section branch."1 234 blabl/a" branch.drei ' cat > expect << EOF @@ -640,7 +640,7 @@ cat >> .git/config << EOF EOF test_expect_success 'rename a section with a var on the same line' ' - git config --rename-section branch.vier branch.zwei + git config ${mode_prefix}rename-section branch.vier branch.zwei ' cat > expect << EOF @@ -661,11 +661,11 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'renaming empty section name is rejected' ' - test_must_fail git config --rename-section branch.zwei "" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "" ' test_expect_success 'renaming to bogus section is rejected' ' - test_must_fail git config --rename-section branch.zwei "bogus name" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "bogus name" ' test_expect_success 'renaming a section with a long line' ' @@ -674,7 +674,7 @@ test_expect_success 'renaming a section with a long line' ' printf " c = d %1024s [a] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y b.e ' @@ -684,7 +684,7 @@ test_expect_success 'renaming an embedded section with a long line' ' printf " c = d %1024s [a] [foo] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y foo.e ' @@ -694,7 +694,7 @@ test_expect_success 'renaming a section with an overly-long line' ' printf " c = d %525000s e" " " && printf "[a] g = h\\n" } >y && - test_must_fail git config -f y --rename-section a xyz 2>err && + test_must_fail git config ${mode_prefix}rename-section -f y a xyz 2>err && grep "refusing to work with overly long line in .y. on line 2" err ' @@ -1986,7 +1986,7 @@ test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' git config imap.pass Hunter2 && perl -e \ "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && - git config --rename-section imap pop && + git config ${mode_prefix}rename-section imap pop && perl -e \ "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" ' @@ -2475,7 +2475,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --add dev.null bogus && test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && - test_must_fail git config --file=config --fixed-value --rename-section dev null && + test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null && test_must_fail git config --file=config --fixed-value --remove-section dev && test_must_fail git config ${mode_prefix}list --file=config --fixed-value && test_must_fail git config --file=config --fixed-value --get-color dev.null && From patchwork Wed Mar 27 08:46:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605959 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 6574F3839D for ; Wed, 27 Mar 2024 08:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529221; cv=none; b=LdIxUjZgP3WyCD2RVY+0oxgmg92i/rwbX0iSNLQdNgRddwpForWqRC5pnAgfM9hs7KUuk4eBqtFgKCeG1VKa+AKocHXyB7zn6HzZYnb46IkM7Yaf+zLgqxExddUYl5DZ/DA0Vm0HlLl8pW1gbTD1dRWjeQOkudDIpXPR7FHPUnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529221; c=relaxed/simple; bh=0hZh4HvmpRkVKPbPbUdpoomP+SSkcRTYh1icR6JxZXM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tuONsJgtfbKS7kwy3BHtZCh5Nun//v/NioomTbkKg7l+Usla75X2Fa52DGeGzZKbNyPwrImCWKa3JtWID094xREADaw3xoMgQDtKB4WEfKkUBdUUQ7Fb4K3nPUV5AfqegMXDZ2G4dNEag/bgdGXCevlVbcL3f5giUWvdmuQTJVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=iAuIRxza; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hclJrOm0; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="iAuIRxza"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hclJrOm0" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 7EC8F138015E; Wed, 27 Mar 2024 04:46:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 04:46:58 -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=fm2; t=1711529218; x=1711615618; bh=Fm5NvVRU2K UlKrHIrU3AIKavbMKok8AgdYtqodM2LpE=; b=iAuIRxza/35/5XVu0ZXX/RaRos ibIWFp3GWuaa48aOu55B9E6yScoPp3cLgsdJVnQQiiinUQzMlnDq3hPyigMdy2Nd ZteQeDEyAsU4azkv1TJPeFfQqKvhmnzAQQuf6x258YJdteGSGRkkYKGj6lPZjKFD qhnwDZJi4AlUxsA/F2lTZUfxq8uI8AdNVRO/oOWenJZinN/jyjKGOwAGInIPyzs7 WJk5yU2P35EHNTTXnw+1uCLnIglDUxHQJGV+mvqNgNPLpKlseTRXMs70PM6qSSQw ld3G+5yDI/4/WujtBpEAciL/FRbKb8HabW0BAMPDL6uGlvdVxtXowtTiPj0A== 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= fm2; t=1711529218; x=1711615618; bh=Fm5NvVRU2KUlKrHIrU3AIKavbMKo k8AgdYtqodM2LpE=; b=hclJrOm0uzgGawxN2RDh04TVM2HQeGyypszpNQb3aRsv wlL/WhthFWzVW1Ol5Id5gylovr0GLsexkuhz/gd11+LSvFA9qnIbtC9qp7EZ5jJI 7jPEAycG+Po1Ec9s67NzR54EsDijnP/FUU8tYJJkwF5ta+VfLVO7MFhUXhhgL+XL LlUsOCVzuPPx73u28+s3cTMTYgf7ppd5My7M1DfwMaNwrA0L24NeoOPVb9uc9I0L bGhvUUoVv2JpzFXwg/dTb223Tupc8kCjkc54QWPrNo8KPY2rWkERrRMbx4KLf4Vf DKCrREV6lsvzEvIcKdIbPMM3Nko7cp5n2Enshr+d9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 68c81058 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:43 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:55 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 11/13] builtin/config: introduce "remove-section" subcommand 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: Introduce a new "remove-section" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 11 +++++++---- builtin/config.c | 32 ++++++++++++++++++++++++++++++++ t/t1300-config.sh | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 0695eeae22..b9ca5e83a2 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -14,7 +14,7 @@ SYNOPSIS 'git config set' [] [--type=] [--all] [--value=] [--fixed-value] 'git config unset' [] [--all] [--value=] [--fixed-value] 'git config rename-section' [] -'git config' [] --remove-section +'git config remove-section' [] 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -95,6 +95,9 @@ unset:: rename-section:: Rename the given section to a new name. +remove-section:: + Remove the given section from the configuration file. + [[OPTIONS]] OPTIONS ------- @@ -180,9 +183,6 @@ See also <>. section in linkgit:gitrevisions[7] for a more complete list of ways to spell blob names. ---remove-section:: - Remove the given section from the configuration file. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -321,6 +321,9 @@ recommended to migrate to the new syntax. --rename-section :: Replaced by `git config rename-section `. +--remove-section :: + Replaced by `git config remove-section `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when diff --git a/builtin/config.c b/builtin/config.c index 99d9ac6341..6be6717f26 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -21,6 +21,7 @@ static const char *const builtin_config_usage[] = { N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), N_("git config unset [] [--all] [--value=] [--fixed-value] "), N_("git config rename-section [] "), + N_("git config remove-section [] "), NULL }; @@ -49,6 +50,11 @@ static const char *const builtin_config_rename_section_usage[] = { NULL }; +static const char *const builtin_config_remove_section_usage[] = { + N_("git config remove-section [] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -971,12 +977,38 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr return 0; } +static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_remove_section_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 1, 1); + + handle_config_location(prefix); + + ret = git_config_rename_section_in_file(given_config_source.file, + argv[0], NULL); + if (ret < 0) + return ret; + else if (!ret) + die(_("no such section: %s"), argv[0]); + + return 0; +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), + OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 4818c495bd..2f8d0310b1 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -703,7 +703,7 @@ cat >> .git/config << EOF EOF test_expect_success 'remove section' ' - git config --remove-section branch.zwei + git config ${mode_prefix}remove-section branch.zwei ' cat > expect << EOF @@ -2476,7 +2476,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null && - test_must_fail git config --file=config --fixed-value --remove-section dev && + test_must_fail git config ${mode_prefix}remove-section --file=config --fixed-value dev && test_must_fail git config ${mode_prefix}list --file=config --fixed-value && test_must_fail git config --file=config --fixed-value --get-color dev.null && test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && From patchwork Wed Mar 27 08:46:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605966 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 063703839C for ; Wed, 27 Mar 2024 08:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529225; cv=none; b=cRKPemntFcF2+3BNeipXEDLOBXP//l1eqhFfgsVoAB5qwuakTPw3Rlvd/JMwIgWGaNxsry6IEP648HtAeh0P+z9Xm3jd3orZqg0/N51CVpbD3YkYlWxihRWgcKHZvxuK/QLBGJk/Ijpq2sjklNAqv5x4vZR1H2TvjB8J51knqag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529225; c=relaxed/simple; bh=UNYCq6IXcT0ESv7z6eQuYg/k2lJUtYrvJIXTshb7CAE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z/g7KRukuQh5GLaFwR2FNDKjcD9Hdl8s5YD73dFrZrCn3JY5Dbm+jdgbUQLqaWZ5aQZuTSamUDHyx/+UPArmNvoH3UYJEokZdWp8SUHtcraVhO3rBtTe6ta5S48/hX57kAofrczMCjypmNWROy0+jz3eZxVvU8hJuJPOI443YX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=EFNhScQp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=L/6v1pUJ; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="EFNhScQp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="L/6v1pUJ" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 241F7138015E; Wed, 27 Mar 2024 04:47:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 27 Mar 2024 04:47:03 -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=fm2; t=1711529223; x=1711615623; bh=k1WQmxZsY7 3p584j7ogy3ZQtIE7I8mqNcTvR72mO4PI=; b=EFNhScQpnb404eoKxQkvNzxYq8 yXGcGI8qqT5rr17KrmaR/pUfSy2iCqNaSnp9b5HEt3Imvf4MsU2J3L8OGNXpIVYi 8qcOji5/qJ+tHpXbuiUt8NErUBB5EgpiDliZ5YS3//VmfgpS2M9okA200VQ7eOm2 OCGFqJSJMwbZUk+64vpRd5fBa98ldtN7cv52LowY/qA3krsE78fQwRNeO6zUm9dM sE1Yqn+a/IMI4BMF5SCjyaEJkA2MEXnrXC3K9dmG8hX4zl1KR2JCDD3Owp3pqkkG 3U7gUM9Y5+sOyOyj/n7IMlMb3cv2Wr9h1CXXbQaPNazDDe+2Q8c/n0LBdTHA== 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= fm2; t=1711529223; x=1711615623; bh=k1WQmxZsY73p584j7ogy3ZQtIE7I 8mqNcTvR72mO4PI=; b=L/6v1pUJE2NcExAVp4UaMcMld9avd/eqJ3C3mBCuinyY XyMB74mhyVGBHqm/fszyrhygdICZf2GJ7AHGNFaBhURAXWbmndyXFnOasKY00U6T Y9flBun2UOfaS9rZ8dnryrymMAacei17PJ2fqMqmyqnlFqej4mDJF5/7U5skqXCz 35cMFu8NJ9ibekYYHPQoKJjFMtF4btKX8vHo1MggE/CLhbA9KcGy3R8KRqHq8TWO W5yr2Q+WhplxbFREzh8uO4pz1mNVifUrIYwSGoXdpmUg8RCN+75LCMPOlBCooacF oePMXOp5YH93AFjXGmRx63gFGhtyDX9KR3D4kvTkuA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:47:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 28ea266c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:47 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:59 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 12/13] builtin/config: introduce "edit" subcommand Message-ID: <4a6512c88af82013b8a08767515f5715af05c6bb.1711527812.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: Introduce a new "edit" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 17 ++++---- builtin/config.c | 81 ++++++++++++++++++++++++------------ t/t1300-config.sh | 6 +-- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index b9ca5e83a2..448bf43bb3 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -15,8 +15,8 @@ SYNOPSIS 'git config unset' [] [--all] [--value=] [--fixed-value] 'git config rename-section' [] 'git config remove-section' [] +'git config edit' [] 'git config' [] --get-colorbool [] -'git config' [] -e | --edit DESCRIPTION ----------- @@ -98,6 +98,11 @@ rename-section:: remove-section:: Remove the given section from the configuration file. +edit:: + Opens an editor to modify the specified config file; either + `--system`, `--global`, `--local` (default), `--worktree`, or + `--file `. + [[OPTIONS]] OPTIONS ------- @@ -262,12 +267,6 @@ Valid ``'s include: When the color setting for `name` is undefined, the command uses `color.ui` as fallback. --e:: ---edit:: - Opens an editor to modify the specified config file; either - `--system`, `--global`, `--local` (default), `--worktree`, or - `--file `. - --[no-]includes:: Respect `include.*` directives in config files when looking up values. Defaults to `off` when a specific file is given (e.g., @@ -324,6 +323,10 @@ recommended to migrate to the new syntax. --remove-section :: Replaced by `git config remove-section `. +-e:: +--edit:: + Replaced by `git config edit`. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when diff --git a/builtin/config.c b/builtin/config.c index 6be6717f26..b8cb940b1e 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -22,6 +22,7 @@ static const char *const builtin_config_usage[] = { N_("git config unset [] [--all] [--value=] [--fixed-value] "), N_("git config rename-section [] "), N_("git config remove-section [] "), + N_("git config edit []"), NULL }; @@ -55,6 +56,11 @@ static const char *const builtin_config_remove_section_usage[] = { NULL }; +static const char *const builtin_config_edit_usage[] = { + N_("git config edit []"), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -1002,6 +1008,53 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr return 0; } +static int show_editor(void) +{ + char *config_file; + + if (!given_config_source.file && !startup_info->have_repository) + die(_("not in a git directory")); + if (given_config_source.use_stdin) + die(_("editing stdin is not supported")); + if (given_config_source.blob) + die(_("editing blobs is not supported")); + git_config(git_default_config, NULL); + config_file = given_config_source.file ? + xstrdup(given_config_source.file) : + git_pathdup("config"); + if (use_global_config) { + int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd >= 0) { + char *content = default_user_config(); + write_str_in_full(fd, content); + free(content); + close(fd); + } + else if (errno != EEXIST) + die_errno(_("cannot create configuration file %s"), config_file); + } + launch_editor(config_file, NULL, NULL); + free(config_file); + + return 0; +} + +static int cmd_config_edit(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_END(), + }; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_edit_usage, 0); + check_write(); + check_argc(argc, 0, 0); + + handle_config_location(prefix); + + return show_editor(); +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), @@ -1009,6 +1062,7 @@ static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), + OPT_SUBCOMMAND("edit", &subcommand, cmd_config_edit), OPT_END(), }; @@ -1127,32 +1181,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) } } else if (actions == ACTION_EDIT) { - char *config_file; - - check_argc(argc, 0, 0); - if (!given_config_source.file && !startup_info->have_repository) - die(_("not in a git directory")); - if (given_config_source.use_stdin) - die(_("editing stdin is not supported")); - if (given_config_source.blob) - die(_("editing blobs is not supported")); - git_config(git_default_config, NULL); - config_file = given_config_source.file ? - xstrdup(given_config_source.file) : - git_pathdup("config"); - if (use_global_config) { - int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); - if (fd >= 0) { - char *content = default_user_config(); - write_str_in_full(fd, content); - free(content); - close(fd); - } - else if (errno != EEXIST) - die_errno(_("cannot create configuration file %s"), config_file); - } - launch_editor(config_file, NULL, NULL); - free(config_file); + ret = show_editor(); } else if (actions == ACTION_SET) { check_write(); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 2f8d0310b1..3049b61533 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -556,7 +556,7 @@ test_expect_success 'setting a value in stdin is an error' ' ' test_expect_success 'editing stdin is an error' ' - test_must_fail git config --file - --edit + test_must_fail git config ${mode_prefix}edit --file - ' test_expect_success 'refer config from subdirectory' ' @@ -1642,7 +1642,7 @@ test_expect_success 'command line overrides environment config' ' test_expect_success 'git config --edit works' ' git config -f tmp test.value no && echo test.value=yes >expect && - GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit && + GIT_EDITOR="echo [test]value=yes >" git config ${mode_prefix}edit -f tmp && git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' @@ -1651,7 +1651,7 @@ test_expect_success 'git config --edit respects core.editor' ' git config -f tmp test.value no && echo test.value=yes >expect && test_config core.editor "echo [test]value=yes >" && - git config -f tmp --edit && + git config ${mode_prefix}edit -f tmp && git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' From patchwork Wed Mar 27 08:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605967 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 90FE536139 for ; Wed, 27 Mar 2024 08:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529229; cv=none; b=IUzhVawKOGzAHNeEYAGmaENRWozSflhAMV8+Zwv0Ao6cnHeTSGF1kq0QlC3DQBek9ZqhZQOqiCFk3a4bG5K18OFaA/dFrNkxA2CQNY2akhTNhYOjM+PSkUPMMflGIq+RPUa7FCboZvDFVa2j/CXwZHQ5LJquA5nwq/juGTztWkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529229; c=relaxed/simple; bh=LU0uu5/voFOFQ/1LLQK2T/RhNNr6j2ZhN1x3lbkmTTQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X3CQVATpRVryZ/XzhInOKymCqJzCRrmLhh/rplX4FwAnSYJX1xK73aUjVN2r2JNfMjZnLqxVvYWNpea4opgkx6w84DjLSIYyXPZ/uYZgmCuTbmpPaxwf6YjJgeEFT2HvD96S/qCvTY2A7T0Kle6JOjIer8RfzlfBmbNrEht+ErQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=KP9uR0Ol; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sEZ1E6vD; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="KP9uR0Ol"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sEZ1E6vD" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id B9C74138015E; Wed, 27 Mar 2024 04:47:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 27 Mar 2024 04:47:06 -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=fm2; t=1711529226; x=1711615626; bh=UPE/s/ysUt gvuixHiyTXOeWSosJNsQ+lvFIcNXYp030=; b=KP9uR0OlFjp39QNVzh6zoxNylE wxnivzcw2fKjhtCsXGDJ3gTDkA4Ul6qbfUcyX22DUlokapk4XCG6frboUPewdVbc /QEIscFxUnev/u78Y7o5WqgYJ1KIzUYMhkiEAReM5ipYvG2YagC2X0fhpPHN3gCt c/uenAOu68DO8gxJEvLzVi5hYnzzMVuOsqs8yESzfaSrX5bbcXVMBZ9tvLIrf9o0 dMfU5tsc2YRk0bhwDi4TPoUau9LPXw+gml6i+45irTS+/lFnPn9WkjtHsS75UfOI 8j1j1hssjDCn/C1ktnnaNbGlvRGV+hX7EPhTapg73/hmEHr3NwaOI2HCtUSg== 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= fm2; t=1711529226; x=1711615626; bh=UPE/s/ysUtgvuixHiyTXOeWSosJN sQ+lvFIcNXYp030=; b=sEZ1E6vDC36scqffdH4TKUGDccett0pYp2gMSS6yplZL OtsVNHv/iV+vQPdR2nZuDYx+keta3sVM14bYS0ygxhIJY2liCC0+qENS9zqJ/tGD YxvQBEQzumGSYewUBdUTI/fdU5B1UpTcRD6/YfzGOVIcB6hlfpyrL/l9aJXN8Ehg 9mIRRgwb1ZXN5QEih8KCrGwCCz75CSaivo6xom4fpEM3InHLYjzizCZGu86959zv HB/X0B8ytbd76zASeFCDtGS9YH3IKtw+lwm5c47/AOY8GnXKx+fwV1rNJra+nNxs evi7M5ZjCICLO3qxzSqSnYEOgtvcT0wEQCXsicKXCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:47:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2c8784b8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:52 +0000 (UTC) Date: Wed, 27 Mar 2024 09:47:03 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 13/13] builtin/config: display subcommand help Message-ID: <657d1355b5d33056644effc5d170d323a58ebdbc.1711527812.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: Until now, `git config -h` would have printed help for the old-style syntax. Now that all modes have proper subcommands though it is preferable to instead display the subcommand help. Drop the `NO_INTERNAL_HELP` flag to do so. While at it, drop the help mismatch in t0450 and add the `--get-colorbool` option to the usage such that git-config(1)'s synopsis and `git config -h` match. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 5 +++-- t/t0450/txt-help-mismatches | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index b8cb940b1e..18b1f7014a 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -23,6 +23,7 @@ static const char *const builtin_config_usage[] = { N_("git config rename-section [] "), N_("git config remove-section [] "), N_("git config edit []"), + N_("git config [] --get-colorbool []"), NULL }; @@ -1084,10 +1085,10 @@ int cmd_config(int argc, const char **argv, const char *prefix) * us when parsing the legacy-style modes that don't use subcommands. */ argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, - PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_NO_INTERNAL_HELP|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); if (subcommand) { argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, - PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_NO_INTERNAL_HELP|PARSE_OPT_KEEP_UNKNOWN_OPT); + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); return subcommand(argc, argv, prefix); } diff --git a/t/t0450/txt-help-mismatches b/t/t0450/txt-help-mismatches index a0777acd66..28003f18c9 100644 --- a/t/t0450/txt-help-mismatches +++ b/t/t0450/txt-help-mismatches @@ -10,7 +10,6 @@ checkout checkout-index clone column -config credential credential-cache credential-store