From patchwork Sat Jul 24 22:06:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12397863 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,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 78891C4338F for ; Sat, 24 Jul 2021 22:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B2EC60C51 for ; Sat, 24 Jul 2021 22:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230010AbhGXV01 (ORCPT ); Sat, 24 Jul 2021 17:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbhGXV00 (ORCPT ); Sat, 24 Jul 2021 17:26:26 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A374AC061575 for ; Sat, 24 Jul 2021 15:06:57 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id g15so6361558wrd.3 for ; Sat, 24 Jul 2021 15:06:57 -0700 (PDT) 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=GXZ41+jgPdyF00+igEeNjUAal2iSsNHeuyjHsFuewTY=; b=GISammVPOarrIJNC7lryImld4gM2yqHqOr2d7CKE7MXLgjxFPaI/+sQrfmTwz5NThm OBqyOFk4J+yHHJdNjjeixDXgdn9x4TNdcU72vy/J3kaoQeW2kmUJsb5h7T0g/GuB00Ao DsERpfP4n2BH2nFalQy5XQ3MEekCMmnkW8CoDG8ANOdhUqdip9Fu6RvuGP/99rFDEqt4 CpMGm+Pt+GdTXj1jkQysi+KUvtg7W9mRIMfCIKOcH+Ax9mN+XE+JDfy8ULVaxWWDzvQy HD+1xA7KQ/hZT+yiutxjmeRti+Sjc3VAUq+IGTOHa/v6u13/19gdOMEAQHcvFh+tK98R 2/iQ== 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=GXZ41+jgPdyF00+igEeNjUAal2iSsNHeuyjHsFuewTY=; b=H7dUQimZs5Wr2PCnoGpPKCwMMMAyMKisFxQmYsix2mEO/JQLfPnMoU/45FaV+bzUIW cPMPj3UraIsCeBl2FMNbHUg8+RQPWpP1s/oujtquuIQxL9QmeJBwW9nVEK39wJ5Ex7U5 zXjqF1L6ru9FEb0ppuIHoiYUjsFvc7fw9fkyDqzYZnxA4o3SKg3ZWBS3ZGIcwzcStpJZ W5sdn//2ylbjaIhELEepSzRQBudp49+WQbnRvCmGl1R7uplXM1iPikcJxHbilNQVQeMg I7t/qCavJi1k0owL7stHe/YFhfVKXK8GgBaLsI+KFz07k+Hasv2DrV1dYNy1XxRMEC9R GpEg== X-Gm-Message-State: AOAM532BSY7pswV4YSr7fML0DzvgL+Nl3jx9yfljp3VNyvzijtyAE4+x RnuaT0oEH9r25eaDP31820X3iwjaE+U= X-Google-Smtp-Source: ABdhPJw1wa0gZ7dHFO09rwSfN0cyN+JzhOLCgl8Lf5wXh0V0uYXVQiV/AyB18euFjCrFtrM8khWyMg== X-Received: by 2002:a5d:598f:: with SMTP id n15mr11491096wri.133.1627164416347; Sat, 24 Jul 2021 15:06:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d29sm45136938wrb.63.2021.07.24.15.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 15:06:55 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 24 Jul 2021 22:06:49 +0000 Subject: [PATCH v3 1/5] tests: exercise the RUNTIME_PREFIX feature Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ramsay Jones , Duy Nguyen , Junio C Hamano , Johannes Sixt , Jeff King , Eric Sunshine , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Originally, we refrained from adding a regression test in 7b6c6496374 (system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set, 2008-08-10), and in 226c0ddd0d6 (exec_cmd: RUNTIME_PREFIX on some POSIX systems, 2018-04-10). The reason was that it was deemed too tricky to test. Turns out that it is not tricky to test at all: we simply create a pseudo-root, copy the `git` executable into the `git/` subdirectory of that pseudo-root, then copy a script into the `libexec/git-core/` directory and expect that to be picked up. As long as the trash directory is in a location where binaries can be executed, this works. Signed-off-by: Johannes Schindelin --- Makefile | 5 +++++ t/t0060-path-utils.sh | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Makefile b/Makefile index c3565fc0f8f..4c3e4ccabcd 100644 --- a/Makefile +++ b/Makefile @@ -2826,6 +2826,11 @@ ifdef GIT_TEST_INDEX_VERSION endif ifdef GIT_TEST_PERL_FATAL_WARNINGS @echo GIT_TEST_PERL_FATAL_WARNINGS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_PERL_FATAL_WARNINGS)))'\' >>$@+ +endif +ifdef RUNTIME_PREFIX + @echo RUNTIME_PREFIX=\'true\' >>$@+ +else + @echo RUNTIME_PREFIX=\'false\' >>$@+ endif @if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index de4960783f0..a76728c27bf 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -525,4 +525,22 @@ test_expect_success MINGW 'is_valid_path() on Windows' ' "PRN./abc" ' +test_lazy_prereq RUNTIME_PREFIX ' + test true = "$RUNTIME_PREFIX" +' + +test_lazy_prereq CAN_EXEC_IN_PWD ' + cp "$GIT_EXEC_PATH"/git$X ./ && + ./git rev-parse +' + +test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' + mkdir -p pretend/bin pretend/libexec/git-core && + echo "echo HERE" | write_script pretend/libexec/git-core/git-here && + cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && + GIT_EXEC_PATH= ./pretend/bin/git here >actual && + echo HERE >expect && + test_cmp expect actual +' + test_done From patchwork Sat Jul 24 22:06:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12397869 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,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 109B3C4320A for ; Sat, 24 Jul 2021 22:07:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB37E608FE for ; Sat, 24 Jul 2021 22:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbhGXV0c (ORCPT ); Sat, 24 Jul 2021 17:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbhGXV01 (ORCPT ); Sat, 24 Jul 2021 17:26:27 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 308A0C061757 for ; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id j2so6302048wrx.9 for ; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) 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=651mikC42NqdxBURBS08LfDrQ3pmYpSkSnti8dRktRs=; b=SWSDv1MQFPbfGKppCalaNCZWtfyZYSckRcBMYvKgfgsVI3mSj8AlM3LKFGdWcrwKh2 fGBsaSsXCqKlwz4eOCRhjLTB59GVQeu70lpjN8ItKmgbJ5nRPf2giOyuDWTwZ+qVG6u+ eay/OMfrY5s4ScZOmePOZerqke3qBaSU6oWnaAxd3gXd1l5ZYXnWnJmcDoetqoyVvx+1 WdULKaiaEsSnTGrLOs//GXin57cjURLiMNY8/KnWfkObyv+IlTUTooRkNFQA00iLMhNC LOP8rsbehWzdqDgXc+PCIuMGfWoSJ9Tnhp7Sqg2hlB2cxb0KA8MW08/Hc8WhxFYCRnfq 9PTQ== 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=651mikC42NqdxBURBS08LfDrQ3pmYpSkSnti8dRktRs=; b=H0PYHaTH/ycasXVCPQ5UIgYQNilnGo/C2yfGrv5rJ7tdMCRJGTLtjvrv59VWIF2IiC VY6dKunv9FY3FILPjiiOB8oWbolghwwtc9Hvh8gl4dCN40wWwKYWqeOlulUW4EZwiKF2 h93oOQpOVTSHOgDNGxs3MtnSIrfoLAsJczvjgMTgq4aer6bLekYDVEN5VKXkhMytp2zH 0ktlrqUCEVhzDey9tP9Iqtf5TMJyPxVSbdZNti2vE4KDYBAmVJ0AYuYYL5jmWgMJIhm0 dp7kdx6z0tmdSh4dnFdWMlQVaIy4YOVUKvXKW2Nyqo4kNZJQFFKYiwCAvq1++OHQEYPe /uNg== X-Gm-Message-State: AOAM5303JzItB5PhWrseMcHU4ZPBY8CcpF0fx8GY3mrQt27F6SwepDxY boay/VST4O6t5978eeDfYuTExsUHkJY= X-Google-Smtp-Source: ABdhPJw/r3m9R5c2rdMQA014EtJiSnUkUwpNALl1e5wIPNpKROqrQqok3FFwph+1tFt4ckFeXPg9dg== X-Received: by 2002:a05:6000:1042:: with SMTP id c2mr11600181wrx.355.1627164416881; Sat, 24 Jul 2021 15:06:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n5sm30239481wrp.80.2021.07.24.15.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 15:06:56 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 24 Jul 2021 22:06:50 +0000 Subject: [PATCH v3 2/5] expand_user_path(): remove stale part of the comment Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ramsay Jones , Duy Nguyen , Junio C Hamano , Johannes Sixt , Jeff King , Eric Sunshine , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In 395de250d9d (Expand ~ and ~user in core.excludesfile, commit.template, 2009-11-17), the `user_path()` function was refactored into the `expand_user_path()`. During that refactoring, the `buf` parameter was lost, but the code comment above said function still talks about it. Let's remove that stale part of the comment. Signed-off-by: Johannes Schindelin --- path.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/path.c b/path.c index 7bccd830e95..3318ad24336 100644 --- a/path.c +++ b/path.c @@ -719,9 +719,8 @@ static struct passwd *getpw_str(const char *username, size_t len) } /* - * Return a string with ~ and ~user expanded via getpw*. If buf != NULL, - * then it is a newly allocated string. Returns NULL on getpw failure or - * if path is NULL. + * Return a string with ~ and ~user expanded via getpw*. Returns NULL on getpw + * failure or if path is NULL. * * If real_home is true, strbuf_realpath($HOME) is used in the expansion. */ From patchwork Sat Jul 24 22:06:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12397865 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,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 37F0DC432BE for ; Sat, 24 Jul 2021 22:07:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22CF4608FE for ; Sat, 24 Jul 2021 22:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230052AbhGXV03 (ORCPT ); Sat, 24 Jul 2021 17:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhGXV01 (ORCPT ); Sat, 24 Jul 2021 17:26:27 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFDA1C061575 for ; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id n12so2778388wrr.2 for ; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) 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=4sbo9L3WyEzpnZVRXoNExIO8xlbAV5n42dZGsSUqv5Y=; b=YLbiozst+Dx+hxrDjL9MgQeZ5M7XdbzhO5+2LVrhLvg6HZWVGnwQSSZAZxC6McqKpa NEVOu/P0PA7d4thoNrGGg0+wIpifPwVqanstpa/HEZm8Kk+tTychmuvUy+jM2fNwiQGj S3lmd097QwJdHPkJNMWbSGznpjL+KAh88iNAruqEKykIHvxuVJ3w6QiWbTmwTaoHnEZ3 raW5BMgg/z/beASZTdBuDbdvn8MCyISn/lp/y55uH2kCi/Vzp6yuXutZ+fEqAJoaesNg blmi1Gber0fGrmDGi4lFg6Wp57+m73r2j3+5jjR+m8wwCNGrNKwUGt+ZPTb655d6tRi7 rq5g== 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=4sbo9L3WyEzpnZVRXoNExIO8xlbAV5n42dZGsSUqv5Y=; b=JrRopYLrjYJOM1DtxsPmx4jKQZJ+jAFQqvWhK6BA3sfXW0PVpkxGZMrRhdpdl9nHVX r09XnVLCK+XTZ9VTzDsO05nX0LUUlK9B2n5A5Wfs3aCYXjFwA5GVPn1VqsRwPLNQEKt5 Iv+8q4JivTBFsfwGrAa+pLtdgm3qlueqIB7o6GOoHWtWtm7quTAfN1YKnqy/uDiGsu9c MMr/DhdWtKe8d9XI/glYR2DBpSsT69nBc7QIjKpVBkvXuzuw1mIodlEtLy8qxvaRVay4 NOCv/b+GxzFqBplottgpHTI5BGaDWGZZv3u/42IdZ7vnVMSJ3mKYcklQwEXbT4nIWwlf 26zA== X-Gm-Message-State: AOAM533yJ/IBORDKYfWYgb0wysLaf9JkuQw1mbHG2GH0TkAERusgJa8a SCV1u2Jx2/R3f/UvMSIZUrzUbORcyug= X-Google-Smtp-Source: ABdhPJzf9RZbb+f7wpAXS9a21Yn68tEC3PPnV4awiS3pDErpYy9faMESncA/WFj+saVXayag/DdlKQ== X-Received: by 2002:adf:f50e:: with SMTP id q14mr11509582wro.183.1627164417399; Sat, 24 Jul 2021 15:06:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s24sm39397781wra.33.2021.07.24.15.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 15:06:57 -0700 (PDT) Message-Id: <7b79ba66dd0d43f2565d2cbba268f01d3d36d052.1627164413.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 24 Jul 2021 22:06:51 +0000 Subject: [PATCH v3 3/5] expand_user_path(): clarify the role of the `real_home` parameter Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ramsay Jones , Duy Nguyen , Junio C Hamano , Johannes Sixt , Jeff King , Eric Sunshine , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `real_home` parameter only has an effect when expanding paths starting with `~/`, not when expanding paths starting with `~/`. Let's make that clear. Signed-off-by: Johannes Schindelin --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index 3318ad24336..bf329e535cf 100644 --- a/path.c +++ b/path.c @@ -722,7 +722,7 @@ static struct passwd *getpw_str(const char *username, size_t len) * Return a string with ~ and ~user expanded via getpw*. Returns NULL on getpw * failure or if path is NULL. * - * If real_home is true, strbuf_realpath($HOME) is used in the expansion. + * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion. */ char *expand_user_path(const char *path, int real_home) { From patchwork Sat Jul 24 22:06:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12397867 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,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 20F4FC4338F for ; Sat, 24 Jul 2021 22:07:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02774606A5 for ; Sat, 24 Jul 2021 22:07:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbhGXV0b (ORCPT ); Sat, 24 Jul 2021 17:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbhGXV02 (ORCPT ); Sat, 24 Jul 2021 17:26:28 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D914C06175F for ; Sat, 24 Jul 2021 15:06:59 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id y8so6296718wrt.10 for ; Sat, 24 Jul 2021 15:06:59 -0700 (PDT) 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=O6yuFn11f0SxKGCXo82ef58o5xH+q2dD0HptPT3QZl4=; b=NEDzcIgkweM/O2l4vRjRK291eTXlonB4JWdqnx2sj95qk7IlfQlOIv63KCQvwtdf6M gB8WiKtvWkkiOD/KnQfibnRfmqpaiMTJ/cI9aGXYIPaZV5/0PPDWVJsgRtNsaEoy+IhE qPPfD2WgjRQ0/yNuDbhsein35uxsJQqQ70vt4ao8lPfStZmWKYFDH9Bvg/hTQGgzBTbk zB3WZl5ZrCdy2S1grAm27hARdUbVR+dBV3ZUQQpklUoSwD+ghLKjV62DhgZ4BelIbEcP 5AwhuRMNpHaBH1LBfn/dRBp+3hqdx4eXQgXxWqTBhzfBHIrF5d9v+G2HhKt+nFkvrMYl 8Zsg== 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=O6yuFn11f0SxKGCXo82ef58o5xH+q2dD0HptPT3QZl4=; b=d9ny29/qNz3QS2IV8U8CyW8mv08BWfnM55LYIDkPF3TyvlFixlyF6Z0VSGtbFW/xsT XD/H5CD/Z8e4+Ca8gQSRZWZlvCbeJTZPq1kwE7tX2koxB79hEQpgjlXpOUL2vhyaQTIK gIRdGVj63IOcJ0qjErnDOj19ixDwXKTRUY2XVRczRRg05aXmfaELDv0HsUW1ZHUWe0pH qhd1GTAxukCw0eWDBLuMsZoAJ9L7tbY4TuBkVIGLeVxbpcqAejbsY9zZo+G6X0opa2AK oa8j+QNZYqnGeqeVAFieOLoljQUOXsX6vVzUPkKZNr6GRF1PevyjcPJW4N/mK3zsvJgc 3u3w== X-Gm-Message-State: AOAM532g3DtBzJAu+Saocms+iNty4KSnkDkC0nTs4051POgt/bBgJ88j 0pykkbP0/yu8z3EcMphy2D9X4bi7fds= X-Google-Smtp-Source: ABdhPJxaKPVIDents/pVrkqCWIIxpOWNL8TwCsaNqpfDYvkvVBzSrtG+ukZRti3JWWZSmTFRp7S/tQ== X-Received: by 2002:a5d:4c87:: with SMTP id z7mr11522852wrs.405.1627164418053; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s1sm9098294wmj.8.2021.07.24.15.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 15:06:57 -0700 (PDT) Message-Id: <19fd9c3c803a300b586c76736301a7379c4c6226.1627164413.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 24 Jul 2021 22:06:52 +0000 Subject: [PATCH v3 4/5] Use a better name for the function interpolating paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ramsay Jones , Duy Nguyen , Junio C Hamano , Johannes Sixt , Jeff King , Eric Sunshine , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin It is not immediately clear what `expand_user_path()` means, so let's rename it to `interpolate_path()`. This also opens the path for interpolating more than just a home directory. Signed-off-by: Johannes Schindelin --- builtin/credential-cache.c | 2 +- builtin/credential-store.c | 2 +- builtin/gc.c | 2 +- cache.h | 2 +- config.c | 8 ++++---- path.c | 4 ++-- sequencer.c | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 76a6ba37223..e8a74157471 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -90,7 +90,7 @@ static char *get_socket_path(void) { struct stat sb; char *old_dir, *socket; - old_dir = expand_user_path("~/.git-credential-cache", 0); + old_dir = interpolate_path("~/.git-credential-cache", 0); if (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode)) socket = xstrfmt("%s/socket", old_dir); else diff --git a/builtin/credential-store.c b/builtin/credential-store.c index ae3c1ba75fe..62a4f3c2653 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -173,7 +173,7 @@ int cmd_credential_store(int argc, const char **argv, const char *prefix) if (file) { string_list_append(&fns, file); } else { - if ((file = expand_user_path("~/.git-credentials", 0))) + if ((file = interpolate_path("~/.git-credentials", 0))) string_list_append_nodup(&fns, file); file = xdg_config_home("credentials"); if (file) diff --git a/builtin/gc.c b/builtin/gc.c index f05d2f0a1ac..6ce5ca45126 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1542,7 +1542,7 @@ static char *launchctl_service_filename(const char *name) struct strbuf filename = STRBUF_INIT; strbuf_addf(&filename, "~/Library/LaunchAgents/%s.plist", name); - expanded = expand_user_path(filename.buf, 1); + expanded = interpolate_path(filename.buf, 1); if (!expanded) die(_("failed to expand path '%s'"), filename.buf); diff --git a/cache.h b/cache.h index ba04ff8bd36..87e4cbe9c5f 100644 --- a/cache.h +++ b/cache.h @@ -1246,7 +1246,7 @@ typedef int create_file_fn(const char *path, void *cb); int raceproof_create_file(const char *path, create_file_fn fn, void *cb); int mkdir_in_gitdir(const char *path); -char *expand_user_path(const char *path, int real_home); +char *interpolate_path(const char *path, int real_home); const char *enter_repo(const char *path, int strict); static inline int is_absolute_path(const char *path) { diff --git a/config.c b/config.c index f9c400ad306..c17b9797292 100644 --- a/config.c +++ b/config.c @@ -137,7 +137,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc if (!path) return config_error_nonbool("include.path"); - expanded = expand_user_path(path, 0); + expanded = interpolate_path(path, 0); if (!expanded) return error(_("could not expand include path '%s'"), path); path = expanded; @@ -185,7 +185,7 @@ static int prepare_include_condition_pattern(struct strbuf *pat) char *expanded; int prefix = 0; - expanded = expand_user_path(pat->buf, 1); + expanded = interpolate_path(pat->buf, 1); if (expanded) { strbuf_reset(pat); strbuf_addstr(pat, expanded); @@ -1270,7 +1270,7 @@ int git_config_pathname(const char **dest, const char *var, const char *value) { if (!value) return config_error_nonbool(var); - *dest = expand_user_path(value, 0); + *dest = interpolate_path(value, 0); if (!*dest) die(_("failed to expand user dir in: '%s'"), value); return 0; @@ -1844,7 +1844,7 @@ void git_global_config(char **user_out, char **xdg_out) char *xdg_config = NULL; if (!user_config) { - user_config = expand_user_path("~/.gitconfig", 0); + user_config = interpolate_path("~/.gitconfig", 0); xdg_config = xdg_config_home("config"); } diff --git a/path.c b/path.c index bf329e535cf..8dc5ad2cb55 100644 --- a/path.c +++ b/path.c @@ -724,7 +724,7 @@ static struct passwd *getpw_str(const char *username, size_t len) * * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion. */ -char *expand_user_path(const char *path, int real_home) +char *interpolate_path(const char *path, int real_home) { struct strbuf user_path = STRBUF_INIT; const char *to_copy = path; @@ -811,7 +811,7 @@ const char *enter_repo(const char *path, int strict) strbuf_add(&validated_path, path, len); if (used_path.buf[0] == '~') { - char *newpath = expand_user_path(used_path.buf, 0); + char *newpath = interpolate_path(used_path.buf, 0); if (!newpath) return NULL; strbuf_attach(&used_path, newpath, strlen(newpath), diff --git a/sequencer.c b/sequencer.c index 0bec01cf38e..007a851804d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1241,7 +1241,7 @@ N_("Your name and email address were configured automatically based\n" static const char *implicit_ident_advice(void) { - char *user_config = expand_user_path("~/.gitconfig", 0); + char *user_config = interpolate_path("~/.gitconfig", 0); char *xdg_config = xdg_config_home("config"); int config_exists = file_exists(user_config) || file_exists(xdg_config); From patchwork Sat Jul 24 22:06:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12397871 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,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 5420CC432BE for ; Sat, 24 Jul 2021 22:07:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C160606A5 for ; Sat, 24 Jul 2021 22:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbhGXV0d (ORCPT ); Sat, 24 Jul 2021 17:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbhGXV02 (ORCPT ); Sat, 24 Jul 2021 17:26:28 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C4EC061760 for ; Sat, 24 Jul 2021 15:07:00 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id m38-20020a05600c3b26b02902161fccabf1so5698915wms.2 for ; Sat, 24 Jul 2021 15:06:59 -0700 (PDT) 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:mime-version :content-transfer-encoding:fcc:to:cc; bh=lnQvCCgXIKYagGNLDYsPxjYsJR3p/tSWk47a9/2CEyM=; b=tPE8T248l5PQSIRhK26ScMfePUvs180N/RxZKLKciSBuqEABHFav526z97+gm5eWfI mkQgd9Z649yVnvmqIayfzy23yg4hQ/gUlir2IatkhbESvbECVhQXh+aLCHGqKA37rG0g WpWA4bC9/OQYnjK/vXgGZsztL3HQnvT47Hgb6urtktjOeGx2izaqwMfOSFxvOb6W6H/n c++VXgfekmJUrsl/HZTWW/cC19ap1LGYIqWl9N+nokbY8QfsbdO8zCC+8qRO60S8d4mS MctUSMfC9h4QFVN5XjqRDeePhBYGrzq0NodDD1xYurzFqmzKzkVT5nmO9AjS66SQEhd8 A9uA== 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:mime-version:content-transfer-encoding:fcc:to:cc; bh=lnQvCCgXIKYagGNLDYsPxjYsJR3p/tSWk47a9/2CEyM=; b=HRwmERuFzyloG9recsoLVB1TeKoOepyC/LtsyCPORQfdlqkMi2iZf9P4XOTGejNA96 2ctOvN3DijmQMPSjl/jE199T3i3OMvBjw5szt91AGrzanxpj1G8GSjLgGTIOIsHsbibT 0o4YFzkC/gQ9xT+GBrXalDVCi1Puc2/ioBI3vrfea7HMoZYOO7h8zfSbyhm1wXtePTFQ hNj6OtganuFAC7X0ipVor5aOlzQZxVCqi4Hx9Omlogb0I0kQVv5RU/Y+hDTJPzDnG385 DmnUoIt/grtw6M0u7RVIhTn/nIvVEtATGzYEiGJR3DR9J0TSPqaWV4iv9JlsqtINWsUX XCBA== X-Gm-Message-State: AOAM533gxY2nsiaZYkzPvJCNEZbl6r9kw0bmS/i5n+uuSWrWXISOt0IE N1C41d0LPR3dEtLKGMvjmAWnA0aCpU8= X-Google-Smtp-Source: ABdhPJw5R2OgikwdMt34CbXD13pDSo+KlDVG3dMtytQ0zj8gRgtn2RKWU6SIDO++NgS7AvYVL/nOcQ== X-Received: by 2002:a7b:c208:: with SMTP id x8mr1913692wmi.42.1627164418637; Sat, 24 Jul 2021 15:06:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k13sm37873950wrp.34.2021.07.24.15.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 15:06:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 24 Jul 2021 22:06:53 +0000 Subject: [PATCH v3 5/5] interpolate_path(): allow specifying paths relative to the runtime prefix MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Ramsay Jones , Duy Nguyen , Junio C Hamano , Johannes Sixt , Jeff King , Eric Sunshine , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Ever since Git learned to detect its install location at runtime, there was the slightly awkward problem that it was impossible to specify paths relative to said location. For example, if a version of Git was shipped with custom SSL certificates to use, there was no portable way to specify `http.sslCAInfo`. In Git for Windows, the problem was "solved" for years by interpreting paths starting with a slash as relative to the runtime prefix. However, this is not correct: such paths _are_ legal on Windows, and they are interpreted as absolute paths in the same drive as the current directory. After a lengthy discussion, and an even lengthier time to mull over the problem and its best solution, and then more discussions, we eventually decided to introduce support for the magic sequence `%(prefix)/`. If a path starts with this, the remainder is interpreted as relative to the detected (runtime) prefix. If built without runtime prefix support, Git will simply interpolate the compiled-in prefix. If a user _wants_ to specify a path starting with the magic sequence, they can prefix the magic sequence with `./` and voilĂ , the path won't be expanded. Signed-off-by: Johannes Schindelin --- Documentation/config.txt | 9 +++++++++ path.c | 8 ++++++++ t/t0060-path-utils.sh | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index bf82766a6a2..0c0e6b859f1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -298,6 +298,15 @@ pathname:: tilde expansion happens to such a string: `~/` is expanded to the value of `$HOME`, and `~user/` to the specified user's home directory. ++ +If a path starts with `%(prefix)/`, the remainder is interpreted as a +path relative to Git's "runtime prefix", i.e. relative to the location +where Git itself was installed. For example, `%(prefix)/bin/` refers to +the directory in which the Git executable itself lives. If Git was +compiled without runtime prefix support, the compiled-in prefix will be +subsituted instead. In the unlikely event that a literal path needs to +be specified that should _not_ be expanded, it needs to be prefixed by +`./`, like so: `./%(prefix)/bin`. Variables diff --git a/path.c b/path.c index 8dc5ad2cb55..0bc788ea40f 100644 --- a/path.c +++ b/path.c @@ -12,6 +12,7 @@ #include "packfile.h" #include "object-store.h" #include "lockfile.h" +#include "exec-cmd.h" static int get_st_mode_bits(const char *path, int *mode) { @@ -723,6 +724,9 @@ static struct passwd *getpw_str(const char *username, size_t len) * failure or if path is NULL. * * If real_home is true, strbuf_realpath($HOME) is used in the `~/` expansion. + * + * If the path starts with `%(prefix)/`, the remainder is interpreted as + * relative to where Git is installed, and expanded to the absolute path. */ char *interpolate_path(const char *path, int real_home) { @@ -731,6 +735,10 @@ char *interpolate_path(const char *path, int real_home) if (path == NULL) goto return_null; + + if (skip_prefix(path, "%(prefix)/", &path)) + return system_path(path); + if (path[0] == '~') { const char *first_slash = strchrnul(path, '/'); const char *username = path + 1; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index a76728c27bf..34d1061f321 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -540,6 +540,14 @@ test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && GIT_EXEC_PATH= ./pretend/bin/git here >actual && echo HERE >expect && + test_cmp expect actual' + +test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' + mkdir -p pretend/bin && + cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && + git config yes.path "%(prefix)/yes" && + GIT_EXEC_PATH= ./pretend/bin/git config --path yes.path >actual && + echo "$(pwd)/pretend/yes" >expect && test_cmp expect actual '