From patchwork Mon Jan 11 08:36:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12010073 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 DEC40C433E0 for ; Mon, 11 Jan 2021 08:38:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A023A22581 for ; Mon, 11 Jan 2021 08:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727973AbhAKIhx (ORCPT ); Mon, 11 Jan 2021 03:37:53 -0500 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:56621 "EHLO wout4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727739AbhAKIhw (ORCPT ); Mon, 11 Jan 2021 03:37:52 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 1E8DD2486; Mon, 11 Jan 2021 03:36:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 11 Jan 2021 03:36:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=ctBB26mAkTcdgZIgm1IcYvI4Pyy bfN7Vhbn3CUMD9Jg=; b=MC8um5uJRnVklc5jAzhB0MdKRoQlCb0fEu44HaytRIp 06hQ2LqLc0CF4Zuslzxr0fQwW8uuS0jYN6JzZ8HmCdkmgbXIrFoynWydRY5z8OxU msYBHy1nfHToEp6Cb50I8vE40icr3c5H87hli2q1lYKBhsGlNqEAK7pP2kxZ4QnR KQb8LdbiTOrD993KhfvvlB1Ipsd7G2A60AcCw63tOv2bCinPY0ytlXnrMGw6h7PD 3jONdKxP4xYud30p9umBRWbYqa88slt0e1GEvr0MPCo1NYuuJSssqgVN1CNbAigM xkyaBog8tCIBV5qEYKufTf3EYDiV/ek3iE5J7b6fusA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=ctBB26 mAkTcdgZIgm1IcYvI4PyybfN7Vhbn3CUMD9Jg=; b=KQohcq/sC0GMw3yXiG2zl1 wNQkagqLkcXm5Z0qr1HRvxbq+a6dcmsjnuiUkWxnW1Kh7hcIh01G3FmYNt6KTeCA bjV9cLq965IEMGqW1EwrB26acjxa/T1EHtOmzR8v7dPR01hjSxzD3Rl5QUKdlOQ/ 5ShBzxxa/vjEUQ4evzH1Iinfa9hQOBNZKY6HcI5CHwisXGm1Rfg6FV+8R4WPhHGu FfSZoXsuOzmVnyLfkxFQRR7WO82CQlM6WY9UUoo5Nt9HQGwugt09/EDDHP5nyWNu 7BbfE8+CQJZPANAHRdwl5U2YQwfjePfe8BISFjmjrSWBEhswtFLvWM72dH4Cv4eA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdehtddguddulecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfh necukfhppeekledrudegrdeghedrudejtdenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-089-014-045-170.89.14.pool.telefonica.de [89.14.45.170]) by mail.messagingengine.com (Postfix) with ESMTPA id B6B5D240066; Mon, 11 Jan 2021 03:36:43 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 491542e4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 11 Jan 2021 08:36:42 +0000 (UTC) Date: Mon, 11 Jan 2021 09:36:40 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Simon Ruderich , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Jeff King , "brian m. carlson" , Philip Oakley Subject: [PATCH v7 0/8] config: allow specifying config entries via envvar pairs Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi, this is the seventh version of my patch series which aims to implement a way to pass config entries via the environment while avoiding any requirements to perform shell quoting on the user's side. The only change in this version is improved error handling for the `--config-env` switch: - Error messages are now correctly marked for translation. - A separate error message is given if no value is passed to `--config-env`. Previously, we would've tried to look up the empty environment variable (`getenv("")`). - The error message when the environment variable is missing was improved. Please see the attached ranged-diff for further details. Patrick Jeff King (2): quote: make sq_dequote_step() a public function config: parse more robust format in GIT_CONFIG_PARAMETERS Patrick Steinhardt (6): git: add `--super-prefix` to usage string config: add new way to pass config via `--config-env` config: extract function to parse config pairs config: store "git -c" variables using more robust format environment: make `getenv_safe()` a public function config: allow specifying config entries via envvar pairs Documentation/git-config.txt | 16 +++ Documentation/git.txt | 24 +++- cache.h | 1 + config.c | 208 ++++++++++++++++++++++++++++---- config.h | 1 + environment.c | 8 +- environment.h | 12 ++ git.c | 3 + quote.c | 15 ++- quote.h | 18 ++- t/t1300-config.sh | 222 ++++++++++++++++++++++++++++++++++- 11 files changed, 489 insertions(+), 39 deletions(-) create mode 100644 environment.h Range-diff against v6: 1: cd3de0743a = 1: 55fa4d0d11 git: add `--super-prefix` to usage string 2: 9b8461010e ! 2: b9cf47afe8 config: add new way to pass config via `--config-env` @@ config.c: void git_config_push_parameter(const char *text) + + env_name = strrchr(spec, '='); + if (!env_name) -+ die("invalid config format: %s", spec); ++ die(_("invalid config format: %s"), spec); + env_name++; ++ if (!*env_name) ++ die(_("missing value for --config-env")); + + env_value = getenv(env_name); + if (!env_value) -+ die("config variable missing for '%s'", env_name); ++ die(_("missing environment variable '%s' for configuration '%.*s'"), ++ env_name, (int)(env_name - spec - 1), spec); + + strbuf_add(&buf, spec, env_name - spec); + strbuf_addstr(&buf, env_value); @@ t/t1300-config.sh: test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' +test_expect_success 'git --config-env fails with invalid parameters' ' + test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && + test_i18ngrep "invalid config format" error && ++ test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error && ++ test_i18ngrep "missing value for --config-env" error && + test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error && -+ test_i18ngrep "config variable missing" error ++ test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error +' + +test_expect_success 'git -c and --config-env work together' ' 3: 9d4c8d7be9 = 3: 1b47f0db98 quote: make sq_dequote_step() a public function 4: 0a9b085fe5 = 4: b9565a050e config: extract function to parse config pairs 5: b96686c9cd ! 5: 8f998ac81a config: store "git -c" variables using more robust format @@ ## Metadata ## -Author: Jeff King +Author: Patrick Steinhardt ## Commit message ## config: store "git -c" variables using more robust format @@ config.c: void git_config_push_parameter(const char *text) env_name = strrchr(spec, '='); if (!env_name) - die("invalid config format: %s", spec); + die(_("invalid config format: %s"), spec); + key = xmemdupz(spec, env_name - spec); env_name++; - - env_value = getenv(env_name); - if (!env_value) - die("config variable missing for '%s'", env_name); + if (!*env_name) + die(_("missing value for --config-env")); +@@ config.c: void git_config_push_env(const char *spec) + die(_("missing environment variable '%s' for configuration '%.*s'"), + env_name, (int)(env_name - spec - 1), spec); - strbuf_add(&buf, spec, env_name - spec); - strbuf_addstr(&buf, env_value); 6: 6597700ffb = 6: e7b073c9dc config: parse more robust format in GIT_CONFIG_PARAMETERS 7: cade8fb12f = 7: 6c1800a18f environment: make `getenv_safe()` a public function 8: 4e3f208d13 = 8: ac9e778704 config: allow specifying config entries via envvar pairs