From patchwork Wed Nov 25 22:12:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932297 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 55081C6379D for ; Wed, 25 Nov 2020 22:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17A10206D9 for ; Wed, 25 Nov 2020 22:13:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oQsjlvmL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732913AbgKYWNR (ORCPT ); Wed, 25 Nov 2020 17:13:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731806AbgKYWNQ (ORCPT ); Wed, 25 Nov 2020 17:13:16 -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 4070BC0617A7 for ; Wed, 25 Nov 2020 14:13:01 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id h21so199761wmb.2 for ; Wed, 25 Nov 2020 14:13:01 -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=ROAjL97M45dWEQLOqthxa3ji8Wj54z8dFjWGjWjU4yE=; b=oQsjlvmLu9m9cT0dH/btrqSAbV/4/0kKAojHWcBho7LLjvxRmkujwQ58QgkNsdsHgX rHn28AL6kHZeMDn1orKob+0eab5sCRFD+L5VQk6ZEsJjmC+fmkVBaIbubwRXhMb07a8k ijGgLpQvEcGjEnaLwChEPIGC13VdsUGRCLXAw8WndXwCmI8ZQlZbJGoJQ2AJQZZAi192 NI2piasOLFX+zikiraWJ0POziY8cycrGvaRA8k3Sm5VjGRAiHgTNBwHDAZp5mOQn+nvf h10f3bKcr6IB/sLgQ9RK+OL1InFfB4cfWRp7ogVHPqVKK77dfroAf8p94bITrDLMn9xR 5cOw== 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=ROAjL97M45dWEQLOqthxa3ji8Wj54z8dFjWGjWjU4yE=; b=qCiDPcYIKUo/fW6nu7oOTgobltf6xu4VRkBJuxHJIXoluVLRLy3TDc4NsJM0EZRYSI 46fm58SOWFexxk3ZhPQgyv8MeW5wMDT3Wo9h4w+e/zTg1X8Ws3j6blbsQLVyKusRD4K/ 8yHzwryS5arkoxR+Ei1esNQ8Lbs8jgkCFoL20HVKWSSEeatSAtaLh0dORIiyVCcZQ+yC 4PTcdYLDKK7sv5Y7p7mVy+GTFX7f5NHwRAZrCfYRGU+E4ytyUJOJIG0mxQuPGNFt85Ju rI3n+FM2jp66MVXsg2JawOqbZYRB4luGx+nNOSZAqY4pQADbHZV0/dhLL5TN5oHDHA5D kdyw== X-Gm-Message-State: AOAM531YiN1WmyMgMjO+d8gNb/P0YVzRTxHoexaKPFKtGUpow3qNj1ZS GUA7wZgSgM5AHCc+JugErZngHjt7NOI= X-Google-Smtp-Source: ABdhPJwvrjl2/eTwM1P6dOd9boGJ5cYC4kQCgP/2eFHtFkQeu3mCHmYWnxDf60qCs6ilDTuJgbQznw== X-Received: by 2002:a1c:7d13:: with SMTP id y19mr5984806wmc.98.1606342379581; Wed, 25 Nov 2020 14:12:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h83sm5090867wmf.9.2020.11.25.14.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:12:59 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:49 +0000 Subject: [PATCH v3 1/8] 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 , Eric Sunshine , 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 --- 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..f34a11d94b 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 contains the CONFIG_FLAGS_MULTI_REPLACE flag, all matching + * key/values are removed before a single new pair is written. If the + * flag is not present, then replace only the first match. * * 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..58726c34d6 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 single 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 Wed Nov 25 22:12:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932301 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 BDF0EC71155 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7027C20857 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IdJjFstb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732887AbgKYWNJ (ORCPT ); Wed, 25 Nov 2020 17:13:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731475AbgKYWNC (ORCPT ); Wed, 25 Nov 2020 17:13:02 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486D1C061A51 for ; Wed, 25 Nov 2020 14:13:02 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 10so173376wml.2 for ; Wed, 25 Nov 2020 14:13:02 -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=JNeuasjdJpTx03qlPCn2+QaPpT57HetwOjVQ9GfHlsM=; b=IdJjFstbTCVdk0uf8VhNzFq66o/cn58bAF2Wb3ubhQ9yovcbYEhDUMUsTr9FSa5IVY fIqtSBvDctLcpSXpYCZJkG8oGFNYNLpYZ3vTyzBabdKHwTDtiXc/kOo3dcNGO9PDVyNl 1pCj0eKZx7SYljbADe3/ccp6v7ZFujtOGF4ENw3x+1EFL/7dDKHHVzwxvMSRFt2LfhSN G0SAYx9MY56CO8V79wFUt1cCPnNGABk9zhlSSzWiC1mg772J1/UHapt407MZqmmbfTz4 /hJkpl9JTtjp+mQJFz6NDbyvjKOdUIYkbmN8lnoWEcpYKmoxAANQoh8i2kJiBOjKPF3D /PHw== 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=JNeuasjdJpTx03qlPCn2+QaPpT57HetwOjVQ9GfHlsM=; b=LQuq47Doyq22Xgc8YMMv/PVVSgAc630Hlep8sZACodZmY9/OosIpNoSvYCg+cH65nn YMZwf1JUMV7DDSIWXAKC4nhrA6wnDkGSZpAdndzLYtb3CLGKF/4wVIIC52sSZeVHYVDv +FnEWY4/kOPVivm2LWiszKM3PcrNhiDppduZCrCvvR9C6WJwsJTgUmR3on0z0KDHGx1O x2f4V6x+23UrjFNPVEm+mWXUksID+Z0IVyP72TqbhO89aEdbr1YU2+NlYak46isT6qUZ Dhx+IPyfaM9Vxz40GIBcXvE9IyjXhRx4MrYV7BaRF+5y/tMrpNEP6uOHqphNo2O6y76/ oDYg== X-Gm-Message-State: AOAM530lKtsfSIjs1vtBOP5DL6kS1tJV60gfuLxkP967e0N9fxuEzz8U eyr3qXr24m5M+rDfd2ZtgVgiCYfvJTA= X-Google-Smtp-Source: ABdhPJzBWZksFzEJ2h7sFPidGZmbmbVGUei9NKvhNcVxhSL8GI4+VR24+UNm4GnoVbDbO1atortcDQ== X-Received: by 2002:a7b:c5c6:: with SMTP id n6mr6117576wmk.131.1606342380631; Wed, 25 Nov 2020 14:13:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d13sm7339443wrb.39.2020.11.25.14.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:00 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:50 +0000 Subject: [PATCH v3 2/8] config: replace 'value_regex' with 'value_pattern' 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 , Eric Sunshine , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'value_regex' argument in the 'git config' builtin is poorly named, especially related to an upcoming change that allows exact string matches instead of ERE pattern matches. Perform a mostly mechanical change of every instance of 'value_regex' to 'value_pattern' in the codebase. This is only critical for documentation and error messages, but it is best to be consistent inside the codebase, too. For documentation, use 'value-pattern' which is better punctuation. This affects Documentation/git-config.txt and the usage in builtin/config.c, which was already mixed between 'value_regex' and 'value-regex'. I gave some thought to leaving the value_regex variables inside config.c that are regex_t pointers. However, it is probably best to keep the name consistent with the rest of the variables. This does not update the translations inside the po/ directory, as that creates conflicts with ongoing work. The input strings should automatically update through automation, and a few of the output strings currently use "[value_regex]" directly. Signed-off-by: Derrick Stolee --- Documentation/git-config.txt | 20 ++++++------- builtin/config.c | 12 ++++---- config.c | 54 ++++++++++++++++++------------------ config.h | 2 +- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 7573160f21..0be5499952 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=] [--show-origin] [--show-scope] [-z|--null] name [value [value-pattern]] '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=] --replace-all name value [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get name [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get-all name [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value-pattern] 'git config' [] [--type=] [-z|--null] --get-urlmatch name URL -'git config' [] --unset name [value_regex] -'git config' [] --unset-all name [value_regex] +'git config' [] --unset name [value-pattern] +'git config' [] --unset-all name [value-pattern] '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 @@ -33,7 +33,7 @@ escaped. Multiple lines can be added to an option by using the `--add` option. If you want to update or unset an option which can occur on multiple -lines, a POSIX regexp `value_regex` needs to be given. Only the +lines, a POSIX regexp `value-pattern` needs to be given. Only the existing values that match the regexp are updated or unset. If you want to handle the lines that do *not* match the regex, just prepend a single exclamation mark in front (see also <>). @@ -73,11 +73,11 @@ OPTIONS --replace-all:: Default behavior is to replace at most one line. This replaces - all lines matching the key (and optionally the value_regex). + all lines matching the key (and optionally the `value-pattern`). --add:: Adds a new line to the option without altering any existing - values. This is the same as providing '^$' as the value_regex + values. This is the same as providing '^$' as the `value-pattern` in `--replace-all`. --get:: diff --git a/builtin/config.c b/builtin/config.c index e7c7f3d455..9d97091561 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -130,14 +130,14 @@ static struct option builtin_config_options[] = { OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), OPT_GROUP(N_("Action")), - OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET), - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL), - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP), + OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), + OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), + OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL), + OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-regex]"), ACTION_UNSET), - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL), + OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), + OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), diff --git a/config.c b/config.c index f34a11d94b..ac6aace166 100644 --- a/config.c +++ b/config.c @@ -2402,7 +2402,7 @@ struct config_store_data { size_t baselen; char *key; int do_not_match; - regex_t *value_regex; + regex_t *value_pattern; int multi_replace; struct { size_t begin, end; @@ -2416,10 +2416,10 @@ struct config_store_data { static void config_store_data_clear(struct config_store_data *store) { free(store->key); - if (store->value_regex != NULL && - store->value_regex != CONFIG_REGEX_NONE) { - regfree(store->value_regex); - free(store->value_regex); + if (store->value_pattern != NULL && + store->value_pattern != CONFIG_REGEX_NONE) { + regfree(store->value_pattern); + free(store->value_pattern); } free(store->parsed); free(store->seen); @@ -2431,13 +2431,13 @@ static int matches(const char *key, const char *value, { if (strcmp(key, store->key)) return 0; /* not ours */ - if (!store->value_regex) + if (!store->value_pattern) return 1; /* always matches */ - if (store->value_regex == CONFIG_REGEX_NONE) + if (store->value_pattern == CONFIG_REGEX_NONE) return 0; /* never matches */ return store->do_not_match ^ - (value && !regexec(store->value_regex, value, 0, NULL, 0)); + (value && !regexec(store->value_pattern, value, 0, NULL, 0)); } static int store_aux_event(enum config_event_t type, @@ -2713,8 +2713,8 @@ void git_config_set(const char *key, const char *value) /* * If value==NULL, unset in (remove from) config, - * 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 + * if value_pattern!=NULL, disregard key/value pairs where value does not match. + * if value_pattern==CONFIG_REGEX_NONE, do not match any existing values * (only add a new one) * if flags contains the CONFIG_FLAGS_MULTI_REPLACE flag, all matching * key/values are removed before a single new pair is written. If the @@ -2738,7 +2738,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, + const char *value_pattern, unsigned flags) { int fd = -1, in_fd = -1; @@ -2799,22 +2799,22 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, int i, new_line = 0; struct config_options opts; - if (value_regex == NULL) - store.value_regex = NULL; - else if (value_regex == CONFIG_REGEX_NONE) - store.value_regex = CONFIG_REGEX_NONE; + if (value_pattern == NULL) + store.value_pattern = NULL; + else if (value_pattern == CONFIG_REGEX_NONE) + store.value_pattern = CONFIG_REGEX_NONE; else { - if (value_regex[0] == '!') { + if (value_pattern[0] == '!') { store.do_not_match = 1; - value_regex++; + value_pattern++; } else store.do_not_match = 0; - store.value_regex = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(store.value_regex, value_regex, + store.value_pattern = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(store.value_pattern, value_pattern, REG_EXTENDED)) { - error(_("invalid pattern: %s"), value_regex); - FREE_AND_NULL(store.value_regex); + error(_("invalid pattern: %s"), value_pattern); + FREE_AND_NULL(store.value_pattern); ret = CONFIG_INVALID_PATTERN; 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, unsigned flags) + const char *value_pattern, unsigned flags) { if (!git_config_set_multivar_in_file_gently(config_filename, key, value, - value_regex, flags)) + value_pattern, flags)) return; if (value) die(_("could not set '%s' to '%s'"), key, value); @@ -2996,16 +2996,16 @@ 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, unsigned flags) + const char *value_pattern, unsigned flags) { - return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex, + return git_config_set_multivar_in_file_gently(NULL, key, value, value_pattern, flags); } void git_config_set_multivar(const char *key, const char *value, - const char *value_regex, unsigned flags) + const char *value_pattern, unsigned flags) { - git_config_set_multivar_in_file(NULL, key, value, value_regex, + git_config_set_multivar_in_file(NULL, key, value, value_pattern, flags); } diff --git a/config.h b/config.h index 58726c34d6..8ad1085b74 100644 --- a/config.h +++ b/config.h @@ -296,7 +296,7 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha void git_config_set_multivar_in_file(const char *config_filename, const char *key, const char *value, - const char *value_regex, + const char *value_pattern, unsigned flags); /** From patchwork Wed Nov 25 22:12:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932287 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 DD195C64E7B for ; Wed, 25 Nov 2020 22:13:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B9BD20857 for ; Wed, 25 Nov 2020 22:13:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="usNLgULJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732849AbgKYWNH (ORCPT ); Wed, 25 Nov 2020 17:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbgKYWND (ORCPT ); Wed, 25 Nov 2020 17:13:03 -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 20473C0613D4 for ; Wed, 25 Nov 2020 14:13:03 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id u12so31012wrt.0 for ; Wed, 25 Nov 2020 14:13:03 -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=q01KP/mClcYGI2iUyxCOeEO/qmWF73sd6QO2OzcB53o=; b=usNLgULJrIs+6fr8b2zqK9ccrEfnEblh3WUSF6zLySca3hactcTHhglIYpDqit9uzG eBX4TVsFuSQvQx8cJUgXtHOD+6x8DGVTsOPWvSxFqF+keteHmqbXFjp6sADo8/sxUs+y 8OYhEgqS2H0fQRsPBnqDGmoZ5sOfsJAUpr3cjl5LvnnRhTwWZ8zSKKLKd0i3aDUkih47 b1Pb0khvSSDN3GseCG+To/NJAFBKg27rSKV4x2qiTGwazG7QbsLZATBKbDOvbM4zgj9K X0WWenN0ytR4Uyneq/a9VaPre8x50sQqqmylBxrnCEEwVIjHRZ6O3+X8lxKBQiu20HgW /B5Q== 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=q01KP/mClcYGI2iUyxCOeEO/qmWF73sd6QO2OzcB53o=; b=pdRprFX4AYxJDeFoXidgDaTkk+ykaJg0+air53EXKJQVpYGyIjBz4aufyvOGDrb9Mr PA4KRvGBAhNTSxnNFZnwbHTGgedXPrF8KXDUk7DCeRQ++wXDEGElDld21ymQdrhTXAFf MRFWG+8fGhw1CbdA8pxbSb8iBVkEfEohLdo6JwgCM6Yn5Ir3JcAYY+UYwiRwCEb8oM2r ZuVcb+7hWjXaXIZyhbZ0QMHqb56//zKK31Kz1Dzslo/8Vujo4W5BQIIrG2sbQbd1GRVr l394ArO8VOMHDx7S/f9VJ1OkdBemX4nCsSSz+yss+cTFDE2ggc3VSoEklS2EFJzhZHrZ WqYQ== X-Gm-Message-State: AOAM532e93paFOJU3mQ+aHwCz8Uo3hZHkHr1XOf22tdqXLvHhxt8d/6w TpAVLH3RkRRcrNWMDhxQYYinuy5sdYs= X-Google-Smtp-Source: ABdhPJxeTVtG1x8oRkck3zUiBi+ce10EXg/dyvD970HAsLGIwOMlUkeUM+ZAvAzm2iAGEQdkOq7OZQ== X-Received: by 2002:adf:e481:: with SMTP id i1mr48701wrm.282.1606342381696; Wed, 25 Nov 2020 14:13:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q1sm6512862wrj.8.2020.11.25.14.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:00 -0800 (PST) Message-Id: <3b72082326b692542f29a71737e2459a1ae12900.1606342377.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:51 +0000 Subject: [PATCH v3 3/8] t1300: test "set all" mode with value-pattern 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 , Eric Sunshine , 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-pattern parameter is supplied, this command behaves in a non-trivial manner. Consider 'git config '. The expected behavior is as follows: 1. If there are multiple existing values that match 'value-pattern', then the command fails. Users should use --replace-all instead. 2. If there is no existing values match 'value-pattern', then the 'key=value' pair is appended, making this 'key' a multi-valued config setting. 3. If there is one existing value that matches 'value-pattern', then the new config has one entry where 'key=value'. 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 to prevent possibly incompatible repo states. Also use 'git config --file= --list' for config state comparison instead of the config file format. This makes the tests more readable. Signed-off-by: Derrick Stolee --- t/t1300-config.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 97ebfe1f9d..72f930ada0 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1914,4 +1914,43 @@ test_expect_success '--replace-all does not invent newlines' ' test_cmp expect .git/config ' +test_expect_success 'set all config with value-pattern' ' + test_when_finished rm -f config initial && + git config --file=initial abc.key one && + + # no match => add new entry + 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 && + + # multiple matches => failure + test_must_fail git config --file=config abc.key three o+ 2>err && + test_i18ngrep "has multiple values" err && + + # multiple values, no match => add + 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 && + + # single match => replace + git config --file=config abc.key four h+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + abc.key=four + EOF + test_cmp expect actual +' + test_done From patchwork Wed Nov 25 22:12:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932285 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 311C9C64E7C for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7A8F206D9 for ; Wed, 25 Nov 2020 22:13:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vQUv1XDX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732823AbgKYWNH (ORCPT ); Wed, 25 Nov 2020 17:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730646AbgKYWNF (ORCPT ); Wed, 25 Nov 2020 17:13:05 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ADE0C061A52 for ; Wed, 25 Nov 2020 14:13:04 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id c198so182704wmd.0 for ; Wed, 25 Nov 2020 14:13:03 -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=zo3dkwqLduSB1lZ4v/CnmsRkQOh94CpIBzBmg4Ha3J4=; b=vQUv1XDX5KoJa3ndT9QzcSq/z1Lf0Dg8OVXAhneWlDsBv1U5Cjk6KpTk4WM1Ldf5er CXWLsc0M3kG47Mvz7TxwuXUlRlPsiX9GjFGBMn6e4i2idArmnJqD+LtSSPKwGC5E77L4 NeSY+Y7qGCgBYaQ7QVydHugAQVvrsCZqrJC1IwQcMvOBHFK9htwU4BxwP3gqQhptX9yl FvpHYMlW2G8r71v24nJP8Dw1RoQgr2NserLaYWcFtGcQwOaWRP38dlp7ulpN0oZlkDrJ jSF14/p0ntHrbO4rxT+FiXNXiskiAxvQkRkWIIXvvVsvORsigaVEdDP+OAFb1IV90MJN gnTA== 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=zo3dkwqLduSB1lZ4v/CnmsRkQOh94CpIBzBmg4Ha3J4=; b=lBukxsYX3GMMezonikMG5EOsp4PAlz8DkC4J0PA1aF5VBLJb9t/e0BknyHINfcd+88 ZSNY79R08a/zrL2xMHH6jjpBLXns8r5gscEWy1EPcQ36xK3A6cLKDgIht5sAHmGms8nW 5BK7WwgfpbZXScIjyPjyEZNva00gO4YiCOw+JvfOyVlWACUE0Yp0tpA4jVjKzufFKRnM lgbRpq3kW7eAoxyZmaeQuLUuen44JBknhH5WLbAcv76ItsQwxm91+bt+wxefJ5G9UC+a LFjX2GEUfdUwEplxO48ZxGF5M9OYLR4XcVJCfqkgvjihAr7fypi1d5PF9CPZP9QPw9BW 1oWQ== X-Gm-Message-State: AOAM5338kSoGff0/OjHR4ZlhwNBVwhSa63ZNfaRUg4EN/T0TejJjRsH0 75/y10oKhsReUnTNmKLG0i8zQXfvYjU= X-Google-Smtp-Source: ABdhPJyQbrUSdmRh5eZ44Mm0nbfFMQvhBX2Nph2jMtbcV+cG8+yJNDDgafM2j5Mj17oeC+YUlKEzsA== X-Received: by 2002:a05:600c:414b:: with SMTP id h11mr6225084wmm.89.1606342382619; Wed, 25 Nov 2020 14:13:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t15sm5954846wmn.19.2020.11.25.14.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:02 -0800 (PST) Message-Id: <75fb74da8324674194cca2b27fc4e6c0fdc6486d.1606342377.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:52 +0000 Subject: [PATCH v3 4/8] t1300: add test for --replace-all with value-pattern 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 , Eric Sunshine , 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-pattern' parameter. Since we will be updating this option to optionally treat 'value-pattern' as a fixed string, let's add a test here that documents the current behavior. Signed-off-by: Derrick Stolee --- t/t1300-config.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 72f930ada0..040b9f7506 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1953,4 +1953,18 @@ test_expect_success 'set all config with value-pattern' ' test_cmp expect actual ' +test_expect_success '--replace-all and value-pattern' ' + test_when_finished 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 Wed Nov 25 22:12:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932295 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 816CEC64E8A for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44323206D9 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T9IOTIPF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732871AbgKYWNI (ORCPT ); Wed, 25 Nov 2020 17:13:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732602AbgKYWNF (ORCPT ); Wed, 25 Nov 2020 17:13:05 -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 5022FC061A53 for ; Wed, 25 Nov 2020 14:13:05 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id u12so31079wrt.0 for ; Wed, 25 Nov 2020 14:13:05 -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=ggyTh2xfy1KZsvIVeRaTDC19qP+roOPfuNpnuBpZipQ=; b=T9IOTIPF8J8fFyMq3vaelWIvHjllhyacQk9YjTRPzNP+F9f6bWWauRtxY8Fg0XDiU9 BeBl29xyu7vxKSL4t7soPVIrljMH1y8iTdSllS7c8XN75NyJA1TjmbOjDi4E+qtw0mQU jOOehhrnMr058y08NgtJUzh7Ozk/79hTyGlOFx2tNvFodmDd+1cXOI+uZt0e3h1FIqq0 fDJv1B78n5ZjUJhejWuGrU7Ekr7xHsvrvq9aSXCusoLUDGwohKFRujvwl3JvyPwStAlR T/ZYHLy33RBFjkrUQb2p8CzcjqZHVDjFRyqNAYBEwKl9vsMIogz6Mmap05Ij8KbutOSm IJ7w== 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=ggyTh2xfy1KZsvIVeRaTDC19qP+roOPfuNpnuBpZipQ=; b=jssubx4kNGjPr/FCF9YRCeQd2dNCOKZQ3gPt5Q2o37qYV6aKW85cZuLeg4OtkKvDwU NiBhHJr3IxP31qdPPF7RNSOFg9wU5sVIG9VFer8PrAvtrtSFZBwm4r7avG/1yDawLHGm t1YVS/m4saEI2g+jk8ElXEEwjVF8gtGVVDNSqM2J+cWR86whN2HQHwkoZmpF/sZIH/NV DBygOsgDnaPmmleAurRyAxuYBBFkUVIfhnwS1xYBLJ7pzRZLpcIuevgSU48qVk65TJRM AEcrFT/EqlRyO2H+qXNiznQUiBph8SK5BJF4+syEbzfTrZw1i9VJo4LwfQjzHgdnU2z+ KWnA== X-Gm-Message-State: AOAM532YkD58wbb/Slynevt2S9TNXeql+94rVQOPoMFp4EVc/M4H5AF7 XjIn+SFtH+1rP4rxqzEoLcczcIeBLhY= X-Google-Smtp-Source: ABdhPJzEXIowgFGMstqf18As1tuPJYU/upMPEeZe24Mk/WQEqTDHJQokpX+sbHMaf8R6Oxm6YKIQCQ== X-Received: by 2002:adf:f542:: with SMTP id j2mr71541wrp.32.1606342383721; Wed, 25 Nov 2020 14:13:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g186sm7221394wma.1.2020.11.25.14.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:03 -0800 (PST) Message-Id: <0c276ffcee4be302be3db9b43ab8371ef26a0aec.1606342377.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:53 +0000 Subject: [PATCH v3 5/8] 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 , Eric Sunshine , 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-pattern' parameter for several actions. This can cause confusion when expecting exact value matches instead of regex matches, especially when the input string contains metacharacters. 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 be filled in by later changes 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-pattern' 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 | 36 ++++++++++++++++++++++++++++++++++++ t/t1300-config.sh | 24 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 0be5499952..09a1d273a9 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-pattern]] +'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] name [value [value-pattern]] 'git config' [] [--type=] --add name value -'git config' [] [--type=] --replace-all name value [value-pattern] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get name [value-pattern] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get-all name [value-pattern] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value-pattern] +'git config' [] [--type=] [--fixed-value] --replace-all name value [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get name [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all name [value-pattern] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp name_regex [value-pattern] 'git config' [] [--type=] [-z|--null] --get-urlmatch name URL -'git config' [] --unset name [value-pattern] -'git config' [] --unset-all name [value-pattern] +'git config' [] [--fixed-value] --unset name [value-pattern] +'git config' [] [--fixed-value] --unset-all name [value-pattern] '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-pattern` argument, treat `value-pattern` 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-pattern`. + --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 9d97091561..d0adbed872 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 comparing values to 'value-pattern'")), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), @@ -745,6 +747,40 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } + /* check usage of --fixed-value */ + if (fixed_value) { + int allowed_usage = 0; + + switch (actions) { + /* git config --get */ + case ACTION_GET: + /* git config --get-all */ + case ACTION_GET_ALL: + /* git config --get-regexp */ + case ACTION_GET_REGEXP: + /* git config --unset */ + case ACTION_UNSET: + /* git config --unset-all */ + case ACTION_UNSET_ALL: + allowed_usage = argc > 1 && !!argv[1]; + break; + + /* git config */ + case ACTION_SET_ALL: + /* git config --replace-all */ + case ACTION_REPLACE_ALL: + allowed_usage = argc > 2 && !!argv[2]; + break; + + /* other options don't allow --fixed-value */ + } + + if (!allowed_usage) { + error(_("--fixed-value only applies with 'value-pattern'")); + 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 040b9f7506..f6f071006d 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1967,4 +1967,28 @@ test_expect_success '--replace-all and value-pattern' ' test_cmp expect actual ' +test_expect_success 'refuse --fixed-value for incompatible actions' ' + test_when_finished rm -f config && + 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-pattern + test_must_fail git config --file=config --fixed-value dev.null bogus && + test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && + test_must_fail git config --file=config --fixed-value --get dev.null && + test_must_fail git config --file=config --fixed-value --get-all dev.null && + test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" && + test_must_fail git config --file=config --fixed-value --unset dev.null && + test_must_fail git config --file=config --fixed-value --unset-all dev.null +' + test_done From patchwork Wed Nov 25 22:12:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932289 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 5F1D3C64E7D for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17D8120857 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KXeqB1Cz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732868AbgKYWNI (ORCPT ); Wed, 25 Nov 2020 17:13:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732710AbgKYWNG (ORCPT ); Wed, 25 Nov 2020 17:13:06 -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 521D8C0613D4 for ; Wed, 25 Nov 2020 14:13:06 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id 64so3387560wra.11 for ; Wed, 25 Nov 2020 14:13:06 -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=z8Lynq2MuI0q+564gtYy6+RX8SHso0xZGcVDlMLOvdM=; b=KXeqB1Cz4ZsQpTeNWr2CVhcJ7x9GmJLnj7+WVyJiROVvr35GBzSeMKvcDHnliG7Jnk 0b3E5qQtyaXynVJXMqPK93I1BNPSr4lf4oe5PYZ9tRIQryFjv+RELBElLWmljbwN6+Os aB6pAnJJnZL/neU5Z1Qoja5Qc2We98ql78CocWj5WvAnmORoGSN0doBWnEG++nUbXWZu jH9/JGEJ42PJjawvzKFWXZqNXBEcVjgxUQNclp/4eJ0eLbq/WDmQZBY6txceyWU3mg6u SoRL0E0gpim7SPI75yGNHrQ7kLK0XUQ4qn8RZz2EY+K2C1gQA6bejiuqjVEUcPI1rW9f l/fw== 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=z8Lynq2MuI0q+564gtYy6+RX8SHso0xZGcVDlMLOvdM=; b=AxZGTmdgFlLZ+7MJqtfW3HxS7MZJsjfpUV0tOzvXLNw1wwO3YA36qzgj4LbgzbEF3V g6n3YR8L4Uph9IvUzvHPoi4KocDbwlHkeqVdEOzCr1knLN88KPgkRHcojjuz46ipHJZ6 paBBTHFnMz98SjuZDvjFZkEaz6/wwuEhmtkuYkYcIsGsVdwRF94bwS4xIyKSU+pMn/HW JP6aovhD0bCm7IUd5Z7RThYBiuDCDba9YnBWAE6fcXS9yVhoR4kxTxzv4FlJvgVd6COo 5ZICgi4tCAcZUy37K33A9S+gGvfjC1ctUIRLohNrXY0ffJiiCUx2hbgwjT/1JbpWNvM0 MXqQ== X-Gm-Message-State: AOAM531NFYJGwA7y+c9YEpbYa/yKEv4yoq9mDk6ZANtb4eGj6HxOeI6q 6GY1iv2CbsUDIU9mNDI6sb5622M1PJg= X-Google-Smtp-Source: ABdhPJyuszrR+DGONFDabywm1/3y3OroAvvero7srKrN2j3f/YH16Rawgb+BoboFAIDBh7IM3jhXgw== X-Received: by 2002:adf:f00f:: with SMTP id j15mr64348wro.102.1606342384786; Wed, 25 Nov 2020 14:13:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v20sm5583879wmh.44.2020.11.25.14.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:04 -0800 (PST) Message-Id: <763401da97289ea00eed372c6ed40ad508781681.1606342377.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:54 +0000 Subject: [PATCH v3 6/8] 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 , Eric Sunshine , 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_pattern 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 | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index d0adbed872..8049d8f5fc 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)); @@ -779,6 +780,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) error(_("--fixed-value only applies with 'value-pattern'")); usage_builtin_config(); } + + flags |= CONFIG_FLAGS_FIXED_VALUE; } if (actions & PAGING_ACTIONS) @@ -842,7 +845,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(); @@ -851,7 +855,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(); @@ -860,7 +865,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); @@ -887,7 +892,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); @@ -897,7 +903,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 ac6aace166..d827167d83 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 *fixed_value; regex_t *value_pattern; 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->fixed_value) + return !strcmp(store->fixed_value, value); if (!store->value_pattern) return 1; /* always matches */ if (store->value_pattern == CONFIG_REGEX_NONE) @@ -2803,6 +2806,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.value_pattern = NULL; else if (value_pattern == CONFIG_REGEX_NONE) store.value_pattern = CONFIG_REGEX_NONE; + else if (flags & CONFIG_FLAGS_FIXED_VALUE) + store.fixed_value = value_pattern; else { if (value_pattern[0] == '!') { store.do_not_match = 1; diff --git a/config.h b/config.h index 8ad1085b74..34901e2b64 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_pattern + * 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 f6f071006d..413fcbba03 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1991,4 +1991,54 @@ 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' ' + test_when_finished rm -f config initial && + META="a+b*c?d[e]f.g" && + git config --file=initial fixed.test "$META" && + + cp initial config && + git config --file=config fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$META + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + git config --file=config --fixed-value fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-\EOF && + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + test_must_fail git config --file=config --unset fixed.test "$META" && + git config --file=config --fixed-value --unset fixed.test "$META" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + test_must_fail git config --file=config --unset-all fixed.test "$META" && + git config --file=config --fixed-value --unset-all fixed.test "$META" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + git config --file=config --replace-all fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$META + fixed.test=bogus + EOF + test_cmp expect actual && + + git config --file=config --fixed-value --replace-all fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=bogus + fixed.test=bogus + EOF + test_cmp expect actual +' + test_done From patchwork Wed Nov 25 22:12:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932299 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 30EE4C56201 for ; Wed, 25 Nov 2020 22:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D261E20857 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SHR/JkB4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732898AbgKYWNM (ORCPT ); Wed, 25 Nov 2020 17:13:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732836AbgKYWNH (ORCPT ); Wed, 25 Nov 2020 17:13:07 -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 5F9B0C061A4F for ; Wed, 25 Nov 2020 14:13:07 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id 10so173510wml.2 for ; Wed, 25 Nov 2020 14:13:07 -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=jIEw+ugPWKoj61LuFUVLRI6qNBF0LnVxvBQcTrUDfY0=; b=SHR/JkB4ayNr1YPvyf6AHz/e2xMtm+AMxMblqSQvo/SBZKm7DqR2lNz/WDtmEQpG32 NwD6mcqflKTVahLDM8cc1oyAuDVBPw95wV6zXbTgWEN8D/izNILbXxg/Z4qFpsk12hUa /PSk4NteRhscrxsKNT7ogJ9TPbZkcpTTZKX1w0VE3NCMpAwgqCGOIXGHEZQqf64VxRfD PMP4uFHMaern+AK8mdAh9ulCexNbXKWvUvadW56nmAPd+7CEQt9k6qVznXwJSIjCj4+2 AxKB8vQF6U0y2Yhdhy6PZeo4EWGqA1nTaz4BamkXY2k36uYCF65zgHgUf59en60iyg1T Fv5g== 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=jIEw+ugPWKoj61LuFUVLRI6qNBF0LnVxvBQcTrUDfY0=; b=nauEJ2qiYEp2K9vNuJaVxv6nuU17KhfYmR7JBxcoEbIjmiG6r/0kfH+QLpc1tr4Rvr wC4a52yT57JCoP+im7QX9eV1lJH9dbqSu6PB8rcViwqgx6UFto9W+APCtXkBv5w12Chb l1lsM2dkTERI9+gQxumQngQL7abfWewO9oK3EAyKePqk52Pwj9Zo4nosDP6Yr1QcHE/E WjxzIZSm+ZvQ4zxqdOg4u5YHuYgPKby8xo1aCGmdcbSo+EpIOaFPDMru5zpBAJ4azuxk F7VGvUfQ7YL0dahpVpYeYXsXxeGl5S3fzEPUrwFl0OOixQ0gCf+ajnG5ZYf8bIsGB57v aMsQ== X-Gm-Message-State: AOAM532jJbyx9o0QVr4pWZop9bXU4S5h7xHwGv+lQ5kEARCAv4jMBT74 Cn4zNrEAxjnWOeI+nRnhY8Y9E5FLbUc= X-Google-Smtp-Source: ABdhPJyAs3gsjyUfL94PymGuqnyEB0jahfa/xFjFvgAIdMXW5WQkwm/ztEQnjOeWuPPnB/nx5CbjDQ== X-Received: by 2002:a1c:5585:: with SMTP id j127mr5320857wmb.169.1606342385909; Wed, 25 Nov 2020 14:13:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f5sm6702309wmj.17.2020.11.25.14.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:05 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:55 +0000 Subject: [PATCH v3 7/8] 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 , Eric Sunshine , 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-pattern argument as a fixed string instead of a regex pattern. Signed-off-by: Derrick Stolee --- 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 8049d8f5fc..82e36c595e 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_pattern; 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_pattern, (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_, unsigned 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_pattern = regex_; + else if (regex_) { if (regex_[0] == '!') { do_not_match = 1; regex_++; @@ -869,19 +874,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 413fcbba03..ea38ba9ab1 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2041,4 +2041,26 @@ test_expect_success '--fixed-value uses exact string matching' ' test_cmp expect actual ' +test_expect_success '--get and --get-all with --fixed-value' ' + test_when_finished rm -f config && + META="a+b*c?d[e]f.g" && + git config --file=config fixed.test bogus && + git config --file=config --add fixed.test "$META" && + + git config --file=config --get fixed.test bogus && + test_must_fail git config --file=config --get fixed.test "$META" && + git config --file=config --get --fixed-value fixed.test "$META" && + 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 "$META" && + git config --file=config --get-all --fixed-value fixed.test "$META" && + 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+ "$META" && + git config --file=config --get-regexp --fixed-value fixed+ "$META" && + test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent +' + test_done From patchwork Wed Nov 25 22:12:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11932293 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 F15BCC64E90 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F255206D9 for ; Wed, 25 Nov 2020 22:13:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VlMXfkq3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732894AbgKYWNK (ORCPT ); Wed, 25 Nov 2020 17:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732881AbgKYWNI (ORCPT ); Wed, 25 Nov 2020 17:13:08 -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 67D91C0613D4 for ; Wed, 25 Nov 2020 14:13:08 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id e7so6914wrv.6 for ; Wed, 25 Nov 2020 14:13:08 -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=kRjRrr+jlp4f+qDklro2hVq4wuNrs892V9EMBcsrKy4=; b=VlMXfkq3rPIslWwhC+JHZ/dGg5hjItYUgS+5cNyq8TAwp6aHxMrvGXgQvoU/apJgdf gph8UhFY1cA5jfFtnHOfMH//e9Q7DupQt40nIdM2QqXJm5agKI3iYBDFgi1NmTjReSFg EZlZGANadH4lHhTznxFFVDbZ8xzhmj3+nDQxIWASTOiZMMOESzqQDUMbd214/Qmrkm4T L94y0fhdq/c74OcdqDboVRhSWGuxrQAGJXow3AHRJMcyzW1H4Z5rFsLC1BYIr0X47LU+ M4CZnCMB45UxNtRiUXMNvORhn9gO+zDC+0ie7F/jCXVgVOa2iPyeq/vFuxXkhdETxtoT PwaA== 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=kRjRrr+jlp4f+qDklro2hVq4wuNrs892V9EMBcsrKy4=; b=B0YFDas03mS/4+L8Vxg0M5mgOKJNn4EKnohCQqvblS/xukthzgGoLP6vG+hgiORKRl kdlwgWr1kjPP9LwUg9uxLDp0hEL8E0NeFNlfyLDvH58GykD8UHMSbktkasuc4Ule2E8T qSZ9QVxW8SYSHMJfIv9/+b29YDJkZLtgKxHBDktancmVI9ylw17Q6KdRUGAoXbORkY1b E7EOeaHl9P711flmBGTxyLV0s3CRXZ/nSIxzNiLWHTKsOfH0WHNqTE738Xi0fjtGwP2W PA3LuHFFrqSfO4J8UInHUK5Gcv364Kk+kisZLd68XtNakYIrritfOdgqjVZnbW7cwIsr romQ== X-Gm-Message-State: AOAM531IrM9JkTWuVsBFWc3AS9yS2CQE0arMnNpdlygjcxYYgL0cbfTd ApbsnFp3Fs1EykSxv26I9To3qkTGdgE= X-Google-Smtp-Source: ABdhPJytuqoAu+HE/tlHwNCHy0VkVHuQfHwJxZbY44fXBeQKUUainTn56pds3meaH46BL4TFjTL7Ng== X-Received: by 2002:adf:ef4c:: with SMTP id c12mr54365wrp.242.1606342386917; Wed, 25 Nov 2020 14:13:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d8sm6488705wrp.44.2020.11.25.14.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 14:13:06 -0800 (PST) Message-Id: <558775f83d7cbf7ad0e2090ab13be404cdf16b24.1606342377.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 25 Nov 2020 22:12:56 +0000 Subject: [PATCH v3 8/8] 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 , Eric Sunshine , 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 metacharacters, 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 escaping these arguments in a piecemeal fashion. For the test, require that we are not running on Windows since the '+' and '*' characters are not allowed on that filesystem. Reported-by: Emily Shaffer Reported-by: Jonathan Nieder Signed-off-by: Derrick Stolee --- 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..bc2207edd6 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 regex metacharacters' ' + META="a+b*c" && + git init "$META" && + git -C "$META" maintenance register && + git config --get-all --show-origin maintenance.repo && + git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$META" && + git -C "$META" maintenance unregister && + test_must_fail git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$META" +' + test_expect_success 'start from empty cron table' ' GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&