From patchwork Mon Nov 23 16:05:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90ADDC2D0E4 for ; Mon, 23 Nov 2020 16:05:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 339FC20782 for ; Mon, 23 Nov 2020 16:05:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sJqYv7at" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389726AbgKWQFN (ORCPT ); Mon, 23 Nov 2020 11:05:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732684AbgKWQFM (ORCPT ); Mon, 23 Nov 2020 11:05:12 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F317C061A4D for ; Mon, 23 Nov 2020 08:05:12 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id r17so19172700wrw.1 for ; Mon, 23 Nov 2020 08:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=BLK6DLFzBwpO+LuZ0Ay+j8PSkKIKU2e15/ivFjqhNC0=; b=sJqYv7ataN7TJTF3/gdOZ+enzeYlrtQ0W7B2LcC7mIAme6EJ4XKN2SbUlMOp50d+Oo wUien6GDrt94YqW1wlqXyg4SA36cnCurRI7QzMkOmjcIu9j3fXFbnB0cKQIObsz55y03 q88ZV0OXnW91S9wRcRjtnKPBSg41e2NLHPAUO9u8ZhJQj2/+EcgR52/TAKmfwzKUmRaq ziAYA9F5PtbCKn4k2pWIR5k4Q+19+1wBO+LK1RHmgHo02xWd7cAjGPsJ71+XTOERfE53 CdzhqnLGBg3t6cQKnjAwPXlbZ/W5Rsf7jayed68g7DlCE57wpYbULYA0mTC6zB7LpFM3 aIeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=BLK6DLFzBwpO+LuZ0Ay+j8PSkKIKU2e15/ivFjqhNC0=; b=PTDH3ajtjLm9/O9Gu+1Fb6ixIJo/cVPfm78MeCFac9f/R5bslp7gZHWT4D1R+r4sj6 4RQurqdYhdQD94/wzQjIUOEWTwpUg2TyIJXhqs0lFedcBAg5nLH55KYvhN/t3lnCb8Ek uH1ORvKehzSrSRwcOm0O/Clk2piwXunMrQZx7OtNanvOkzv8c/caQJMnnJLlSc7M2yhC nzNMsavmvVXs2kanQ6riE5NcdnkG3YcvfVr52lBXc2ZvxMlhYEzNQQTgXf1zJ/AuAsRv Awy6nLtd5OreRbnrL+OJyeNiFh8/M45e8si0cwGjtp4n3/U2DAHYd2vKGZr6hKpkoiH6 Mhug== X-Gm-Message-State: AOAM533cBzDb6LyXn40bu6/DrvRYsZzYtQtNzGxYY3WDIYPApXwddAV+ +lg3hlB1sV3vRtgFVTykKeqETkh921I= X-Google-Smtp-Source: ABdhPJzMkHJ71NVKDbnJ4zotTzuC4Qj3X/AjJy9G2kRAIQ8BJo/NFsvwH89i78PlcaAyefR3Hdgwaw== X-Received: by 2002:a5d:62cb:: with SMTP id o11mr374433wrv.25.1606147510956; Mon, 23 Nov 2020 08:05:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t136sm17802156wmt.18.2020.11.23.08.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:10 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:01 +0000 Subject: [PATCH v2 1/7] t1300: test "set all" mode with value_regex Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Without additional modifiers, 'git config' attempts to set a single value in the .git/config file. When the value_regex parameter is supplied, this command behaves in a non-trivial manner. Consider 'git config key value value_regex'. The expected behavior is as follows: 1. If there are multiple existing values that match 'value_regex', then the command fails. Users should use --replace-all instead. 2. If there is one existing value that matches 'value_regex', then the new config has one entry where 'key=value'. 3. If there is no existing values match 'value_regex', then the 'key=value' pair is appended, making this 'key' a multi-valued config setting. Add a test that demonstrates these options. Break from the existing pattern in t1300-config.sh to use 'git config --file=' instead of modifying .git/config directly. Also use 'git config --file= --list' for config state comparison instead of the config file format. Signed-off-by: Derrick Stolee --- t/t1300-config.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 97ebfe1f9d..19836ec83b 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1914,4 +1914,36 @@ test_expect_success '--replace-all does not invent newlines' ' test_cmp expect .git/config ' +test_expect_success 'set all config with value_regex' ' + git config --file=initial abc.key one && + + cp initial config && + git config --file=config abc.key two a+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + EOF + test_cmp expect actual && + + test_must_fail git config --file=config abc.key three o+ 2>err && + test_i18ngrep "has multiple values" err && + git config --file=config abc.key three a+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + abc.key=three + EOF + test_cmp expect actual && + + cp initial config && + git config --file=config abc.key three o+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=three + EOF + test_cmp expect actual +' + test_done From patchwork Mon Nov 23 16:05:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4474BC6379D for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02EDD2078E for ; Mon, 23 Nov 2020 16:05:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fWenVaJM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389799AbgKWQFR (ORCPT ); Mon, 23 Nov 2020 11:05:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732684AbgKWQFQ (ORCPT ); Mon, 23 Nov 2020 11:05:16 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9113EC0613CF for ; Mon, 23 Nov 2020 08:05:16 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id h21so17737272wmb.2 for ; Mon, 23 Nov 2020 08:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Fg/2Sdn3NbNMM0c7lOw6XNDPCLjgLRzyoI03OVgAd0k=; b=fWenVaJM0tbv+uWjrx+dGXz5uLQ8Trgxn4y1pCBtcGEp8616C2o6OQ8lKSvViZI+fv zW7Q5Wl/Q9hqLCCxGvN540OwVVnt2LeP+UQNRDKOXFvX5b2BhNj0ug5JEN+zroDl0AUD Ul1eV1G/sbT13juzemACJdRGwAJPqt5W/cEFATwGP4CLOBJYXiTivVVJ+nU7L0jzi1Dx GlAG9xJCiO4Pzim/INheA39l+Qae5Pzca8q5HYI998AuFGwPE5tn0MVdoWBlyCeqltNd 8D27sh+sgaNgiKwweTWjnirqh6dpl0+guDW2hxY332YooCgD8DkyEY1gmNJ/jH/SxGbh PFNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Fg/2Sdn3NbNMM0c7lOw6XNDPCLjgLRzyoI03OVgAd0k=; b=IMMOUABSEh8EsFZ5U3NvvGiLxXsVoT8EPJOvB7p7BTOFPhexIegBzigRrIH97/jkC/ dp019bfcF4ci6vgv6nA4bdtBjkvAU2CE8C5xI4iK5sQMg4gmj4MVe9XsqE8k/01+lRFw lQ0JfGQui3AsGtnLSTw/GQXmBbP/kGRWvZKV23AOl8mq6F6P/J9O5HHk3QeB3q3+QdC7 vf4ZyEY0kSiS6P1+8VkrxEZU0OG08u48pa9Voeb0jBGGfl7GqBlcfCPyA8vB3Cj7R7rZ z6TLEeKfkH1Xn4K31Mt/HSeqxeTmWpW7K1BKQJOxasxEMB7blfUsdAQ/YkJN5xHByVMX 5m1g== X-Gm-Message-State: AOAM530a/i4MksT739P5Bsd4RWVEs8EzOUpYiSVQCq8cof6YAObrfiOs n4z1A8Fo3uFKfhKHwGrsIcyCqk/SEvU= X-Google-Smtp-Source: ABdhPJwVaCOixj4SL//FN9HLA7v9ubwqtXAsCtD7SW5AwNzVk1EGF/Jetn7i9js8/rfWHNo9cBnsbw== X-Received: by 2002:a1c:a445:: with SMTP id n66mr25545165wme.51.1606147512096; Mon, 23 Nov 2020 08:05:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i11sm20165777wrm.1.2020.11.23.08.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:11 -0800 (PST) Message-Id: <829d0ccd8c6ae52e78eda52b15283867a0be673e.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:02 +0000 Subject: [PATCH v2 2/7] t1300: add test for --replace-all with value_regex Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The --replace-all option was added in 4ddba79d (git-config-set: add more options) but was not tested along with the 'value_regex' parameter. Since we will be updating this option to optionally treat 'value_regex' as a fixed string, let's add a test here that documents the current behavior. Signed-off-by: Derrick Stolee Reviewed-by: Emily Shaffer --- t/t1300-config.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 19836ec83b..8783767d4f 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1946,4 +1946,18 @@ test_expect_success 'set all config with value_regex' ' test_cmp expect actual ' +test_expect_success '--replace-all and value_regex' ' + rm -f config && + git config --file=config --add abc.key one && + 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 && + cat >expect <<-\EOF && + abc.key=four + abc.key=three + EOF + test_cmp expect actual +' + test_done From patchwork Mon Nov 23 16:05:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 227DFC63697 for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B90652076E for ; Mon, 23 Nov 2020 16:05:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nAI0Ynrc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389741AbgKWQFQ (ORCPT ); Mon, 23 Nov 2020 11:05:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732684AbgKWQFP (ORCPT ); Mon, 23 Nov 2020 11:05:15 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC827C0613CF for ; Mon, 23 Nov 2020 08:05:14 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id l1so19091723wrb.9 for ; Mon, 23 Nov 2020 08:05:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=bdKDxDb9RzI+vgaBN2FGE+rXi/8HQWGBhbOztKwyx2k=; b=nAI0YnrcSDdzUdLLHOSWKMW7B7QJrrsCNZbvN4e8EZpY84MAQLzsFZznpqj4TsaSEn g6DlYlMntJNx1vAhwPnYY06Z2WPRUDreoccGiFUc5Q1whx8AtBKNzzd6T+IFwdb6Thgz DB1dUbvPn0BZN+I90a1sleZ0zlxeXKAk9QqX4GH6g781EJHY7sc+6iqoVxTs9hWMOxst rFup7aAi0BllzDFOEn1fOWPpazP0TfnAQKNnsTLYB4hdlCq2xQaTVTD6FQITdNjUPzhL hBfXPYQjw9FsBofbarDGclbDZlBUCVxja+THvU3Alo2YNbNH8ltvrYhy5m5r7ChCRnB7 10Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=bdKDxDb9RzI+vgaBN2FGE+rXi/8HQWGBhbOztKwyx2k=; b=PuKIYLcXvwluMNZrmLYcmItXSbaqi+K2bAjUJ6c3z1/kyhtg9hUfWHxeD8YhZ+jaOq yiys9hSMKY9wvG89rCh6O9j/74oxFi6G2qT8ZnlOlxcrlLL3p9iP1GxOmY5oEq9Lme/r mT7igTxKpTCPxc5+bj5PlD1/E+KFXE3ViPkVwPpZTzkKBuJX5rFywm0Azlx+0+0L4lOr 2fPybmsvP9lwhU5UTnaCCOLRbOjp1nzgYjwAe5sJEVPRipKIvii0yFRXIw3osSWdxQQW f+bZq20o+fRsNJbYbLhHd8Hg18RoT2X/0sQVe8ygWBE2QFr+/fc0RAy2GM5k8MlYU8p7 +KFw== X-Gm-Message-State: AOAM5331+w5QeUgoR1lXzwxjDcCkR7LaAk/49ECFYSQ7n9BQI2OwNpRl gQhkZohWaVGsaduCerDMyCa6muXV35Y= X-Google-Smtp-Source: ABdhPJwv52ocjCvP0ZgRPQQJaPZFnqFeYsbJbqtCRkGCndfdPFEmo2LAoesH1CLbIktXClpyVFDsag== X-Received: by 2002:a5d:514f:: with SMTP id u15mr309881wrt.385.1606147513111; Mon, 23 Nov 2020 08:05:13 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z17sm8968473wmf.15.2020.11.23.08.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:12 -0800 (PST) Message-Id: <0c152faa00881483db0a59f4c5bc7204ebed8966.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:03 +0000 Subject: [PATCH v2 3/7] config: convert multi_replace to flags Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee We will extend the flexibility of the config API. Before doing so, let's take an existing 'int multi_replace' parameter and replace it with a new 'unsigned flags' parameter that can take multiple options as a bit field. Update all callers that specified multi_replace to now specify the CONFIG_FLAGS_MULTI_REPLACE flag. To add more clarity, extend the documentation of git_config_set_multivar_in_file() including a clear labeling of its arguments. Other config API methods in config.h require only a change of the final parameter from 'int' to 'unsigned'. Signed-off-by: Derrick Stolee Reviewed-by: Emily Shaffer --- builtin/branch.c | 4 ++-- builtin/config.c | 6 ++++-- builtin/remote.c | 8 +++++--- config.c | 24 ++++++++++++------------ config.h | 29 ++++++++++++++++++++++------- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index e82301fb1b..5ce3844d22 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -829,10 +829,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix) die(_("Branch '%s' has no upstream information"), branch->name); strbuf_addf(&buf, "branch.%s.remote", branch->name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.merge", branch->name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_release(&buf); } else if (argc > 0 && argc <= 2) { if (filter.kind != FILTER_REFS_BRANCHES) diff --git a/builtin/config.c b/builtin/config.c index 5e39f61885..e7c7f3d455 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -823,7 +823,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) value = normalize_value(argv[0], argv[1]); UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], 1); + argv[0], value, argv[2], + CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); @@ -859,7 +860,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_write(); check_argc(argc, 1, 2); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], 1); + argv[0], NULL, argv[1], + CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { int ret; diff --git a/builtin/remote.c b/builtin/remote.c index c8240e9fcd..29b1652975 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -708,7 +708,7 @@ static int mv(int argc, const char **argv) strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); for (i = 0; i < oldremote->fetch.raw_nr; i++) { char *ptr; @@ -1485,7 +1485,8 @@ static int update(int argc, const char **argv) static int remove_all_fetch_refspecs(const char *key) { - return git_config_set_multivar_gently(key, NULL, NULL, 1); + return git_config_set_multivar_gently(key, NULL, NULL, + CONFIG_FLAGS_MULTI_REPLACE); } static void add_branches(struct remote *remote, const char **branches, @@ -1674,7 +1675,8 @@ static int set_url(int argc, const char **argv) if (!delete_mode) git_config_set_multivar(name_buf.buf, newurl, oldurl, 0); else - git_config_set_multivar(name_buf.buf, NULL, oldurl, 1); + git_config_set_multivar(name_buf.buf, NULL, oldurl, + CONFIG_FLAGS_MULTI_REPLACE); out: strbuf_release(&name_buf); return 0; diff --git a/config.c b/config.c index 2b79fe76ad..096f2eae0d 100644 --- a/config.c +++ b/config.c @@ -2716,9 +2716,9 @@ void git_config_set(const char *key, const char *value) * if value_regex!=NULL, disregard key/value pairs where value does not match. * if value_regex==CONFIG_REGEX_NONE, do not match any existing values * (only add a new one) - * if multi_replace==0, nothing, or only one matching key/value is replaced, - * else all matching key/values (regardless how many) are removed, - * before the new pair is written. + * if (flags & CONFIG_FLAGS_MULTI_REPLACE) == 0, at most one matching + * key/value is replaced, else all matching key/values (regardless + * how many) are removed, before the new pair is written. * * Returns 0 on success. * @@ -2739,7 +2739,7 @@ void git_config_set(const char *key, const char *value) int git_config_set_multivar_in_file_gently(const char *config_filename, const char *key, const char *value, const char *value_regex, - int multi_replace) + unsigned flags) { int fd = -1, in_fd = -1; int ret; @@ -2756,7 +2756,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, if (ret) goto out_free; - store.multi_replace = multi_replace; + store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0; if (!config_filename) config_filename = filename_buf = git_pathdup("config"); @@ -2845,7 +2845,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, /* if nothing to unset, or too many matches, error out */ if ((store.seen_nr == 0 && value == NULL) || - (store.seen_nr > 1 && multi_replace == 0)) { + (store.seen_nr > 1 && !store.multi_replace)) { ret = CONFIG_NOTHING_SET; goto out_free; } @@ -2984,10 +2984,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, void git_config_set_multivar_in_file(const char *config_filename, const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, unsigned flags) { if (!git_config_set_multivar_in_file_gently(config_filename, key, value, - value_regex, multi_replace)) + value_regex, flags)) return; if (value) die(_("could not set '%s' to '%s'"), key, value); @@ -2996,17 +2996,17 @@ void git_config_set_multivar_in_file(const char *config_filename, } int git_config_set_multivar_gently(const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, unsigned flags) { return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex, - multi_replace); + flags); } void git_config_set_multivar(const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, unsigned flags) { git_config_set_multivar_in_file(NULL, key, value, value_regex, - multi_replace); + flags); } static int section_name_match (const char *buf, const char *name) diff --git a/config.h b/config.h index 060874488f..80844604ab 100644 --- a/config.h +++ b/config.h @@ -256,9 +256,22 @@ void git_config_set(const char *, const char *); int git_config_parse_key(const char *, char **, size_t *); int git_config_key_is_valid(const char *key); -int git_config_set_multivar_gently(const char *, const char *, const char *, int); -void git_config_set_multivar(const char *, const char *, const char *, int); -int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int); + +/* + * The following macros specify flag bits that alter the behavior + * of the git_config_set_multivar*() methods. + */ + +/* + * When CONFIG_FLAGS_MULTI_REPLACE is specified, all matching key/values + * are removed before a new pair is written. If the flag is not present, + * then set operations replace only the first match. + */ +#define CONFIG_FLAGS_MULTI_REPLACE (1 << 0) + +int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned); +void git_config_set_multivar(const char *, const char *, const char *, unsigned); +int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, unsigned); /** * takes four parameters: @@ -276,13 +289,15 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha * - the value regex, as a string. It will disregard key/value pairs where value * does not match. * - * - a multi_replace value, as an int. If value is equal to zero, nothing or only - * one matching key/value is replaced, else all matching key/values (regardless - * how many) are removed, before the new pair is written. + * - a flags value with bits corresponding to the CONFIG_FLAG_* macros. * * It returns 0 on success. */ -void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); +void git_config_set_multivar_in_file(const char *config_filename, + const char *key, + const char *value, + const char *value_regex, + unsigned flags); /** * rename or remove sections in the config file From patchwork Mon Nov 23 16:05:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D3A8C63798 for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C28E2080A for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HO1810yL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388368AbgKWQFW (ORCPT ); Mon, 23 Nov 2020 11:05:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732604AbgKWQFV (ORCPT ); Mon, 23 Nov 2020 11:05:21 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9CC2C0613CF for ; Mon, 23 Nov 2020 08:05:19 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a65so17747176wme.1 for ; Mon, 23 Nov 2020 08:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=kyGJkfWKndxqyK4ZGyfS8HYEi0adgfoui48H66tiSN4=; b=HO1810yLQv4ofXvYkiDJiW2Jhzh2pmRJctiaIzX2pizdxDEJOX1O/gpfCZjsGK10Md F0tYwYRYcc/aKgJj+ulnDbLYn2Qf1tPq2FtxZDmS0mP8TRwQey/eKdSF5vA8FWA/VkzD n7QK2KWCzzu0xVTXrhr/2xK2E+yUUFWDLVWPFpGLUkGeYPlQ4M8ZC/M/IMfwxyjxjmaq 6bUOGKNK1/5gMToXN/1bB9Xm91X3JVLC5AJuOSn3hya1nCJ8j28hwhAW1mhSBeHrqwnk 2cPpU6lSy5avCUh9gObgiz6iG1SP5dwwsWirmOfo9O2iQAz87dnDENiprvyAb3hPne5S XVZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=kyGJkfWKndxqyK4ZGyfS8HYEi0adgfoui48H66tiSN4=; b=SOi2Fi9ddn3cn/j5R0MlD2Anb9kf9YxgYBh4DlIuzZIu5DD0Fk+T9+RoMB4TnuGKQZ 04AQUr8xQQBS1WgQZzmIFQBoDAaMqogvFqH1Wp50efFAiR7i3GiKAM5/fSVjBR8UAUjn LiKHHfvkywswqg5re7KJJ2Aq7twRT3JPzoDZ2bmyAITmGByka/5zbMQ1hFfMhrNjU1fB 2quQrBxaUzBebiFBe0Y7UkW6XvOXfvRaXEUn79Yg0qT/KIPGak2rLuYxnhGdM4Xr9pn2 qQe2MO6GacXgBrcAPab2Ajor5aAv0o4Hc32FOwLexx0Pe4iWeJUXizhleAlVBv/zFZU1 8ZrQ== X-Gm-Message-State: AOAM533uXJy5eWHCyOFAWsmINn0mzAJgJrcYZ+6NRdvDv9otisb7JEsy zVa6ADNwgL39x0VwzDIUMb1ohXhjZ0o= X-Google-Smtp-Source: ABdhPJyP9Hq0SJMweINQ97HNk22y5dru01g6fPN57XdE2REQyo+oxtBspY92CFcx84J+TR24FZVGNA== X-Received: by 2002:a1c:32c6:: with SMTP id y189mr25350911wmy.133.1606147514374; Mon, 23 Nov 2020 08:05:14 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m20sm21895071wrg.79.2020.11.23.08.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:13 -0800 (PST) Message-Id: <0e6a7371ed4696f6cc85df07466fb6c20d58d62e.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:04 +0000 Subject: [PATCH v2 4/7] config: add --fixed-value option, un-implemented Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'git config' builtin takes a 'value_regex' parameter for several actions. This can cause confusion when expecting exact value matches instead of regex matches, especially when the input string contains glob characters. While callers can escape the patterns themselves, it would be more friendly to allow an argument to disable the pattern matching in favor of an exact string match. Add a new '--fixed-value' option that does not currently change the behavior. The implementation will follow for each appropriate action. For now, check and test that --fixed-value will abort the command when included with an incompatible action or without a 'value_regex' argument. The name '--fixed-value' was chosen over something simpler like '--fixed' because some commands allow regular expressions on the key in addition to the value. Signed-off-by: Derrick Stolee --- Documentation/git-config.txt | 20 +++++++++++++------- builtin/config.c | 26 ++++++++++++++++++++++++++ t/t1300-config.sh | 23 +++++++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 7573160f21..d4bb928ea7 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,15 +9,15 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]] +'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]] 'git config' [] [--type=] --add name value -'git config' [] [--type=] --replace-all name value [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get name [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get-all name [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value_regex] +'git config' [] [--type=] [--fixed-value] --replace-all name value [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp name_regex [value_regex] 'git config' [] [--type=] [-z|--null] --get-urlmatch name URL -'git config' [] --unset name [value_regex] -'git config' [] --unset-all name [value_regex] +'git config' [] [--fixed-value] --unset name [value_regex] +'git config' [] [--fixed-value] --unset-all name [value_regex] 'git config' [] --rename-section old_name new_name 'git config' [] --remove-section name 'git config' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list @@ -165,6 +165,12 @@ See also <>. --list:: List all variables set in config file, along with their values. +--fixed-value:: + When used with the `value_regex` argument, treat `value_regex` as + an exact string instead of a regular expression. This will restrict + the name/value pairs that are matched to only those where the value + is exactly equal to the `value_regex`. + --type :: 'git config' will ensure that any input or output is valid under the given type constraint(s), and will canonicalize outgoing values in ``'s diff --git a/builtin/config.c b/builtin/config.c index e7c7f3d455..bfb55a96df 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -34,6 +34,7 @@ static int respect_includes_opt = -1; static struct config_options config_options; static int show_origin; static int show_scope; +static int fixed_value; #define ACTION_GET (1<<0) #define ACTION_GET_ALL (1<<1) @@ -141,6 +142,7 @@ 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 matching values")), 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), @@ -745,6 +747,30 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } + if (fixed_value) { + int allowed_usage = 0; + + switch (actions) { + case ACTION_GET: + case ACTION_GET_ALL: + case ACTION_GET_REGEXP: + case ACTION_UNSET: + case ACTION_UNSET_ALL: + allowed_usage = argc > 1 && !!argv[1]; + break; + + case ACTION_SET_ALL: + case ACTION_REPLACE_ALL: + allowed_usage = argc > 2 && !!argv[2]; + break; + } + + if (!allowed_usage) { + error(_("--fixed-value only applies with 'value_regex'")); + usage_builtin_config(); + } + } + if (actions & PAGING_ACTIONS) setup_auto_pager("config", 1); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 8783767d4f..6dc8117241 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1960,4 +1960,27 @@ test_expect_success '--replace-all and value_regex' ' test_cmp expect actual ' +test_expect_success 'refuse --fixed-value for incompatible actions' ' + git config --file=config dev.null bogus && + + # These modes do not allow --fixed-value at all + 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 --file=config --fixed-value --remove-section dev && + test_must_fail git config --file=config --fixed-value --list && + 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 && + + # These modes complain when --fixed-value has no value_regex + 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 --file=config --fixed-value --unset dev.null && + test_must_fail git config --file=config --fixed-value --unset-all dev.null +' + test_done From patchwork Mon Nov 23 16:05:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA31C6379F for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7174F20782 for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E8Sv0g9J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732874AbgKWQFV (ORCPT ); Mon, 23 Nov 2020 11:05:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731727AbgKWQFV (ORCPT ); Mon, 23 Nov 2020 11:05:21 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01048C061A4D for ; Mon, 23 Nov 2020 08:05:21 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id h21so17737485wmb.2 for ; Mon, 23 Nov 2020 08:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=NTmAkIple9ObMNDjIA5o3xByUE1KUlDLtweBnHhzkPc=; b=E8Sv0g9Ji6HWMnCgGQw3RAzSKR1fZGwiylda6hNMrD2Lr/g3q0VmSImWWyecrohMpV BVg4XIDjmbcikYblgMVCM8vNXozSUH6w9bHyfGlHs3AO2JATwkgkzQN0wwgPSGHxEUID GNWbf9lhtZKGuC8YUDsShrRlZl0VTKrw+85w47jMZbGtDVirmBAd+YumlV724TiSP36G nLQWwKrBIxqDn6NXQPiboh79STXSkGKKhO663V/tQDekg1eMyujJ2sEJal1BoufwKACp urV9tMwMnXKMYdHByqt8N8/YkCKmoBx7ObciqmwMFzw1fdLCar3vivN6I7b7jE56rmRp bI3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=NTmAkIple9ObMNDjIA5o3xByUE1KUlDLtweBnHhzkPc=; b=i7OCPbuh7wd8YUCK7vNv9J38jpASxhrWTBGjtgXE71o8l62E4xEtazNHQKc/9tu380 qMoJ7iP2VWpkNRSHRCzvXx92rMErAoe6y8/bGujD5+HlVPF8MPEvrBgqkjmJMG5b5jND gcPphqDjcgKL5UBuZkxWE2isCTkPRscsWLGER4ukcjrjlpf3lTU42Nd/P0muQM0gz/Gb 9H1tJyrUyVi34Ds4/Ni4RkEc2eKAhDyds2EdKGyKA2a2R67ZTgNJRChZPdqESjoOdgWU TPIdKFFHpsAKsjXebc/zTnZ/GGCFrKfpsTb+MLLFwlWos9JHFL8BE7p8aNwB9Ux/AyNn JQlA== X-Gm-Message-State: AOAM531eeC9QuA7PPAX1dKbWcUCRX/H8hAFiK2Ldjw7zfm/LyJsLU4oa B87GpZnVd6YLabLZPP3RODK11HBpHmo= X-Google-Smtp-Source: ABdhPJycb+UwLSQopTOEhSi1Em+6mcURdvTIJ6fvWKh30UAJxnJThg6kHNDJ6x1wgatz9zfK+HQQyw== X-Received: by 2002:a1c:2b03:: with SMTP id r3mr23649977wmr.184.1606147519385; Mon, 23 Nov 2020 08:05:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4sm19502024wmc.46.2020.11.23.08.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:18 -0800 (PST) Message-Id: <39718048cd8f5be053a13ff73f531e3400b80b25.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:05 +0000 Subject: [PATCH v2 5/7] config: plumb --fixed-value into config API Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The git_config_set_multivar_in_file_gently() and related methods now take a 'flags' bitfield, so add a new bit representing the --fixed-value option from 'git config'. This alters the purpose of the value_regex parameter to be an exact string match. This requires some initialization changes in git_config_set_multivar_in_file_gently() and a new strcmp() call in the matches() method. The new CONFIG_FLAGS_FIXED_VALUE flag is initialized in builtin/config.c based on the --fixed-value option, and that needs to be updated in several callers. This patch only affects some of the modes of 'git config', and the rest will be completed in the next change. Signed-off-by: Derrick Stolee --- builtin/config.c | 16 ++++++++----- config.c | 5 +++++ config.h | 7 ++++++ t/t1300-config.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index bfb55a96df..3e49e04411 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -616,6 +616,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; char *value; + int flags = 0; given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); @@ -769,6 +770,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) error(_("--fixed-value only applies with 'value_regex'")); usage_builtin_config(); } + + flags = CONFIG_FLAGS_FIXED_VALUE; } if (actions & PAGING_ACTIONS) @@ -832,7 +835,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) value = normalize_value(argv[0], argv[1]); UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], 0); + argv[0], value, argv[2], + flags); } else if (actions == ACTION_ADD) { check_write(); @@ -841,7 +845,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, - CONFIG_REGEX_NONE, 0); + CONFIG_REGEX_NONE, + flags); } else if (actions == ACTION_REPLACE_ALL) { check_write(); @@ -850,7 +855,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, argv[2], - CONFIG_FLAGS_MULTI_REPLACE); + flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); @@ -877,7 +882,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); if (argc == 2) return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], 0); + argv[0], NULL, argv[1], + flags); else return git_config_set_in_file_gently(given_config_source.file, argv[0], NULL); @@ -887,7 +893,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], NULL, argv[1], - CONFIG_FLAGS_MULTI_REPLACE); + flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { int ret; diff --git a/config.c b/config.c index 096f2eae0d..64bab2b08e 100644 --- a/config.c +++ b/config.c @@ -2402,6 +2402,7 @@ struct config_store_data { size_t baselen; char *key; int do_not_match; + const char *literal_value; regex_t *value_regex; int multi_replace; struct { @@ -2431,6 +2432,8 @@ static int matches(const char *key, const char *value, { if (strcmp(key, store->key)) return 0; /* not ours */ + if (store->literal_value) + return !strcmp(store->literal_value, value); if (!store->value_regex) return 1; /* always matches */ if (store->value_regex == CONFIG_REGEX_NONE) @@ -2803,6 +2806,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.value_regex = NULL; else if (value_regex == CONFIG_REGEX_NONE) store.value_regex = CONFIG_REGEX_NONE; + else if (flags & CONFIG_FLAGS_FIXED_VALUE) + store.literal_value = value_regex; else { if (value_regex[0] == '!') { store.do_not_match = 1; diff --git a/config.h b/config.h index 80844604ab..977e690be8 100644 --- a/config.h +++ b/config.h @@ -269,6 +269,13 @@ int git_config_key_is_valid(const char *key); */ #define CONFIG_FLAGS_MULTI_REPLACE (1 << 0) +/* + * When CONFIG_FLAGS_FIXED_VALUE is specified, match key/value pairs + * by string comparison (not regex match) to the provided value_regex + * parameter. + */ +#define CONFIG_FLAGS_FIXED_VALUE (1 << 1) + int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned); void git_config_set_multivar(const char *, const char *, const char *, unsigned); int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, unsigned); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 6dc8117241..30e80ae9cb 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1983,4 +1983,61 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --unset-all dev.null ' +test_expect_success '--fixed-value uses exact string matching' ' + GLOB="a+b*c?d[e]f.g" && + rm -f initial && + git config --file=initial fixed.test "$GLOB" && + + cp initial config && + git config --file=config fixed.test bogus "$GLOB" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$GLOB + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + git config --file=config --fixed-value fixed.test bogus "$GLOB" && + git config --file=config --list >actual && + printf "fixed.test=bogus\n" >expect && + test_cmp expect actual && + + cp initial config && + test_must_fail git config --file=config --unset fixed.test "$GLOB" && + git config --file=config --fixed-value --unset fixed.test "$GLOB" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + test_must_fail git config --file=config --unset-all fixed.test "$GLOB" && + git config --file=config --fixed-value --unset-all fixed.test "$GLOB" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + git config --file=config --replace-all fixed.test bogus "$GLOB" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$GLOB + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + git config --file=config --replace-all fixed.test bogus "$GLOB" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$GLOB + fixed.test=bogus + EOF + test_cmp expect actual && + + git config --file=config --fixed-value --replace-all fixed.test bogus "$GLOB" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=bogus + fixed.test=bogus + EOF + test_cmp expect actual +' + test_done From patchwork Mon Nov 23 16:05:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8607C64E75 for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A975E2080A for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E65AuErJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732879AbgKWQFX (ORCPT ); Mon, 23 Nov 2020 11:05:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732604AbgKWQFW (ORCPT ); Mon, 23 Nov 2020 11:05:22 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F32EC0613CF for ; Mon, 23 Nov 2020 08:05:22 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id z7so3294957wrn.3 for ; Mon, 23 Nov 2020 08:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/mzC/Rybws/oBN+M7CZOHIgfp554qaNQMVxBORSPwoY=; b=E65AuErJ8HuVLr+n0kYLofJ8rJ70/HgP44A8gPUIow1BIUmlAgjIfbac6Uwd+b81rg vYjSzHIDEg9WSxiCZv/6W52yquqDTB2ie6GacB1tFW8AovgmPr/3tncaGyxVzYNP43FB tsa0zYHYo2kMst7tMuMyrE0o3OxwlogJV4mDmiaLhuAyaz6ueWCot+AvjDSCNEMfUPBE 6Ep0y6bGgepCbn0ksKgSxUjKroqg6aF9+fQuJxQelgUQDovavh0Cs9BagEbXeHAHo4AO yWKRtmjJPbBqhMza9oVxsGpDgzfd7T/ec1AkJJizv8LA0NfIYPDaHifedOcH0B+egNCO SwfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/mzC/Rybws/oBN+M7CZOHIgfp554qaNQMVxBORSPwoY=; b=sincRnXogDwFtk2eiVAWYfqUUuR7O4sJ4SAb9bGDcRvE4rM2Q2OfGq5gPByYRuBD6M c3N6LEfyc+rm28SgbzJeZHHIZJoomvySHjrx3EX3STn+lPDjR4w1fnbH3sBA1K7DPTS/ n5h4WIloNuQgK4rNm9ud1DqHGtEBlAmuK9l/BwtJFChHhtHBr3Ju6Ntm8BeVkOQ2fjw3 Ee2EIM/6p92AVngUuVNpvDB/ApkhuRm0wMqpLuHSsLw7R35hpeyEMBTCksGPqPYAl+sV /BGkF3C+CyDuZAo65OouuPUeB43YK7I5Fr0ljmbqTzSwQ/oG9uGJCsTCBIW9aQABTqm9 DBAw== X-Gm-Message-State: AOAM532LOuXe3qJhF13gkbBpPDs3Dxc2w6/p/TQiF+Ac1zqtUibq8Omb fnQbfCZBLDXx/sQ0MJ2LEXWdHsKT2UU= X-Google-Smtp-Source: ABdhPJzTe/xyk8tOgSaoOWzTzLognrltgnjexEYONOgu73sGOSdCDcKtrHfpiBDp2Lw0saDw4rl05w== X-Received: by 2002:a5d:67c2:: with SMTP id n2mr348404wrw.139.1606147520789; Mon, 23 Nov 2020 08:05:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm19419245wmf.0.2020.11.23.08.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:20 -0800 (PST) Message-Id: <8e0111c7b4b2c766c61df30c4ae93bd2d724de06.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:06 +0000 Subject: [PATCH v2 6/7] config: implement --fixed-value with --get* Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The config builtin does its own regex matching of values for the --get, --get-all, and --get-regexp modes. Plumb the existing 'flags' parameter to the get_value() method so we can initialize the value_regex argument as a fixed string instead of a regex pattern. Signed-off-by: Derrick Stolee Reviewed-by: Emily Shaffer --- builtin/config.c | 15 ++++++++++----- t/t1300-config.sh | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 3e49e04411..d3772b5efe 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -14,6 +14,7 @@ static const char *const builtin_config_usage[] = { static char *key; static regex_t *key_regexp; +static const char *value_regex; static regex_t *regexp; static int show_keys; static int omit_values; @@ -288,6 +289,8 @@ 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 (fixed_value && strcmp(value_regex, (value_?value_:""))) + return 0; if (regexp != NULL && (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) return 0; @@ -298,7 +301,7 @@ static int collect_config(const char *key_, const char *value_, void *cb) return format_config(&values->items[values->nr++], key_, value_); } -static int get_value(const char *key_, const char *regex_) +static int get_value(const char *key_, const char *regex_, int flags) { int ret = CONFIG_GENERIC_ERROR; struct strbuf_list values = {NULL}; @@ -335,7 +338,9 @@ static int get_value(const char *key_, const char *regex_) } } - if (regex_) { + if (regex_ && (flags & CONFIG_FLAGS_FIXED_VALUE)) + value_regex = regex_; + else if (regex_) { if (regex_[0] == '!') { do_not_match = 1; regex_++; @@ -859,19 +864,19 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_REGEXP) { show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 30e80ae9cb..13211b6bf4 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2040,4 +2040,26 @@ test_expect_success '--fixed-value uses exact string matching' ' test_cmp expect actual ' +test_expect_success '--get and --get-all with --fixed-value' ' + GLOB="a+b*c?d[e]f.g" && + rm -f config && + git config --file=config fixed.test bogus && + git config --file=config --add fixed.test "$GLOB" && + + git config --file=config --get fixed.test bogus && + test_must_fail git config --file=config --get fixed.test "$GLOB" && + git config --file=config --get --fixed-value fixed.test "$GLOB" && + test_must_fail git config --file=config --get --fixed-value fixed.test non-existent && + + git config --file=config --get-all fixed.test bogus && + test_must_fail git config --file=config --get-all fixed.test "$GLOB" && + git config --file=config --get-all --fixed-value fixed.test "$GLOB" && + test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent && + + git config --file=config --get-regexp fixed+ bogus && + test_must_fail git config --file=config --get-regexp fixed+ "$GLOB" && + git config --file=config --get-regexp --fixed-value fixed+ "$GLOB" && + test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent +' + test_done From patchwork Mon Nov 23 16:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11925661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D85EC64E69 for ; Mon, 23 Nov 2020 16:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E196F20782 for ; Mon, 23 Nov 2020 16:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Aj4xx0L6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732605AbgKWQFZ (ORCPT ); Mon, 23 Nov 2020 11:05:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732604AbgKWQFY (ORCPT ); Mon, 23 Nov 2020 11:05:24 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405E4C0613CF for ; Mon, 23 Nov 2020 08:05:23 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id p8so19131226wrx.5 for ; Mon, 23 Nov 2020 08:05:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IY1B6uiZfAzZi0ImRAXBp02jdsBrK+S+g2vny/GnDWw=; b=Aj4xx0L60PQeNJMneDhQ2e5jWS+yI04C/wqbHSX9sqMIZsmXcQHGoYQXVpmjsj3XI6 +8GZPUcdOS1rkhw9QcE1msQt8qxycb0xvWpKqH6NVuM0JrrAgqnyU9VezHI5FRKfteHK tmVV26L7QdEegYYYqkAVSxOUEzwYeg4Gvp0K4KdLRmzXu9oPfRDiOg4dcu4XqaKw8W82 /0KE0L5+hD+ADnnww4FDox/8JYSFeQuTf8wCf9skYzzB0Xr2lyHqhL6f6FWNb4fTatCs EppCGidvvdTQm4N6e9HV0V1chA/UgN9FFOLq5C83JSrnspEPvvjwfD4Xu82D/c157z+e Ld5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IY1B6uiZfAzZi0ImRAXBp02jdsBrK+S+g2vny/GnDWw=; b=c2YStAV7KpvYMTGzgRNHM57hBryvFAS7EMIbQCRNjJgk/d+ngBmWudNMnxGETkpYm5 O961j+4Xf95qS9GSgHOkD1vNGcEDt4f6gLWyvDiitkWNuGDj6XvzVKgq0ep5KP7iFkUc qEnbaNYd+KYHwOCVa4ozYJis6JXUjzRRsjr62jQFUYVoEiYS/zqcBP/m7kNV6iPAM2oh kj4M9mEdC3146o7sjYEbjDs1BYfvDAWFkKj4ykLPkulKMSSMyy9bzJ9w1Zde4/Dri+M3 yukiXqNwSUsvYtSjuir14BeV9CKi7R903nCUMfqfSDp5AHRgMpFuo33nTKZdFdZJ1sjD WTZQ== X-Gm-Message-State: AOAM533f702BOxDfKRJC1KgvTnMXKcsyM1IRm5w8tPM1+CrD79nAUche yh5vdb7vOCuhPCK3sKm5oOshcF1AD8E= X-Google-Smtp-Source: ABdhPJz2NBdTHMcuWiqnS4CuljnuM6jEw/ErdyHY//RII4pbqaWwjyQFgLaIVosgLxqFbd2pm6zn9w== X-Received: by 2002:a5d:534e:: with SMTP id t14mr373019wrv.234.1606147521767; Mon, 23 Nov 2020 08:05:21 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d134sm17534811wmd.8.2020.11.23.08.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 08:05:21 -0800 (PST) Message-Id: <5a3acf811998bb728ce94c69611c237861775142.1606147507.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 16:05:07 +0000 Subject: [PATCH v2 7/7] maintenance: use 'git config --fixed-value' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , "brian m. carlson" , Martin =?utf-8?b?w4Vn?= =?utf-8?b?cmVu?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Derrick Stolee , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When a repository's leading directories contain regex glob characters, the config calls for 'git maintenance register' and 'git maintenance unregister' are not careful enough. Use the new --fixed-value option to direct the config machinery to use exact string matches. This is a more robust option than excaping these arguments in a piecemeal fashion. For the test, require that we are not running on Windows since the '+' character is not allowed on that filesystem. Reported-by: Emily Shaffer Reported-by: Jonathan Nieder Signed-off-by: Derrick Stolee Reviewed-by: Emily Shaffer --- builtin/gc.c | 5 +++-- t/t7900-maintenance.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index e3098ef6a1..6dde3ce1bb 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1452,7 +1452,8 @@ static int maintenance_register(void) git_config_set("maintenance.strategy", "incremental"); config_get.git_cmd = 1; - strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo", + strvec_pushl(&config_get.args, "config", "--global", "--get", + "--fixed-value", "maintenance.repo", the_repository->worktree ? the_repository->worktree : the_repository->gitdir, NULL); @@ -1483,7 +1484,7 @@ static int maintenance_unregister(void) config_unset.git_cmd = 1; strvec_pushl(&config_unset.args, "config", "--global", "--unset", - "maintenance.repo", + "--fixed-value", "maintenance.repo", the_repository->worktree ? the_repository->worktree : the_repository->gitdir, NULL); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 20184e96e1..c4e5564c31 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -367,6 +367,18 @@ test_expect_success 'register and unregister' ' test_cmp before actual ' +test_expect_success !MINGW 'register and unregister with glob characters' ' + GLOB="a+b*c" && + git init "$GLOB" && + git -C "$GLOB" maintenance register && + git config --get-all --show-origin maintenance.repo && + git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$GLOB" && + git -C "$GLOB" maintenance unregister && + test_must_fail git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$GLOB" +' + test_expect_success 'start from empty cron table' ' GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&