From patchwork Wed Nov 13 18:55:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65A8B109A for ; Wed, 13 Nov 2019 18:55:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3775D20658 for ; Wed, 13 Nov 2019 18:55:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MznuhTSA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727915AbfKMSzi (ORCPT ); Wed, 13 Nov 2019 13:55:38 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:38457 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbfKMSzh (ORCPT ); Wed, 13 Nov 2019 13:55:37 -0500 Received: by mail-lf1-f65.google.com with SMTP id q28so2844762lfa.5 for ; Wed, 13 Nov 2019 10:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oFkNEa4pNa7eAB6hNALCb6aGKLvenVhnUwjur3NX6EA=; b=MznuhTSAmyR7KQbMGErXDqDzDAQv65vmIcQ+gvvhlniCP3rrbw+Sot+XflZi5X05aG b7ucstpYpSumCq2eSAh5xkXBRgNdoB7LG6/4ps/uUTVHV0IfP515N1OD+AcGzF32o8V/ /yFVP7fVTJozkiotg8nmroLNM6w8N+OW/DZR/6l2XbVMue2R8NyKbSdRAJuJxE0E3xlZ oMeFUNBMUOahVcyltbwetuQ9OJNP6DtnIxCjZ94jOYw4nP3PXJe3irGftcvvXsRyGylQ jXQVDo/YpXhYT1q8AMjMfLT93waclnwW1txU+u7Te4Y1LBd+kW/OtNwJya/N0+wCk+Vk 5Otw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oFkNEa4pNa7eAB6hNALCb6aGKLvenVhnUwjur3NX6EA=; b=t1QQzRSkY13gzfw6xVcEktHmhlVPZ0Ib5nRwtqlNiIt7WU+PF+8/yjnfNnClD4PafL rG8q9OTwhOfBklXUvcczZrR037D8YVfRSC6grp1Qy8+rSNh3lubxxbFeUcdvTO+nOGI8 pcRh/U0VPnfgLpMgnciHDAc/drzi+jZg+HH/17ocYASkt8hnyzRPTjDPf9LJ1txDy+7m QTd+8Cl0Eo1oJQAlkaLPPdcxxlZY2FCtvixgodWQxByjz4jAM58l+j6rpka2iBvjyziE 9tVReNCTZelwdWJ8rpBAFv4ovjl8/aNLnURNVIr0Y0SBLKwsPtHXo91y8xgXnljqebrq jdeg== X-Gm-Message-State: APjAAAUHBfavXYVUKKtpJg1E6LOq7hICsZ9bFd9bAcEMbPA+9iFLmvuM cF9ussjdZ2W4nxCRPaEMcpZ7Zxm2 X-Google-Smtp-Source: APXvYqyYL8tBWTdmjd4MF11Ui5fcz0y9yYmmTZ9zs506tAR5RlBjEQNULZMXtEQ8mj3vQVQADdx0Kg== X-Received: by 2002:a19:4318:: with SMTP id q24mr3738702lfa.12.1573671335108; Wed, 13 Nov 2019 10:55:35 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:34 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 1/8] config: make `git_parse_maybe_bool_text()` public Date: Wed, 13 Nov 2019 19:55:00 +0100 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We will soon use it from outside config.c. Signed-off-by: Martin Ågren --- config.c | 2 +- config.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index e7052b3977..318711f7a7 100644 --- a/config.c +++ b/config.c @@ -1047,7 +1047,7 @@ ssize_t git_config_ssize_t(const char *name, const char *value) return ret; } -static int git_parse_maybe_bool_text(const char *value) +int git_parse_maybe_bool_text(const char *value) { if (!value) return 1; diff --git a/config.h b/config.h index f0ed464004..343f24c408 100644 --- a/config.h +++ b/config.h @@ -95,6 +95,13 @@ int config_with_options(config_fn_t fn, void *, int git_parse_ssize_t(const char *, ssize_t *); int git_parse_ulong(const char *, unsigned long *); int git_parse_maybe_bool(const char *); + +/** + * Same as `git_parse_maybe_bool`, except that it does not handle + * integer values, i.e., those cause this function to return -1. + */ +int git_parse_maybe_bool_text(const char *); + int git_config_int(const char *, const char *); int64_t git_config_int64(const char *, const char *); unsigned long git_config_ulong(const char *, const char *); From patchwork Wed Nov 13 18:55:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB151138C for ; Wed, 13 Nov 2019 18:55:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4904206E1 for ; Wed, 13 Nov 2019 18:55:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WzqrjE0M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbfKMSzm (ORCPT ); Wed, 13 Nov 2019 13:55:42 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38430 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbfKMSzl (ORCPT ); Wed, 13 Nov 2019 13:55:41 -0500 Received: by mail-lj1-f194.google.com with SMTP id v8so3787934ljh.5 for ; Wed, 13 Nov 2019 10:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=itIbNbcPbXjIy4vURPK2pJHVCGhNOByKpHzFgPbWvTI=; b=WzqrjE0MorwPb0he5QubIcnU/FXIyed2Q4bhmm+9mrGycCQon/g6pgJKf4IO0rCp3I 3c8T1ey6k8XjIHQh/e7jWz8kxete0VlJPwVVH1Nz74H4hj9wXP66GAH9oHWS0tyOPX3i LYdCrdsrz+UposJOhD4r51hM4sCEMlr1WX66htIlrWEc19LlZMNQ5CbRkve9f2n1885A wfuFu6PaxnM9SrHbk46ru4n3oW9XIt0RmEO1Tszci+bVL2sv7TtE4bITjcF6U8Z0tGUp XF3Wtk7FFgG3qSCsFS8vEKPjZJBfsW1ddtyKkNS9MjBnkXZriGbfIuiAPUyQCyOwB6GK AZXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itIbNbcPbXjIy4vURPK2pJHVCGhNOByKpHzFgPbWvTI=; b=V+pY1NBw325nIg5WAMMjYh9yOvbGp3ffFNr+cW9CzzFMRQ0T9e+N0FqD/kNbDYEEC6 BNFCzAkl2wkEy/lHO2ZgprGCNptM8Q1hcubwVq6M/2oDtvmUzg/xQ1vEzOUbL93tXc++ xcGbNSEhNb0eyXYtkmpb4Ko/195Ysdo+eqi+0XtpmeyuxW568DdY7hY30Ui4plLv38dn m1RgPXo8cpkZ0dCA8LLtbzLDCQJlyLtg8dfJMGjvruBoQeynu5W6cbryzJyJPgAQjA+m 3peJK9OG0K4oZV1zrDZyGAb9hL+k06pN+nCChGhHxpPRoeDZ136oXWyUsUUCGBhtqyJx ZCpg== X-Gm-Message-State: APjAAAWYOUZE2hxUdieexSWUZDwUOqkO6j4B+TYFkMOhqUZcNKBh2csj qT/+fY6jeWxt0nvx6cB4EdgDIUpC X-Google-Smtp-Source: APXvYqxgFRjlUM7xAj9Q/T4pZFw8QG22aK5d7sp8S9qvbvmq++rTcRE3l587JC3fMg2FlsVoMt8hIw== X-Received: by 2002:a2e:7016:: with SMTP id l22mr3721680ljc.227.1573671337564; Wed, 13 Nov 2019 10:55:37 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:36 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 2/8] t1300: modernize part of script Date: Wed, 13 Nov 2019 19:55:01 +0100 Message-Id: <37e2b121d5946cfacb3fc4d2721770e496f7b752.1573670565.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Create `.git/config` and `expect` files inside `test_expect_success`, either inside the one existing test that uses the file, or in a new "setup" step before several tests that use it. Redirect using `>output` rather than `> output`. Use `<<-\EOF" with heredocs rather than just `<< EOF` and use `q_to_tab` to create properly indented input and output files. This commit does not modernize the whole script, but just some of it, around the point where a later commit will add new content. Signed-off-by: Martin Ågren --- t/t1300-config.sh | 138 ++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 73 deletions(-) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 983a0a1583..a38cc143a1 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -321,15 +321,14 @@ test_expect_success 'hierarchical section value' ' test_cmp expect .git/config ' -cat > expect << EOF -beta.noindent=sillyValue -nextsection.nonewline=wow2 for me -123456.a123=987 -version.1.2.3eX.alpha=beta -EOF - test_expect_success 'working --list' ' - git config --list > output && + cat >expect <<-\EOF && + beta.noindent=sillyValue + nextsection.nonewline=wow2 for me + 123456.a123=987 + version.1.2.3eX.alpha=beta + EOF + git config --list >output && test_cmp expect output ' test_expect_success '--list without repo produces empty output' ' @@ -337,55 +336,53 @@ test_expect_success '--list without repo produces empty output' ' test_must_be_empty output ' -cat > expect << EOF -beta.noindent -nextsection.nonewline -123456.a123 -version.1.2.3eX.alpha -EOF - test_expect_success '--name-only --list' ' + cat >expect <<-\EOF && + beta.noindent + nextsection.nonewline + 123456.a123 + version.1.2.3eX.alpha + EOF git config --name-only --list >output && test_cmp expect output ' -cat > expect << EOF -beta.noindent sillyValue -nextsection.nonewline wow2 for me -EOF - test_expect_success '--get-regexp' ' + cat >expect <<-\EOF && + beta.noindent sillyValue + nextsection.nonewline wow2 for me + EOF git config --get-regexp in >output && test_cmp expect output ' -cat > expect << EOF -beta.noindent -nextsection.nonewline -EOF - test_expect_success '--name-only --get-regexp' ' + cat >expect <<-\EOF && + beta.noindent + nextsection.nonewline + EOF git config --name-only --get-regexp in >output && test_cmp expect output ' -cat > expect << EOF -wow2 for me -wow4 for you -EOF - test_expect_success '--add' ' + cat >expect <<-\EOF && + wow2 for me + wow4 for you + EOF git config --add nextsection.nonewline "wow4 for you" && - git config --get-all nextsection.nonewline > output && + git config --get-all nextsection.nonewline >output && test_cmp expect output ' -cat > .git/config << EOF -[novalue] - variable -[emptyvalue] - variable = -EOF +test_expect_success 'setup config file with no/empty values' ' + q_to_tab >.git/config <<-\EOF + [novalue] + Qvariable + [emptyvalue] + Qvariable = + EOF +' test_expect_success 'get variable with no value' ' git config --get novalue.variable ^$ @@ -395,38 +392,33 @@ test_expect_success 'get variable with empty value' ' git config --get emptyvalue.variable ^$ ' -echo novalue.variable > expect - test_expect_success 'get-regexp variable with no value' ' - git config --get-regexp novalue > output && + echo novalue.variable >expect && + git config --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 && + echo "novalue.variable true" >expect && + git config --bool --get-regexp 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 && + echo "emptyvalue.variable " >expect && + git config --get-regexp emptyvalue >output && test_cmp expect output ' -echo true > expect - test_expect_success 'get bool variable with no value' ' - git config --bool novalue.variable > output && + echo true >expect && + git config --bool novalue.variable >output && test_cmp expect output ' -echo false > expect - test_expect_success 'get bool variable with empty value' ' - git config --bool emptyvalue.variable > output && + echo false >expect && + git config --bool emptyvalue.variable >output && test_cmp expect output ' @@ -435,34 +427,34 @@ test_expect_success 'no arguments, but no crash' ' test_i18ngrep usage output ' -cat > .git/config << EOF -[a.b] - c = d -EOF - -cat > expect << EOF -[a.b] - c = d -[a] - x = y -EOF +test_expect_success 'setup simple config file' ' + q_to_tab >.git/config <<-\EOF + [a.b] + Qc = d + EOF +' test_expect_success 'new section is partial match of another' ' + q_to_tab >expect <<-\EOF && + [a.b] + Qc = d + [a] + Qx = y + EOF git config a.x y && test_cmp expect .git/config ' -cat > expect << EOF -[a.b] - c = d -[a] - x = y - b = c -[b] - x = y -EOF - test_expect_success 'new variable inserts into proper section' ' + q_to_tab >expect <<-\EOF && + [a.b] + Qc = d + [a] + Qx = y + Qb = c + [b] + Qx = y + EOF git config b.x y && git config a.b c && test_cmp expect .git/config From patchwork Wed Nov 13 18:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58DD4109A for ; Wed, 13 Nov 2019 18:55:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B499206E1 for ; Wed, 13 Nov 2019 18:55:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FW2Z6bnz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbfKMSzm (ORCPT ); Wed, 13 Nov 2019 13:55:42 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:44278 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbfKMSzm (ORCPT ); Wed, 13 Nov 2019 13:55:42 -0500 Received: by mail-lj1-f194.google.com with SMTP id g3so3761351ljl.11 for ; Wed, 13 Nov 2019 10:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lSMbK8DbBv6LFG6/5tYxZtgJWUWauZdxGnoUHUnrV/A=; b=FW2Z6bnznmnqyMslA2neCtQXZ+Bo4+F370nJRQQZ39dHdp2VONS9oTOMW8lX+nM+Gt 1ou6bFz2Pkl3nrJKsmm2+zxUjB+3SsaVztTsiduNdjvoYIsitis8pAhsgfNjrHMMJ+tV p9QYYHjJMmYFKvjfpcRFxY5nclBbI1Rh44tRXx3r/ex1y/lMiPu1D2mjNr3lXD3EmwIQ MDOr8m9rNcwUEMWoxie4TdowHc3EXihSdQo3z0jn1cnIA/y0HK7ylybktu1l2IHRAXOs W1oXctDV2Y6zVQ53oax0Q2kZEh0aQoavWNC7rCZc+J6t375F3ZVTWqdIqw6dkAF2fBAw MxKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lSMbK8DbBv6LFG6/5tYxZtgJWUWauZdxGnoUHUnrV/A=; b=GeKNwGeX1AJhucYmOj6r6hFAThZ00ePPmJMsUvn4x2AhGcGCS/8VWEKGEvng7mylks DxW6/Nl0ADmLw7C+2tJQ30Qr/0UhAXp1ZvdgE+mJLICyux1B82VN9EOtkigI6VPE0MHe JAIRl7iABGUeDA4lr0o0e16cMcBQiWEmOesV7yeDYXog71bAM/upVvEoT9tJTBcHopzC ZdxeWaCG5k6lShqqzQ0Ad8Ao7sYUHwp0t0bZU9cukHoh+t/9o9ihczLrtAJa7thDftkB cYBAC1oWLxU6reP3exbVUF2v2edkxfaA7o+MZPvYeA2R2vqHc5NV++TCjxG/vw5W4CRg bsuQ== X-Gm-Message-State: APjAAAWJOsT26v8+qgdNbIUfZ/LK2Ul4gPXJZAFRwIp/uVlfTCTHBJn4 9lSUGBakJHE3KgCfRRYpAzZs2C1Z X-Google-Smtp-Source: APXvYqxzxBHlxc7Qz3g1NWwVbrC4hlhYlLFXWwr+YQ3OyE9sUklfSAwrl4gd4H+2d8wqvqpOEGJNyw== X-Received: by 2002:a2e:6e15:: with SMTP id j21mr3715421ljc.17.1573671339999; Wed, 13 Nov 2019 10:55:39 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:39 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 3/8] builtin/config: extract `handle_value_regex()` from `get_value()` Date: Wed, 13 Nov 2019 19:55:02 +0100 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is a self-contained and fairly large chunk of code which will soon gain a few more lines. Prepare by extracting it into a separate function. This whole chunk is wrapped in "if (regex_)" -- rewrite it into an early return path in the new helper function to reduce indentation. Signed-off-by: Martin Ågren --- I copy the "xmalloc(sizeof(regex_t))" anti-pattern verbatim. We will lose it in the next patch. builtin/config.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 98d65bc0ad..e675ae0640 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -280,6 +280,28 @@ static int collect_config(const char *key_, const char *value_, void *cb) return format_config(&values->items[values->nr++], key_, value_); } +static int handle_value_regex(const char *regex_) +{ + if (!regex_) { + regexp = NULL; + return 0; + } + + if (regex_[0] == '!') { + do_not_match = 1; + regex_++; + } + + regexp = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(regexp, regex_, REG_EXTENDED)) { + error(_("invalid pattern: %s"), regex_); + FREE_AND_NULL(regexp); + return CONFIG_INVALID_PATTERN; + } + + return 0; +} + static int get_value(const char *key_, const char *regex_) { int ret = CONFIG_GENERIC_ERROR; @@ -317,20 +339,9 @@ static int get_value(const char *key_, const char *regex_) } } - if (regex_) { - if (regex_[0] == '!') { - do_not_match = 1; - regex_++; - } - - regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(regexp, regex_, REG_EXTENDED)) { - error(_("invalid pattern: %s"), regex_); - FREE_AND_NULL(regexp); - ret = CONFIG_INVALID_PATTERN; - goto free_strings; - } - } + ret = handle_value_regex(regex_); + if (ret) + goto free_strings; config_with_options(collect_config, &values, &given_config_source, &config_options); From patchwork Wed Nov 13 18:55:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FFAD138C for ; Wed, 13 Nov 2019 18:55:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72448206E1 for ; Wed, 13 Nov 2019 18:55:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CwXWXpaX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728039AbfKMSzp (ORCPT ); Wed, 13 Nov 2019 13:55:45 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37768 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbfKMSzo (ORCPT ); Wed, 13 Nov 2019 13:55:44 -0500 Received: by mail-lj1-f195.google.com with SMTP id d5so3798326ljl.4 for ; Wed, 13 Nov 2019 10:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d40Dds3jNN7XULFo+RkjUoC3XaUYu9dtW1GObHWalOY=; b=CwXWXpaXqPl4mUSMTrGDuGOcPMZOBi9+xa/+MprfAMJv6I6xJz2lNwb3tsFoY5TVYI G3AR8wkmzAtXP2RL9yd9WAo3vP2Q8uyKYnLOr8qdfqO5H7wkRqrKuuVJiC/CmTJ81pPQ i6oZkIdlkWbF7JRW9za8HCvdAslRDClD6yaywDtgD09yWyVXIYUKEPtPGUzBuxr1vbfP rhm0tsg/xsQ2E9tvnM+sfMac79bV9q6MCCU/6c0R5bKwp2jQUQ0Py1hqAhwmHO4DnJYS oBIcsb8khtdyi/yjBYPrj7iy8eDPNG5Ipig9AtDmlpizpNquTEJ+IzLX7owyPRwE/vPW oWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d40Dds3jNN7XULFo+RkjUoC3XaUYu9dtW1GObHWalOY=; b=pdRfQLkBUEFCoeTcY+KafQlhm3JXkXG+3j7A4weoysO5+1opFjmzisk27CZwbBfpPl XhvxDz57New63OKZ9qcI0s6e2wLWRCTThTxABVcvjpOS9Iebu9bc0V1kYVnqYlCbRY+4 A3L6E6rWCLreBWjIMKho0BlfxEnDqF2Q6uiGdPKJyAUeYJnm3u5vJjhWcQ5jz4P6wWn1 +iz7xjCE+GU95x6a+26tVMIV2pKS6N2q3rV0rsFlqTDy0I2XlqmWlUr8vK7Hh14yJ1Sv DkECl656BCqn+HMa40GkCU8NM6Fg59ghGIEFwruZ4grhLNDwG5jZerugTzvhjj5w2O92 GYVw== X-Gm-Message-State: APjAAAXq3MlkOjVtcts595OWNcHX0DAdzdWcezkn6WDQ1WrU4BysVdUG WOoAYetvr3PJU2z1kwmpqYtzGsIp X-Google-Smtp-Source: APXvYqycnnNiflg+11XRyhw/342QQ2nmGarLMe9/uxT5XeDd/Ne23PiLVbZ66KhiJDgEx562mb+Naw== X-Received: by 2002:a05:651c:111a:: with SMTP id d26mr3670592ljo.168.1573671342581; Wed, 13 Nov 2019 10:55:42 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:41 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 4/8] builtin/config: collect "value_regexp" data in a struct Date: Wed, 13 Nov 2019 19:55:03 +0100 Message-Id: <336eaa77e4974f84ea1eef473672e1d300f3a43d.1573670565.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git config` can take an optional "value_regexp". Collect the `regex_t`-pointer and the `do_not_match` flag into a new `struct cmd_line_value`. Rather than signalling/judging presence of a regexp by the NULL-ness of the pointer, introduce a `mode` enum. After this commit, we just have two modes, "none" and "regexp", but we will gain another one in the next commit. Signed-off-by: Martin Ågren --- builtin/config.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index e675ae0640..d812e73e2b 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -14,12 +14,15 @@ static const char *const builtin_config_usage[] = { static char *key; static regex_t *key_regexp; -static regex_t *regexp; +static struct { + enum { none, regexp } mode; + regex_t *regexp; + int do_not_match; /* used with `regexp` */ +} cmd_line_value; static int show_keys; static int omit_values; static int use_key_regexp; static int do_all; -static int do_not_match; static char delim = '='; static char key_delim = ' '; static char term = '\n'; @@ -270,8 +273,10 @@ static int collect_config(const char *key_, const char *value_, void *cb) return 0; if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) return 0; - if (regexp != NULL && - (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) + if (cmd_line_value.mode == regexp && + (cmd_line_value.do_not_match ^ + !!regexec(cmd_line_value.regexp, value_ ? value_ : "", + 0, NULL, 0))) return 0; ALLOC_GROW(values->items, values->nr + 1, values->alloc); @@ -283,19 +288,21 @@ static int collect_config(const char *key_, const char *value_, void *cb) static int handle_value_regex(const char *regex_) { if (!regex_) { - regexp = NULL; + cmd_line_value.mode = none; return 0; } + cmd_line_value.mode = regexp; + if (regex_[0] == '!') { - do_not_match = 1; + cmd_line_value.do_not_match = 1; regex_++; } - regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(regexp, regex_, REG_EXTENDED)) { + cmd_line_value.regexp = xmalloc(sizeof(*cmd_line_value.regexp)); + if (regcomp(cmd_line_value.regexp, regex_, REG_EXTENDED)) { error(_("invalid pattern: %s"), regex_); - FREE_AND_NULL(regexp); + FREE_AND_NULL(cmd_line_value.regexp); return CONFIG_INVALID_PATTERN; } @@ -372,9 +379,9 @@ static int get_value(const char *key_, const char *regex_) regfree(key_regexp); free(key_regexp); } - if (regexp) { - regfree(regexp); - free(regexp); + if (cmd_line_value.regexp) { + regfree(cmd_line_value.regexp); + free(cmd_line_value.regexp); } return ret; From patchwork Wed Nov 13 18:55:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0D66109A for ; Wed, 13 Nov 2019 18:55:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A91DA20658 for ; Wed, 13 Nov 2019 18:55:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gosZNqXZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728092AbfKMSzs (ORCPT ); Wed, 13 Nov 2019 13:55:48 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44943 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727943AbfKMSzs (ORCPT ); Wed, 13 Nov 2019 13:55:48 -0500 Received: by mail-lf1-f67.google.com with SMTP id z188so2806089lfa.11 for ; Wed, 13 Nov 2019 10:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zDaJ3ejsEjFrg3NLsT1DueVCsQNNykvNu+wDyBOlz0E=; b=gosZNqXZG2v79nKaujUKrU9v2avOirUoD5IrUKGY4ErSnm8+ZBp+b/F2BD9jjSWh/Q oOwljm4yzQilhYIIT0bsUj2GoGd0MZuUgz3VWZ0cDyAfadjspBMa5YNM5NW2RhqF2/HF kxM7RrQO1jUa5sG3V2UZXpih3pSK8svzo67dpbDL7Oy9QAF0haLP4FJf/bIamKkmnK/B y/HaAHwzFdWxtZA0fI9XLGZAE9UJEUYdUD6XOuHG8hzbsBFxnW2yaxCY13zCPhoETxUh jJvuR2bG8sc0aeVlyg/glg2/fb+kdK1LPH26KebRX3beZYK2in9UXXcWsvhr4OwqNQmw jAgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zDaJ3ejsEjFrg3NLsT1DueVCsQNNykvNu+wDyBOlz0E=; b=KVDpKUqN/NR3Nkdh1eLiKvLozFXyMwU1gsRElUEiUaeuOoJWxIzXZYPG2XON0hChSC a8sAvYWrJhxw9nf/oaEAyNJ5SFjJKcJ/yVJ/wmEGbByL7wc3SKy8VxrMW7jL8LM9jlph /fafZe0HOcSEqqgCTCZsCnCZWRKBAGB6T6zOSP2f6l22YLcGD0T8y0Qfil4JbT8AJDaL h0OMyO48OAHnEL6ZvAN8CIQZNRAA3wzWgAUkXgkgoBmKSgBhOUCuJbuIOLKLtprLCqss VehMH3cofzoMPzQb1a7wRFV39b8sFq9nqhWWFk1mtPWojomVDnYGhN+tDlxkCDY0OmC7 Ufww== X-Gm-Message-State: APjAAAVHmn2LRKONGEYHjfvBONUhIU2FDp/FpH9c4u3SGq11ujLwfYkU /RQqAO41BPnAPxvNO0EgXrJkcS77 X-Google-Smtp-Source: APXvYqztMmkyrEgU+WWU2EULiCNa0IWkV8F6v5uyPrVHCMxB6up6TBLxF1tyZz8E/6B/BcHgHlQL/A== X-Received: by 2002:a19:8ac5:: with SMTP id m188mr3912436lfd.186.1573671344832; Wed, 13 Nov 2019 10:55:44 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:44 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 5/8] builtin/config: canonicalize "value_regex" with `--type=bool` Date: Wed, 13 Nov 2019 19:55:04 +0100 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With `--type=bool`, we use the "value_regex" as a normal regex and do not use our knowledge about the different well-defined ways we have of spelling the boolean values. Let's consider a few examples. These output "true": git -c foo.bar=true config --type=bool --get foo.bar true git -c foo.bar=true config --type=bool --get foo.bar t These produce no output: git -c foo.bar=true config --type=bool --get foo.bar True git -c foo.bar=true config --type=bool --get foo.bar 1 Canonicalize the provided "value_regex", then canonicalize candidate values as we go through the config and compare the canonicalized values. If the parameter doesn't canonicalize, fall back to handling it as a regex, as before. This would happen in the second example above, but also if someone has hand-rolled their own canonicalisation with, e.g., something like "^(on|On|ON|true|1|42)$". This commit affects all modes that take a "value_regex", e.g., `--get-regexp` which can be used in a more useful way than the examples above might at first suggest: git config --type=bool --name-only --get-regexp '^foo\.' true This commit does change the behavior for certain usages, but it almost certainly does so for the better: We don't exclude config items based on how the config happens to spell "true" or "false". This commit would cause a regression if someone uses different synonyms for "true", knowing that Git handles them all the same in day-to-day operation, but relying on the encoding (using, say, integers 1-100) to signal some sort of confidence and using `git config` to query for various such "levels". I'm tempted to bet no-one will be hurt by this change. Do not rename the "value_regex" in the documentation. This commit can be seen as teaching `git config --type=bool` about a particular type of regex, where "true" matches "yes", but not "no". So arguably, "value_regex" still describes quite well what is going on. Signed-off-by: Martin Ågren --- Documentation/git-config.txt | 4 ++++ builtin/config.c | 15 +++++++++++- t/t1300-config.sh | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 899e92a1c9..139750bbda 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -43,6 +43,10 @@ outgoing values are canonicalize-able under the given . If no `--type=` is given, no canonicalization will be performed. Callers may unset an existing `--type` specifier with `--no-type`. +With `--type=bool`, if `value_regex` is given +and canonicalizes to a boolean value, it matches all entries +that canonicalize to the same boolean value. + When reading, the values are read from the system, global and repository local configuration files by default, and options `--system`, `--global`, `--local`, `--worktree` and diff --git a/builtin/config.c b/builtin/config.c index d812e73e2b..c9fe0c5752 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -15,9 +15,10 @@ static const char *const builtin_config_usage[] = { static char *key; static regex_t *key_regexp; static struct { - enum { none, regexp } mode; + enum { none, regexp, boolean } mode; regex_t *regexp; int do_not_match; /* used with `regexp` */ + int boolean; } cmd_line_value; static int show_keys; static int omit_values; @@ -278,6 +279,9 @@ static int collect_config(const char *key_, const char *value_, void *cb) !!regexec(cmd_line_value.regexp, value_ ? value_ : "", 0, NULL, 0))) return 0; + if (cmd_line_value.mode == boolean && + git_parse_maybe_bool(value_) != cmd_line_value.boolean) + return 0; ALLOC_GROW(values->items, values->nr + 1, values->alloc); strbuf_init(&values->items[values->nr], 0); @@ -292,6 +296,15 @@ static int handle_value_regex(const char *regex_) return 0; } + if (type == TYPE_BOOL) { + int boolval = git_parse_maybe_bool(regex_); + if (boolval >= 0) { + cmd_line_value.mode = boolean; + cmd_line_value.boolean = boolval; + return 0; + } + } + cmd_line_value.mode = regexp; if (regex_[0] == '!') { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index a38cc143a1..e4906a893e 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -427,6 +427,51 @@ test_expect_success 'no arguments, but no crash' ' test_i18ngrep usage output ' +test_expect_success 'setup config file with several boolean values' ' + cat >.git/config <<-\EOF + [foo] + n1 = no + n2 = NO + n3 = off + n4 = false + n5 = 0 + n6 = + y1 = yes + y2 = YES + y3 = on + y4 = true + y5 = 1 + y6 = 42 + y7 + EOF +' + +test_expect_success '--get-regexp canonicalizes value_regex with --type=bool (false)' ' + git config --type=bool --get-regexp "foo\..*" OFF >output && + test_line_count = 6 output && + ! grep -v "^foo.n" output +' + +test_expect_success '--get-regexp canonicalizes value_regex with --type=bool (true)' ' + git config --type=bool --get-regexp "foo\..*" ON >output && + test_line_count = 7 output && + ! grep -v "^foo.y" output +' + +test_expect_success '--get canonicalizes integer value_regex with --type=bool' ' + echo true >expect && + git config --type=bool --get foo.y2 1 >output && + test_cmp expect output +' + +test_expect_success '--type=bool with "non-bool" value_regex' ' + echo true >expect && + git config --type=bool --get foo.y4 "t.*" >output && + test_cmp expect output && + test_must_fail git config --type=bool --get foo.y4 "T.*" >output && + test_must_be_empty output +' + test_expect_success 'setup simple config file' ' q_to_tab >.git/config <<-\EOF [a.b] From patchwork Wed Nov 13 18:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F845109A for ; Wed, 13 Nov 2019 18:55:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E593B20658 for ; Wed, 13 Nov 2019 18:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gUGBxnIq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728096AbfKMSzv (ORCPT ); Wed, 13 Nov 2019 13:55:51 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40608 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbfKMSzt (ORCPT ); Wed, 13 Nov 2019 13:55:49 -0500 Received: by mail-lj1-f195.google.com with SMTP id q2so3783948ljg.7 for ; Wed, 13 Nov 2019 10:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g9Z4iMJWW6/KaTN7qELoQ4mcTWBr9HV8TZqKdgyaGmo=; b=gUGBxnIqCxiovw8YYqlGkIljtHjsV4G4h/vr95gst0knZ8A7MJav6Ls7aAH6SR0YjP c6WrIY8sz07P/iQ6ntF7A1AD5c8zrzn4Ig39UMrZEkqNlrdqf/FIjXxj9lTcO+g5eZuU oXG6y5BvsuyjnVqOWAAdMDQv21sJx1F7TcHASN4vB4L26isK4L9owmnW1MTrvKVPocyT joSzj0BqYq82FQicY0a3ztYAZ8ieOqaGUcqrubz80C57HOjbPzQd5JZJC0QZD4TVmB+s 33BZfOXlGw2jzFq4HPqwXgkD3lRmvqRMqcNDjgVsbYH+n7qNw0z0GheJVq+gNKWd/cb4 I3mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g9Z4iMJWW6/KaTN7qELoQ4mcTWBr9HV8TZqKdgyaGmo=; b=V8lzBtkVroA/urJ8OHZwNn6mg5RAbojVHJ7Ua1m5wqVAzB/2JFBnYjzlplQE/HMmFE eujcj9Nvh18agVyJcsabZALoB0/HQdcefqSC1hFIeVGuhYMUcBVDRxY/vziOlsRnyxj4 9bYk9ug6txie2FXOLhGNIcErzQD+sZzig3fIy1Vh3UESddWbOsaRO3a4ylTm5Rl3r5q6 CkD4VJoSZ8fCuCbmYs2a48PsB8Rs1ZOO3ek4oqesVukEOLdmuxG6c7QtlfUCU4K9mjEM F8b8Xio0x7+sKuJtMURo+gKXtxkKKzkHJstbFitsL5feqpH5c0xJvCJJEYK1lmQrpfTe qShA== X-Gm-Message-State: APjAAAXXB1YlW9wmSPGZk+JXx0zlLHxhQn62IXi+8qU27wwLe1+koDxt GgTmB2E3fRn5uJCSqDQ9cTSLWsZw X-Google-Smtp-Source: APXvYqwQds2K8xBeCjVe4S9+76aXTBNOUzXpPTROrZk9Rocg+sWhfG5CjzILugguR+Qnkfm6AYAlUA== X-Received: by 2002:a2e:b5d0:: with SMTP id g16mr3782918ljn.88.1573671347148; Wed, 13 Nov 2019 10:55:47 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:46 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 6/8] builtin/config: canonicalize "value_regex" with `--type=bool-or-int` Date: Wed, 13 Nov 2019 19:55:05 +0100 Message-Id: <5d6bf76f2e9bccf38f566524f6133252be0603c9.1573670565.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As an obvious follow-up to the previous commit, also canonicalize the "value_regex" when the type is "bool-or-int". Observe that in this case, falling back to handling the "value_regex" as a normal regex is not just to cater to old scripts and habits. It is necessary to handle the numerical inputs (or regexes matching some specific numerical values!) that we must expect. Future commits will expand on the code for `--type=bool`. Rather than trying to shoehorn both these cases into a single chunk of code, let's just duplicate some of the code from the previous commit. Signed-off-by: Martin Ågren --- Documentation/git-config.txt | 2 +- builtin/config.c | 9 +++++++++ t/t1300-config.sh | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 139750bbda..864375b1ec 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -43,7 +43,7 @@ outgoing values are canonicalize-able under the given . If no `--type=` is given, no canonicalization will be performed. Callers may unset an existing `--type` specifier with `--no-type`. -With `--type=bool`, if `value_regex` is given +With `--type=bool` or `--type=bool-or-int`, if `value_regex` is given and canonicalizes to a boolean value, it matches all entries that canonicalize to the same boolean value. diff --git a/builtin/config.c b/builtin/config.c index c9fe0c5752..4e274d4867 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -305,6 +305,15 @@ static int handle_value_regex(const char *regex_) } } + if (type == TYPE_BOOL_OR_INT) { + int boolval = git_parse_maybe_bool_text(regex_); + if (boolval >= 0) { + cmd_line_value.mode = boolean; + cmd_line_value.boolean = boolval; + return 0; + } + } + cmd_line_value.mode = regexp; if (regex_[0] == '!') { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index e4906a893e..f0e9a21dc4 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -472,6 +472,26 @@ test_expect_success '--type=bool with "non-bool" value_regex' ' test_must_be_empty output ' +test_expect_success '--type=bool-or-int with boolean value_regex' ' + echo true >expect && + git config --type=bool-or-int --get foo.y2 true >output && + test_cmp expect output +' + +test_expect_success '--type=bool-or-int with integer value_regex' ' + test_must_fail git config --type=bool-or-int --get foo.y2 1 >output && + test_must_be_empty output && + echo 1 >expect && + git config --type=bool-or-int --get foo.y5 1 >output && + test_cmp expect output +' + +test_expect_success '--type=bool-or-int with regex value_regex' ' + echo true >expect && + git config --type=bool-or-int --get foo.y4 "t.*" >output && + test_cmp expect output +' + test_expect_success 'setup simple config file' ' q_to_tab >.git/config <<-\EOF [a.b] From patchwork Wed Nov 13 18:55:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD7C41390 for ; Wed, 13 Nov 2019 18:55:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E934206E1 for ; Wed, 13 Nov 2019 18:55:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tSYHQHOP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbfKMSz4 (ORCPT ); Wed, 13 Nov 2019 13:55:56 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38462 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbfKMSz4 (ORCPT ); Wed, 13 Nov 2019 13:55:56 -0500 Received: by mail-lj1-f196.google.com with SMTP id v8so3788777ljh.5 for ; Wed, 13 Nov 2019 10:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pSD2VDvr82/IoSXeKYKK22kLzHcNEqKtYhNihOJgIKA=; b=tSYHQHOPOxdBaONMz7QawOTT3QRJsNi0TsKf2dzlih+rxiZ4IKQ6hMlvWM2U0zmoQs gbuBEJ5JKIBKHA5DWiM8faGwdiEnuirMClYx1fZc7G81YEnZ21VvZjBIxqE+h7rV5ZvM tHDCNrXjMyXdJR4f5WKSl12Y2hpUUwu9wRawGL1+I6MnwDDoJo/96XPH1s7562jgBcTW AnU3ghT6dD1GUQc5LPZxmpgWL3/XtZm/Bc36kOfieT7RCe5Mwkmz722ZbiIv7MS4bD6G eNYnYOxbAgdypn/d7UZUflxgxGKMHRY8/NAcMEQtEO/HS/HWno0EiRcujWaJ+sto8qwX ImYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pSD2VDvr82/IoSXeKYKK22kLzHcNEqKtYhNihOJgIKA=; b=ncDn0E574A7L1Z+26+lLr5w7xGmQJqQ+eKx0XjQSN+1rtoXyL0J48veBnbTlaFsuCv BQ5SeNU3paZ13fJfLgin6eGWqfsVUr675mO4Y7EubL4uQLAog0hVWY3mxL7XK5pzp5jD g0XwRaeeB8rM7t47QTWIAx7oU2mC+wd0S7VubDjAwiYm2Ur8JqTE0ITwGbNy9o17L3+w 5L2PMKUvPKsmET7aQ9bhMcVrjUMQ78KpfNJLqLlewv6vgtNvCQMuzmxbGgL3B9W0Duc/ 2EkODeFi7qiaMTRzxknhsG5BQ2Lfwk549SUnIplMDSFH3DGzs/iUIKVZp4gO3QnAcsSw zz5g== X-Gm-Message-State: APjAAAXp6BqhumbOZnN1iTPuWSw4NJmXEnd+9Ii4CUULr1Nx2IKXhN1O eq2lgJ9SFkhF/in9HSA2Ky4ynkWY X-Google-Smtp-Source: APXvYqwGiyMy8eMn/sTii/KylpOf62hiAgXfncl5aJmxVdCNifVyYj0cQeQn46s/pEa6BRe4wDHoxA== X-Received: by 2002:a2e:b4ba:: with SMTP id q26mr3646894ljm.60.1573671353671; Wed, 13 Nov 2019 10:55:53 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:52 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 7/8] builtin/config: warn if "value_regex" doesn't canonicalize as boolean Date: Wed, 13 Nov 2019 19:55:06 +0100 Message-Id: <0f48ab4fc344b3cc226d0a45d13530022208ff3e.1573670565.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With `--type=bool`, we try to canonicalize the "value_regex". If it doesn't canonicalize, we continue and handle the "value_regex" as an ordinary regex. This is deliberate -- we do not want to cause existing scripts to fail. This does mean that users might be at risk of missing out on config values depending on which representation they use in their config file: $ git config foo.bar on $ git config foo.baz true $ git config --type=bool --get-regex "foo\.*" tru foo.baz true $ # oops! missing foo.bar Let's start warning when the "value_regex" doesn't look like a boolean. Document our intention of eventually requiring the canonicalization to pass. Signed-off-by: Martin Ågren --- Documentation/git-config.txt | 2 ++ builtin/config.c | 2 ++ t/t1300-config.sh | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 864375b1ec..43310ca3c0 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -46,6 +46,8 @@ unset an existing `--type` specifier with `--no-type`. With `--type=bool` or `--type=bool-or-int`, if `value_regex` is given and canonicalizes to a boolean value, it matches all entries that canonicalize to the same boolean value. +The support for non-canonicalizing values of `value_regex` with +`--type=bool` is deprecated. When reading, the values are read from the system, global and repository local configuration files by default, and options diff --git a/builtin/config.c b/builtin/config.c index 4e274d4867..2af62b95f8 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -303,6 +303,8 @@ static int handle_value_regex(const char *regex_) cmd_line_value.boolean = boolval; return 0; } + warning(_("value_regex '%s' cannot be canonicalized " + "to a boolean value"), regex_); } if (type == TYPE_BOOL_OR_INT) { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f0e9a21dc4..3e067c211d 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -466,8 +466,9 @@ test_expect_success '--get canonicalizes integer value_regex with --type=bool' ' test_expect_success '--type=bool with "non-bool" value_regex' ' echo true >expect && - git config --type=bool --get foo.y4 "t.*" >output && + git config --type=bool --get foo.y4 "t.*" >output 2>err && test_cmp expect output && + test_i18ngrep "cannot be canonicalized" err && test_must_fail git config --type=bool --get foo.y4 "T.*" >output && test_must_be_empty output ' From patchwork Wed Nov 13 18:55:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 11242697 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 878D9109A for ; Wed, 13 Nov 2019 18:56:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59D52206E1 for ; Wed, 13 Nov 2019 18:56:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bhqF1TG3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbfKMS4C (ORCPT ); Wed, 13 Nov 2019 13:56:02 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46904 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbfKMS4B (ORCPT ); Wed, 13 Nov 2019 13:56:01 -0500 Received: by mail-lj1-f194.google.com with SMTP id e9so3758604ljp.13 for ; Wed, 13 Nov 2019 10:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VY4OGchn4ttzxkTbz7bR4pwBhl0Mc2MoXTOBIK/hNjk=; b=bhqF1TG3fR3f1gJ0gzQ5iJebplbI9HOSiu9r1K3L4bHgA+YgdOP3VIpLv8jh0PqlXJ jaHcEvhWUDsUPWz5YTHNXN4qfe1V42bMtLG5uDZQcJgQFU08Tn2KUPBcqGc5v7ilPOmK Aq4LM7u5zJidCw6vNNkCgLdqGK+TaRBEj4l8R20C3wmDtGiOsKQPbgvLNq7DNMxBbPul 0rnL5hSJnJjXYfIOM+aa40dybJQYDSGD/O74k0OXYJ+OtQn11kSRg413LTyzjeMqVx2U Eyh/2s+82hxmBGCKmhVFuezEnt7EcLkc1cgxJtOGYW8BGQM0QFscIHA2hzEgiYQjq+RA qL5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VY4OGchn4ttzxkTbz7bR4pwBhl0Mc2MoXTOBIK/hNjk=; b=jPinVADL9rqu5YrztwBLrVHxPfzr4IWBK0egs3xT/mI8TItfM7SchjJRwCjgCkjqbD XCdOHfmSXiC78UrszjjxKYD9U2UC6QjdqjqJkSSAyKkfabblxgvP88yhQv8AhO6LE2nQ uIfdSowVF1ZNYxMng4Zaybt2UtV5tVlD+aClje8khqBBKdNYr6Fuc3oXkwF2XccpPC2t rTW27bUSxavj9BMQMHpcDKzvjbLrLPa7WlOlz5ACCbZ2OxGHsHeCOsOyjTNsmtnMXM6R 3cfNke4zQT9LqQTZNA2VHXBgOPPSoHwfojaW5wpU0VbagpNnFs+Ww7MCV1M2D1TIGbLr e1Jw== X-Gm-Message-State: APjAAAW4ONmSPPPOZlqhDDX4WaNGqbcpPK6/hPGTeMBf4Ipx+j0GPhTu R7P/gznHUDSrrs71Zi/sBtYSOQle X-Google-Smtp-Source: APXvYqzM+1gbaLtoy5QVKh7UuvGwWB/gNqMYlbxMUH5R8xyt8n2AaDMXnkqSz4XvlQVXvCC5AsaAsQ== X-Received: by 2002:a2e:9f4c:: with SMTP id v12mr3272790ljk.167.1573671359316; Wed, 13 Nov 2019 10:55:59 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id c24sm1422765lfm.20.2019.11.13.10.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 10:55:58 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Junio C Hamano Subject: [PATCH 8/8] builtin/config: die if "value_regex" doesn't canonicalize as boolean Date: Wed, 13 Nov 2019 19:55:07 +0100 Message-Id: <309960f7d4bd790a11c31b727475134368eb6a10.1573670565.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This completes the transition from handling a "value_regexp" with `--type=bool` as a regex, to handling it on the assumption that it canonicalizes to a boolean value. Signed-off-by: Martin Ågren --- Documentation/git-config.txt | 5 ++--- builtin/config.c | 4 ++-- t/t1300-config.sh | 5 +---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 43310ca3c0..598915eac6 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -43,11 +43,10 @@ outgoing values are canonicalize-able under the given . If no `--type=` is given, no canonicalization will be performed. Callers may unset an existing `--type` specifier with `--no-type`. -With `--type=bool` or `--type=bool-or-int`, if `value_regex` is given +With `--type=bool-or-int`, if `value_regex` is given and canonicalizes to a boolean value, it matches all entries that canonicalize to the same boolean value. -The support for non-canonicalizing values of `value_regex` with -`--type=bool` is deprecated. +With `--type=bool`, `value_regex` (if given) must canonicalize. When reading, the values are read from the system, global and repository local configuration files by default, and options diff --git a/builtin/config.c b/builtin/config.c index 2af62b95f8..837766cfb3 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -303,8 +303,8 @@ static int handle_value_regex(const char *regex_) cmd_line_value.boolean = boolval; return 0; } - warning(_("value_regex '%s' cannot be canonicalized " - "to a boolean value"), regex_); + die(_("value_regex '%s' cannot be canonicalized " + "to a boolean value"), regex_); } if (type == TYPE_BOOL_OR_INT) { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 3e067c211d..9eccc255db 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -465,11 +465,8 @@ test_expect_success '--get canonicalizes integer value_regex with --type=bool' ' ' test_expect_success '--type=bool with "non-bool" value_regex' ' - echo true >expect && - git config --type=bool --get foo.y4 "t.*" >output 2>err && - test_cmp expect output && + test_must_fail git config --type=bool --get foo.y4 t >output 2>err && test_i18ngrep "cannot be canonicalized" err && - test_must_fail git config --type=bool --get foo.y4 "T.*" >output && test_must_be_empty output '