From patchwork Tue Dec 20 12:39:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077850 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84E7AC3DA6E for ; Tue, 20 Dec 2022 12:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233761AbiLTMnd (ORCPT ); Tue, 20 Dec 2022 07:43:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233747AbiLTMnE (ORCPT ); Tue, 20 Dec 2022 07:43:04 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAA861ADAE for ; Tue, 20 Dec 2022 04:40:17 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id i187-20020a1c3bc4000000b003d1e906ca23so8108250wma.3 for ; Tue, 20 Dec 2022 04:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zSzeH7luLu4Pkp0byFVjuqOXJIB7KyJBRfz3RD90wb4=; b=Jv+sH94/aRL0t/HX9F+X69QFpMUGseP7GpOY74rflu4BDs4JEhCMIciXRkrBypT3Wb qaq7mxh8jtMttf8Btf3sxrtrZkeofLFicbBWFy1hE4zCUG/LU8CNN4saXy+ZqyKT/z1W w/LVrBudHqhpzlUidlkIUWAGOtBE75/e97BpcMO1oy/zp+YmHNzM+Tj1/uQ/3yTVLQ8D RZ1jEV+4dFxaEd9EhXdrWOhciOwJHMVCUR2FKS/6qvzCngA0k6FyGiRTdzU0MmPrJnui 0x3FqCIkbaXPDSLFT1tE/FkK/T7HTW4dPNMgES/WJWCNo40/c9UG8qYj7cMXKo+7KNa3 zGhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zSzeH7luLu4Pkp0byFVjuqOXJIB7KyJBRfz3RD90wb4=; b=yYtueas8OkyAqnSWDr5GqmQ+t4CoVyUYo4qxEK4klj1vKM8mRBojT8T42tW2aqS9fR 1SB9BDSw/Ec5n8p3TNHY3AzFufTPwmgpIfd1JRGFPY0lOvAdkVpiy/SN8M2KNGlUMsE6 zgpKE/eEOpNwdoAiVOmh4Y113OAMMgAJ/m5tv+Q/z1mC72mNAvTvswutCvZqCzlJTYoX aYcwLunEKHyypcDe2ZHwwZjL34JmUJplWwbir4LwbUE8E7mUWrzjMv+eKuTdzExQ4Iiw 4MXcKK3j6h4O4I2nPfiilpVWppPqVSd7N/WqIZ7LH1aHRCfhlBNvngsMFYOW/P0MX1o8 xWyQ== X-Gm-Message-State: AFqh2kqoTm8/q0z4XNdJGh4dTyx14HrRNikPaB8AM43eOHyMc3+58MNP zTl03AYXZwsZVVK2rpPc1yZipHJ8mHvuuw== X-Google-Smtp-Source: AMrXdXu27uFDBCfL7+PQkeJnSYn8J24Oaoj8w2kq9LF1PQTgzT/lJpbX8ZwpOqzmjAj5m1fLhFue/Q== X-Received: by 2002:a05:600c:3d1b:b0:3cf:497c:c59e with SMTP id bh27-20020a05600c3d1b00b003cf497cc59emr1513087wmb.6.1671540002236; Tue, 20 Dec 2022 04:40:02 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:01 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 1/9] submodule absorbgitdirs tests: add missing "Migrating git..." tests Date: Tue, 20 Dec 2022 13:39:48 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a blind spots in the tests surrounding "submodule absorbgitdirs" and test what output we emit, and how emitted the message and behavior interacts with a "git worktree" where the repository isn't at the base of the working directory. The "$(pwd)" instead of "$PWD" here is needed due to Windows, where the latter will be a path like "/d/a/git/[...]", whereas we need "D:/a/git/[...]". Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7412-submodule-absorbgitdirs.sh | 64 ++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 2859695c6d2..f7783218576 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -10,6 +10,7 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup a real submodule' ' + cwd="$(pwd)" && git init sub1 && test_commit -C sub1 first && git submodule add ./sub1 && @@ -18,13 +19,21 @@ test_expect_success 'setup a real submodule' ' ' test_expect_success 'absorb the git dir' ' + >expect && + >actual && >expect.1 && >expect.2 && >actual.1 && >actual.2 && git status >expect.1 && git -C sub1 rev-parse HEAD >expect.2 && - git submodule absorbgitdirs && + cat >expect <<-EOF && + Migrating git directory of '\''sub1'\'' from + '\''$cwd/sub1/.git'\'' to + '\''$cwd/.git/modules/sub1'\'' + EOF + git submodule absorbgitdirs 2>actual && + test_cmp expect actual && git fsck && test -f sub1/.git && test -d .git/modules/sub1 && @@ -37,7 +46,8 @@ test_expect_success 'absorb the git dir' ' test_expect_success 'absorbing does not fail for deinitialized submodules' ' test_when_finished "git submodule update --init" && git submodule deinit --all && - git submodule absorbgitdirs && + git submodule absorbgitdirs 2>err && + test_must_be_empty err && test -d .git/modules/sub1 && test -d sub1 && ! test -e sub1/.git @@ -56,7 +66,13 @@ test_expect_success 'setup nested submodule' ' test_expect_success 'absorb the git dir in a nested submodule' ' git status >expect.1 && git -C sub1/nested rev-parse HEAD >expect.2 && - git submodule absorbgitdirs && + cat >expect <<-EOF && + Migrating git directory of '\''sub1/nested'\'' from + '\''$cwd/sub1/nested/.git'\'' to + '\''$cwd/.git/modules/sub1/modules/nested'\'' + EOF + git submodule absorbgitdirs 2>actual && + test_cmp expect actual && test -f sub1/nested/.git && test -d .git/modules/sub1/modules/nested && git status >actual.1 && @@ -87,7 +103,13 @@ test_expect_success 're-setup nested submodule' ' test_expect_success 'absorb the git dir in a nested submodule' ' git status >expect.1 && git -C sub1/nested rev-parse HEAD >expect.2 && - git submodule absorbgitdirs && + cat >expect <<-EOF && + Migrating git directory of '\''sub1'\'' from + '\''$cwd/sub1/.git'\'' to + '\''$cwd/.git/modules/sub1'\'' + EOF + git submodule absorbgitdirs 2>actual && + test_cmp expect actual && test -f sub1/.git && test -f sub1/nested/.git && test -d .git/modules/sub1/modules/nested && @@ -97,6 +119,27 @@ test_expect_success 'absorb the git dir in a nested submodule' ' test_cmp expect.2 actual.2 ' +test_expect_success 'absorb the git dir outside of primary worktree' ' + test_when_finished "rm -rf repo-bare.git" && + git clone --bare . repo-bare.git && + test_when_finished "rm -rf repo-wt" && + git -C repo-bare.git worktree add ../repo-wt && + + test_when_finished "rm -f .gitconfig" && + test_config_global protocol.file.allow always && + git -C repo-wt submodule update --init && + git init repo-wt/sub2 && + test_commit -C repo-wt/sub2 A && + git -C repo-wt submodule add ./sub2 sub2 && + cat >expect <<-EOF && + Migrating git directory of '\''sub2'\'' from + '\''$cwd/repo-wt/sub2/.git'\'' to + '\''$cwd/repo-bare.git/worktrees/repo-wt/modules/sub2'\'' + EOF + git -C repo-wt submodule absorbgitdirs 2>actual && + test_cmp expect actual +' + test_expect_success 'setup a gitlink with missing .gitmodules entry' ' git init sub2 && test_commit -C sub2 first && @@ -107,7 +150,11 @@ test_expect_success 'setup a gitlink with missing .gitmodules entry' ' test_expect_success 'absorbing the git dir fails for incomplete submodules' ' git status >expect.1 && git -C sub2 rev-parse HEAD >expect.2 && - test_must_fail git submodule absorbgitdirs && + cat >expect <<-\EOF && + fatal: could not lookup name for submodule '\''sub2'\'' + EOF + test_must_fail git submodule absorbgitdirs 2>actual && + test_cmp expect actual && git -C sub2 fsck && test -d sub2/.git && git status >actual && @@ -127,8 +174,11 @@ test_expect_success 'setup a submodule with multiple worktrees' ' ' test_expect_success 'absorbing fails for a submodule with multiple worktrees' ' - test_must_fail git submodule absorbgitdirs sub3 2>error && - test_i18ngrep "not supported" error + cat >expect <<-\EOF && + fatal: could not lookup name for submodule '\''sub2'\'' + EOF + test_must_fail git submodule absorbgitdirs 2>actual && + test_cmp expect actual ' test_done From patchwork Tue Dec 20 12:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA6D3C4167B for ; Tue, 20 Dec 2022 12:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232209AbiLTMnb (ORCPT ); Tue, 20 Dec 2022 07:43:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233890AbiLTMnE (ORCPT ); Tue, 20 Dec 2022 07:43:04 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D680C1CFE2 for ; Tue, 20 Dec 2022 04:40:17 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m19so8590741wms.5 for ; Tue, 20 Dec 2022 04:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DDeV4GVeBwo8GeLUmGbBP9Kp3rbdYeGp+Yoo2c8FYXk=; b=QaTinUA8eSZtBULmnY/MXDb8YzqbyPEjfD/ZqYFE0ffRNWKPKMYZj5qib+SnVrG3Xf vC/uCMbRn7+TiGzBeY0tupD6b8h84PcahoF2RVaQL5jkvegQskEmBqICt18sKWGGtX5y tPoLg5d1bpbPUoe8UPcCBxrWACMXC/yJ9QnzZAbs99olSG6Uh0Thp2HHGkuptzGQH+Ty 1ZMyDgSMOijuPZXYEe2CqNuZ/tH5DLNTWYwvlPq7NIeyYXyEBvGO1RTHYFg3fnQRY2I2 BVUOataKXayt+ec9EjASUsx2PPrHxE9suSwso14OZhUnY7eTXdw6kl+i3BUK+ZT02H4F 9frQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DDeV4GVeBwo8GeLUmGbBP9Kp3rbdYeGp+Yoo2c8FYXk=; b=gXJbBdYBfmPDk3L/YtMfWwoxX12P4JppLIN01/wPBjBRcGOxDwyc6l8qpDBEDPvOaF mX243FnCRbnS3SWClnG1qn3SMeosxLR0LeIYmJ6V1fB1Kf3eqVFDfXcW9r4dKh9EBTei Xai4VDYI+98owofUzwSQ2ocJizphIFoLP7+8cbx13LjznuLhtN4zosoipkUIY72/isWx MtyZ3jk39D8DIzt/eJPzEFWyKhJFxj+tdK0OnhU25ewbWl1ycLAajgja927wrDXU6YFu 6SbWiKOPMz3NOc+U8KvMc5sXwsmgR7FIKaFjjy5ipc1zEmJNaUpvmpRWAa8FIejGFMu7 bvkA== X-Gm-Message-State: AFqh2krhFUY59JbxDDbylbhhR+tONKGbbIwoHFRGcdZN5IddM0OF1NMi zZqQl+TDzvKSrF/n8z7BMxRWWsjHmtZXsg== X-Google-Smtp-Source: AMrXdXthASjzYWR+txkd7AtwxvF9N5HFsT/fHQY8LjPKAMbUfARlIb8S+kRe+riovX2seFjEyDX6xg== X-Received: by 2002:a05:600c:5124:b0:3d6:10e:68a8 with SMTP id o36-20020a05600c512400b003d6010e68a8mr973286wms.0.1671540003273; Tue, 20 Dec 2022 04:40:03 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:02 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 2/9] read-tree + fetch tests: test failing "--super-prefix" interaction Date: Tue, 20 Dec 2022 13:39:49 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo Ever since "git fetch --refetch" was introduced in 0f5e8851737 (Merge branch 'rc/fetch-refetch', 2022-04-04) the test being added here would fail. This is because "restore" will "read-tree .. --reset ", which will in turn invoke "fetch". The "fetch" will then die with: fatal: fetch doesn't support --super-prefix This edge case and other "--super-prefix" bugs will be fixed in subsequent commits, but let's first add a "test_expect_failure" test for it. It passes until the very last command in the test. Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5616-partial-clone.sh | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 037941b95d2..2846ec6629c 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -644,6 +644,49 @@ test_expect_success 'repack does not loosen promisor objects' ' grep "loosen_unused_packed_objects/loosened:0" trace ' +test_expect_failure 'lazy-fetch in submodule succeeds' ' + # setup + test_config_global protocol.file.allow always && + + test_when_finished "rm -rf src-sub" && + git init src-sub && + git -C src-sub config uploadpack.allowfilter 1 && + git -C src-sub config uploadpack.allowanysha1inwant 1 && + + # This blob must be missing in the subsequent commit. + echo foo >src-sub/file && + git -C src-sub add file && + git -C src-sub commit -m "submodule one" && + SUB_ONE=$(git -C src-sub rev-parse HEAD) && + + echo bar >src-sub/file && + git -C src-sub add file && + git -C src-sub commit -m "submodule two" && + SUB_TWO=$(git -C src-sub rev-parse HEAD) && + + test_when_finished "rm -rf src-super" && + git init src-super && + git -C src-super config uploadpack.allowfilter 1 && + git -C src-super config uploadpack.allowanysha1inwant 1 && + git -C src-super submodule add ../src-sub src-sub && + + git -C src-super/src-sub checkout $SUB_ONE && + git -C src-super add src-sub && + git -C src-super commit -m "superproject one" && + + git -C src-super/src-sub checkout $SUB_TWO && + git -C src-super add src-sub && + git -C src-super commit -m "superproject two" && + + # the fetch + test_when_finished "rm -rf client" && + git clone --filter=blob:none --also-filter-submodules \ + --recurse-submodules "file://$(pwd)/src-super" client && + + # Trigger lazy-fetch from the superproject + git -C client restore --recurse-submodules --source=HEAD^ :/ +' + . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd From patchwork Tue Dec 20 12:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 878D8C4332F for ; Tue, 20 Dec 2022 12:43:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233747AbiLTMng (ORCPT ); Tue, 20 Dec 2022 07:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233764AbiLTMnH (ORCPT ); Tue, 20 Dec 2022 07:43:07 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A96361ADB0 for ; Tue, 20 Dec 2022 04:40:19 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id r206-20020a1c44d7000000b003d6b8e8e07fso63633wma.0 for ; Tue, 20 Dec 2022 04:40:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1yqB/IQjPU0JdPCGgeUmhzJaK+oHnrbiIoWKnKW7KTI=; b=ETgGfQPXuVkI2CFJCyB3ypQuRoR4kEiDT6433BX3WANxhoE9Dz1O8iTwvMUiKoRKAr fl1LMQ5opZrD2KuXqovHZCPkj0KbUD4E/MiprRBpwgBjPHWVTn6AXkftQ6idEbmuO0up 76eLEa6OfJ1NW0/z7MCnqTrJ6RVR3BrmeU/Gr0rvERNatbgR4VEhyp608fd6tcCrnHNE /ny0OjDy23Bzh4GrFK3vvDdK7x0pl+L0BHJ9jqOjl4f4LodfUJGH1Evr2MgkBcpVHYAZ xo4XvlUy7FUKhSrcr8xB0cc3AQ77VegUkjjlCL5WB7V16W65pvE906/frlFVSLhIjcmc tZUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1yqB/IQjPU0JdPCGgeUmhzJaK+oHnrbiIoWKnKW7KTI=; b=fU6QZNeF1gtm0J4UU06CcQkE5B9TWKpzr2vzYy0DxteMnAIpz+IPZP05VhnUcm8Tdy ddfpD37GFTl31C7pb87R8mbiu+BNYIYTE1jaA7vA2X+61zZ8MGwY92/NtmtJx7dgC1SF 3av2ieDhmFvKVNdbt5Skni3LL6dtQrxsys1/omdI0Y+PbAu61aIboWushwD5Ww+nbybq DmYtIKWnMxG42cjWVdzFCOboipY4mkrAlB+oT12vwvoFN303briaJ+Oz7REnShK9iicr y3wq/hqRzcpZEbLdLeFDLwFgvKWYh/f3AQtasRySzXleEhPuVTN0G+4+TXR0SGp71wQb ghqA== X-Gm-Message-State: ANoB5pn3chOLdQTBq1EGE7NZCtBC63nFTGz5l8A4dAwHsIcrXwTcA3iL c/fC11EFiA1z6hOUXwXcmG/zb3xKcoFanw== X-Google-Smtp-Source: AA0mqf51uwbwEoZgDNlu6QzGx1FNXgXF/tBKYz+Ludt33M1p/NR0c9R98EpVnHA5pRvkrOCeS/AZFA== X-Received: by 2002:a05:600c:2252:b0:3d2:196c:270c with SMTP id a18-20020a05600c225200b003d2196c270cmr29159726wmm.31.1671540004291; Tue, 20 Dec 2022 04:40:04 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:03 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 3/9] submodule.c & submodule--helper: pass along "super_prefix" param Date: Tue, 20 Dec 2022 13:39:50 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Start passing the "super_prefix" along as a parameter to get_submodule_displaypath() and absorb_git_dir_into_superproject(), rather than get the value directly as a global. This is in preparation for subsequent commits, where we'll gradually phase out get_super_prefix() for an alternative way of getting the "super_prefix". Most of the users of this get a get_super_prefix() value, either directly or by indirection. The exceptions are: - builtin/rm.c: Doesn't declare SUPPORT_SUPER_PREFIX, so we'd have died if this was provided, so it's safe to pass "NULL". - deinit_submodule(): The "deinit_submodule()" function has never been able to use the "git -super-prefix". It will call "absorb_git_dir_into_superproject()", but it will only do so from the top-level project. If "absorbgitdirs" recurses will use the "path" passed to "absorb_git_dir_into_superproject()" in "deinit_submodule()" as its starting "--super-prefix". So we can safely remove the get_super_prefix() call here, and pass NULL instead. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rm.c | 2 +- builtin/submodule--helper.c | 35 ++++++++++++++++++++++------------- submodule.c | 15 +++++++++------ submodule.h | 3 ++- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/builtin/rm.c b/builtin/rm.c index d4989d4d863..4a4aec0d00e 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -86,7 +86,7 @@ static void submodules_absorb_gitdir_if_needed(void) continue; if (!submodule_uses_gitfile(name)) - absorb_git_dir_into_superproject(name); + absorb_git_dir_into_superproject(name, NULL); } } diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 05f2c9bc985..da844cad5ce 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -113,10 +113,9 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int } /* the result should be freed by the caller. */ -static char *get_submodule_displaypath(const char *path, const char *prefix) +static char *get_submodule_displaypath(const char *path, const char *prefix, + const char *super_prefix) { - const char *super_prefix = get_super_prefix(); - if (prefix && super_prefix) { BUG("cannot have prefix '%s' and superprefix '%s'", prefix, super_prefix); @@ -294,7 +293,8 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, struct child_process cp = CHILD_PROCESS_INIT; char *displaypath; - displaypath = get_submodule_displaypath(path, info->prefix); + displaypath = get_submodule_displaypath(path, info->prefix, + get_super_prefix()); sub = submodule_from_path(the_repository, null_oid(), path); @@ -447,7 +447,8 @@ static void init_submodule(const char *path, const char *prefix, const char *upd; char *url = NULL, *displaypath; - displaypath = get_submodule_displaypath(path, prefix); + displaypath = get_submodule_displaypath(path, prefix, + get_super_prefix()); sub = submodule_from_path(the_repository, null_oid(), path); @@ -624,7 +625,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, die(_("no submodule mapping found in .gitmodules for path '%s'"), path); - displaypath = get_submodule_displaypath(path, prefix); + displaypath = get_submodule_displaypath(path, prefix, + get_super_prefix()); if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) { print_status(flags, 'U', path, null_oid(), displaypath); @@ -948,7 +950,8 @@ static void generate_submodule_summary(struct summary_cb *info, dst_abbrev = xstrndup(oid_to_hex(&p->oid_dst), 7); } - displaypath = get_submodule_displaypath(p->sm_path, info->prefix); + displaypath = get_submodule_displaypath(p->sm_path, info->prefix, + get_super_prefix()); if (!missing_src && !missing_dst) { struct child_process cp_rev_list = CHILD_PROCESS_INIT; @@ -1239,7 +1242,8 @@ static void sync_submodule(const char *path, const char *prefix, super_config_url = xstrdup(""); } - displaypath = get_submodule_displaypath(path, prefix); + displaypath = get_submodule_displaypath(path, prefix, + get_super_prefix()); if (!(flags & OPT_QUIET)) printf(_("Synchronizing submodule url for '%s'\n"), @@ -1365,7 +1369,7 @@ static void deinit_submodule(const char *path, const char *prefix, if (!sub || !sub->name) goto cleanup; - displaypath = get_submodule_displaypath(path, prefix); + displaypath = get_submodule_displaypath(path, prefix, NULL); /* remove the submodule work tree (unless the user already did it) */ if (is_directory(path)) { @@ -1379,7 +1383,7 @@ static void deinit_submodule(const char *path, const char *prefix, ".git file by using absorbgitdirs."), displaypath); - absorb_git_dir_into_superproject(path); + absorb_git_dir_into_superproject(path, NULL); } @@ -1958,7 +1962,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, enum submodule_update_type update_type; char *key; const struct update_data *ud = suc->update_data; - char *displaypath = get_submodule_displaypath(ce->name, ud->prefix); + char *displaypath = get_submodule_displaypath(ce->name, ud->prefix, + get_super_prefix()); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; int need_free_url = 0; @@ -2608,7 +2613,8 @@ static int update_submodules(struct update_data *update_data) goto fail; update_data->displaypath = get_submodule_displaypath( - update_data->sm_path, update_data->prefix); + update_data->sm_path, update_data->prefix, + get_super_prefix()); code = update_submodule(update_data); FREE_AND_NULL(update_data->displaypath); fail: @@ -2828,6 +2834,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) int i; struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; + const char *super_prefix; struct option embed_gitdir_options[] = { OPT_END() }; @@ -2843,8 +2850,10 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) if (module_list_compute(argv, prefix, &pathspec, &list) < 0) goto cleanup; + super_prefix = get_super_prefix(); for (i = 0; i < list.nr; i++) - absorb_git_dir_into_superproject(list.entries[i]->name); + absorb_git_dir_into_superproject(list.entries[i]->name, + super_prefix); ret = 0; cleanup: diff --git a/submodule.c b/submodule.c index 8ac2fca855d..bf19598b8c2 100644 --- a/submodule.c +++ b/submodule.c @@ -2145,7 +2145,8 @@ int submodule_move_head(const char *path, if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { if (old_head) { if (!submodule_uses_gitfile(path)) - absorb_git_dir_into_superproject(path); + absorb_git_dir_into_superproject(path, + get_super_prefix()); } else { struct strbuf gitdir = STRBUF_INIT; submodule_name_to_gitdir(&gitdir, the_repository, @@ -2315,7 +2316,8 @@ static void relocate_single_git_dir_into_superproject(const char *path) strbuf_release(&new_gitdir); } -static void absorb_git_dir_into_superproject_recurse(const char *path) +static void absorb_git_dir_into_superproject_recurse(const char *path, + const char *super_prefix) { struct child_process cp = CHILD_PROCESS_INIT; @@ -2323,8 +2325,8 @@ static void absorb_git_dir_into_superproject_recurse(const char *path) cp.dir = path; cp.git_cmd = 1; cp.no_stdin = 1; - strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); + strvec_pushf(&cp.args, "--super-prefix=%s%s/", super_prefix ? + super_prefix : "", path); strvec_pushl(&cp.args, "submodule--helper", "absorbgitdirs", NULL); prepare_submodule_repo_env(&cp.env); @@ -2337,7 +2339,8 @@ static void absorb_git_dir_into_superproject_recurse(const char *path) * having its git directory within the working tree to the git dir nested * in its superprojects git dir under modules/. */ -void absorb_git_dir_into_superproject(const char *path) +void absorb_git_dir_into_superproject(const char *path, + const char *super_prefix) { int err_code; const char *sub_git_dir; @@ -2386,7 +2389,7 @@ void absorb_git_dir_into_superproject(const char *path) } strbuf_release(&gitdir); - absorb_git_dir_into_superproject_recurse(path); + absorb_git_dir_into_superproject_recurse(path, super_prefix); } int get_superproject_working_tree(struct strbuf *buf) diff --git a/submodule.h b/submodule.h index b52a4ff1e73..f90ee547d08 100644 --- a/submodule.h +++ b/submodule.h @@ -164,7 +164,8 @@ void submodule_unset_core_worktree(const struct submodule *sub); */ void prepare_submodule_repo_env(struct strvec *env); -void absorb_git_dir_into_superproject(const char *path); +void absorb_git_dir_into_superproject(const char *path, + const char *super_prefix); /* * Return the absolute path of the working tree of the superproject, which this From patchwork Tue Dec 20 12:39:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B123CC4332F for ; Tue, 20 Dec 2022 12:43:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233804AbiLTMnk (ORCPT ); Tue, 20 Dec 2022 07:43:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbiLTMnH (ORCPT ); Tue, 20 Dec 2022 07:43:07 -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 D6FAC1CFDF for ; Tue, 20 Dec 2022 04:40:19 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id ja17so8594635wmb.3 for ; Tue, 20 Dec 2022 04:40:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MuAlp611vdaUwy7xf5zt9ILKfZsIDXObZBlnq7skH8M=; b=qPgQKrLHPJ1QN8PaWr3oGIPX5Cu7dIrt+1vt0gDwbp7MIjiUcBuMMIchDJjvJBMRe7 Dv/NqIxtE5tO5lecN6Rm7od7VLlCQBkzHiSo3wzit134/gJM+99xY2FWjdW2ygDH2rIk ohogGp4kqnyp6k144WeoIkSXGOIYaKlewbNUT+VBoC8y09CVwyFWGoHvCjLVyuaaM1wX eZQ5wvbncfMPa4zUt1nUaEC/9RuKNCXCDP6ZqPZlZYjG25y1GJBwUGvE5zVL5y8peiIv 165xa+frROZJLnqkVlVUfOMpFvKf2AJocVygxTVgLpWLXMNRKg/VWY9dx6Eq7gGehWLH o2LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MuAlp611vdaUwy7xf5zt9ILKfZsIDXObZBlnq7skH8M=; b=alpPF+df9hG/Hdc9PsulAJvFQ88cUGIENOC2n3RZMPrKlbkvWvAJ2QFsAFlfd6EQdM cyNpCKBXY74I+H/xDbVAIH633PAxtEqVjwjD/PabMqz5BXFtkopct3bGL5izNcNrNOm3 XG4KSC7ymCxm5J96Vwkhr7vabTDiEdAHiczMUXGVtwiEVlVAd1K0h6O5ZEyEMo/l6HPX oYGAj0/1P/NgQdmsDDreNHbMfcsjpDT+HghRmfOl20ef8tj81FO9IUZkO9qX42p0w25D NCOCY8RIoL390vcTlyz/jMq2shrLv1vJKBBhFXfNdt2o40TsU3B3p4O4XSv/vO+AhlFE WvTw== X-Gm-Message-State: ANoB5pnt9BgDg7H4iJgRpRGQRVex79N5WelEZ+UMlQt25/d2WqT987Gi zqf+5+c+IiuFoShv6gWjgePQrasv5o05+g== X-Google-Smtp-Source: AA0mqf60f3dsnz4QjgPJ0LtHaoVwJM2VVpl6ZtwgMlg/mW8Zi9OfOFqq7CgcfW79ieOPg1glhkqy3g== X-Received: by 2002:a05:600c:538f:b0:3d1:d396:1ade with SMTP id hg15-20020a05600c538f00b003d1d3961ademr35340584wmb.9.1671540005310; Tue, 20 Dec 2022 04:40:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:04 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 4/9] submodule--helper: don't use global --super-prefix in "absorbgitdirs" Date: Tue, 20 Dec 2022 13:39:51 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "--super-prefix" facility was introduced in [1] has always been a transitory hack, which is why we've made it an error to supply it as an option to "git" to commands that don't know about it. That's been a good goal, as it has a global effect we haven't wanted calls to get_super_prefix() from built-ins we didn't expect. But it has meant that when we've had chains of different built-ins using it all of the processes in that "chain" have needed to support it, and worse processes that don't need it have needed to ask for "SUPPORT_SUPER_PREFIX" because their parent process needs it. That's how "fsmonitor--daemon" ended up with it, per [2] it's called from (among other things) "submodule--helper absorbgitdirs", but as we declared "submodule--helper" as "SUPPORT_SUPER_PREFIX" we needed to declare "fsmonitor--daemon" as accepting it too, even though it doesn't care about it. But in the case of "absorbgitdirs" it only needed "--super-prefix" to invoke itself recursively, and we'd never have another "in-between" process in the chain. So we didn't need the bigger hammer of "git --super-prefix", and the "setenv(GIT_SUPER_PREFIX_ENVIRONMENT, ...)" that it entails. Let's instead accept a hidden "--super-prefix" option to "submodule--helper absorbgitdirs" itself. Eventually (as with all other "--super-prefix" users) we'll want to clean this code up so that this all happens in-process. I.e. needing any variant of "--super-prefix" is itself a hack around our various global state, and implicit reliance on "the_repository". This stepping stone makes such an eventual change easier, as we'll need to deal with less global state at that point. The "fsmonitor--daemon" test adjusted here was added in [3]. To assert that it didn't run into the "--super-prefix" message it was asserting the output it didn't have. Let's instead assert the full output that we *do* have, using the same pattern as a preceding change to "t/t7412-submodule-absorbgitdirs.sh" used. We could also remove the test entirely (as [4] did), but even though the initial reason for having it is gone we're still getting some marginal benefit from testing the "fsmonitor" and "submodule absorbgitdirs" interaction, so let's keep it. The change here to have either a NULL or non-"" string as a "super_prefix" instead of the previous arrangement of "" or non-"" is somewhat arbitrary. We could also decide to never have to check for NULL. As we'll be changing the rest of the "git --super-prefix" users to the same pattern, leaving them all consistent makes sense. Why not pick "" over NULL? Because that's how the "prefix" works[5], and having "prefix" and "super_prefix" work the same way will be less confusing. That "prefix" picked NULL instead of "" is itself arbitrary, but as it's easy to make this small bit of our overall API consistent, let's go with that. 1. 74866d75793 (git: make super-prefix option, 2016-10-07) 2. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument, 2022-05-26) 3. 53fcfbc84f6 (fsmonitor--daemon: allow --super-prefix argument, 2022-05-26) 4. https://lore.kernel.org/git/20221109004708.97668-5-chooglen@google.com/ 5. 9725c8dda20 (built-ins: trust the "prefix" from run_builtin(), 2022-02-16) Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 7 +++---- git.c | 2 +- parse-options.h | 4 ++++ submodule.c | 12 +++++++----- t/t7527-builtin-fsmonitor.sh | 36 ++++++++++++++---------------------- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index da844cad5ce..b8b2bc776d1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2834,8 +2834,9 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) int i; struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; - const char *super_prefix; + const char *super_prefix = NULL; struct option embed_gitdir_options[] = { + OPT__SUPER_PREFIX(&super_prefix), OPT_END() }; const char *const git_submodule_helper_usage[] = { @@ -2850,7 +2851,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) if (module_list_compute(argv, prefix, &pathspec, &list) < 0) goto cleanup; - super_prefix = get_super_prefix(); for (i = 0; i < list.nr; i++) absorb_git_dir_into_superproject(list.entries[i]->name, super_prefix); @@ -3391,8 +3391,7 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && strcmp(subcmd, "foreach") && strcmp(subcmd, "status") && - strcmp(subcmd, "sync") && strcmp(subcmd, "absorbgitdirs") && - get_super_prefix()) + strcmp(subcmd, "sync") && get_super_prefix()) /* * xstrfmt() rather than "%s %s" to keep the translated * string identical to git.c's. diff --git a/git.c b/git.c index 277a8cce840..e473b4b7d72 100644 --- a/git.c +++ b/git.c @@ -539,7 +539,7 @@ static struct cmd_struct commands[] = { { "format-patch", cmd_format_patch, RUN_SETUP }, { "fsck", cmd_fsck, RUN_SETUP }, { "fsck-objects", cmd_fsck, RUN_SETUP }, - { "fsmonitor--daemon", cmd_fsmonitor__daemon, SUPPORT_SUPER_PREFIX | RUN_SETUP }, + { "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP }, { "gc", cmd_gc, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT }, { "grep", cmd_grep, RUN_SETUP_GENTLY }, diff --git a/parse-options.h b/parse-options.h index b6ef86e0d15..50d852f2991 100644 --- a/parse-options.h +++ b/parse-options.h @@ -369,6 +369,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int); { OPTION_CALLBACK, 0, "abbrev", (var), N_("n"), \ N_("use digits to display object names"), \ PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 } +#define OPT__SUPER_PREFIX(var) \ + OPT_STRING_F(0, "super-prefix", (var), N_("prefix"), \ + N_("prefixed path to initial superproject"), PARSE_OPT_HIDDEN) + #define OPT__COLOR(var, h) \ OPT_COLOR_FLAG(0, "color", (var), (h)) #define OPT_COLUMN(s, l, v, h) \ diff --git a/submodule.c b/submodule.c index bf19598b8c2..46a03473195 100644 --- a/submodule.c +++ b/submodule.c @@ -2275,7 +2275,8 @@ int validate_submodule_git_dir(char *git_dir, const char *submodule_name) * Embeds a single submodules git directory into the superprojects git dir, * non recursively. */ -static void relocate_single_git_dir_into_superproject(const char *path) +static void relocate_single_git_dir_into_superproject(const char *path, + const char *super_prefix) { char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL; struct strbuf new_gitdir = STRBUF_INIT; @@ -2305,7 +2306,7 @@ static void relocate_single_git_dir_into_superproject(const char *path) real_new_git_dir = real_pathdup(new_gitdir.buf, 1); fprintf(stderr, _("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n"), - get_super_prefix_or_empty(), path, + super_prefix ? super_prefix : "", path, real_old_git_dir, real_new_git_dir); relocate_gitdir(path, real_old_git_dir, real_new_git_dir); @@ -2325,10 +2326,11 @@ static void absorb_git_dir_into_superproject_recurse(const char *path, cp.dir = path; cp.git_cmd = 1; cp.no_stdin = 1; - strvec_pushf(&cp.args, "--super-prefix=%s%s/", super_prefix ? - super_prefix : "", path); strvec_pushl(&cp.args, "submodule--helper", "absorbgitdirs", NULL); + strvec_pushf(&cp.args, "--super-prefix=%s%s/", super_prefix ? + super_prefix : "", path); + prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) die(_("could not recurse into submodule '%s'"), path); @@ -2382,7 +2384,7 @@ void absorb_git_dir_into_superproject(const char *path, char *real_common_git_dir = real_pathdup(get_git_common_dir(), 1); if (!starts_with(real_sub_git_dir, real_common_git_dir)) - relocate_single_git_dir_into_superproject(path); + relocate_single_git_dir_into_superproject(path, super_prefix); free(real_sub_git_dir); free(real_common_git_dir); diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 4abc74db2bb..76d0220daa0 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -866,27 +866,9 @@ test_expect_success 'submodule always visited' ' # the submodule, and someone does a `git submodule absorbgitdirs` # in the super, Git will recursively invoke `git submodule--helper` # to do the work and this may try to read the index. This will -# try to start the daemon in the submodule *and* pass (either -# directly or via inheritance) the `--super-prefix` arg to the -# `git fsmonitor--daemon start` command inside the submodule. -# This causes a warning because fsmonitor--daemon does take that -# global arg (see the table in git.c) -# -# This causes a warning when trying to start the daemon that is -# somewhat confusing. It does not seem to hurt anything because -# the fsmonitor code maps the query failure into a trivial response -# and does the work anyway. -# -# It would be nice to silence the warning, however. - -have_t2_error_event () { - log=$1 - msg="fsmonitor--daemon doesnQt support --super-prefix" && - - tr '\047' Q <$1 | grep -e "$msg" -} +# try to start the daemon in the submodule. -test_expect_success "stray submodule super-prefix warning" ' +test_expect_success "submodule absorbgitdirs implicitly starts daemon" ' test_when_finished "rm -rf super; \ rm -rf sub; \ rm super-sub.trace" && @@ -904,10 +886,20 @@ test_expect_success "stray submodule super-prefix warning" ' test_path_is_dir super/dir_1/dir_2/sub/.git && + cwd="$(cd super && pwd)" && + cat >expect <<-EOF && + Migrating git directory of '\''dir_1/dir_2/sub'\'' from + '\''$cwd/dir_1/dir_2/sub/.git'\'' to + '\''$cwd/.git/modules/dir_1/dir_2/sub'\'' + EOF GIT_TRACE2_EVENT="$PWD/super-sub.trace" \ - git -C super submodule absorbgitdirs && + git -C super submodule absorbgitdirs >out 2>actual && + test_cmp expect actual && + test_must_be_empty out && - ! have_t2_error_event super-sub.trace + # Confirm that the trace2 log contains a record of the + # daemon starting. + test_subcommand git fsmonitor--daemon start X-Patchwork-Id: 13077852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4724DC4167B for ; Tue, 20 Dec 2022 12:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233766AbiLTMni (ORCPT ); Tue, 20 Dec 2022 07:43:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233765AbiLTMnH (ORCPT ); Tue, 20 Dec 2022 07:43:07 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D254E1AD98 for ; Tue, 20 Dec 2022 04:40:20 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id ja17so8594666wmb.3 for ; Tue, 20 Dec 2022 04:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=As/Hj+6fC5VCfoJBYg3HjS+IBdM9HhWr/D7Ex8iL6+Y=; b=KT4snsiHgVVoxHtupbXkaYqI0GBNJs2DgJTnqFr2n+Ge1LvDedlk6godZZ+s8cNHDj kxls8+hSa3L8dXjwZqz5z2g809hgc6yhnFG1eqKT/EY6Lc97omVnjwMigN6IgNDfN1JP hcyJCWtaeq5hQcde481wrgLlRfMQTbm/gHxrPRlGmkmp9F1o1pdoQl09MeLjBcufSzXq 7aOWTDG5lqoheHSOtaucSgyKSSUPNPTI60GLQ3UKIUOhFzkXIENJu63alYoolZTBEfp9 pAyxKF9BlG59N53IZ3UHCT/hyfZmMqU5fvdHJA6HuOH7Q1DHYgrkWn7wK4vp7xZ10816 JP+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=As/Hj+6fC5VCfoJBYg3HjS+IBdM9HhWr/D7Ex8iL6+Y=; b=4sYtXyQ9nCmojcYYrRtZGp5LR7vVeBxzVuyNJaTO8ldN81pofdR+bR1DLJExWHyM1w 1QRcMdzCWSFQx2bmXGm5Qqf07b5Nuk9tLqgZztfKHnTfEu1c+iw2uI+HznCuP+P2MmG5 CBYLP2Yx4qAatzM4x8XD3ku/wTSKmoW4uUc/3UwpCe5PFu3Oj9WSl9ttB6Q92B9H+E3i 5c2cx6r3Oyvb3QO5BHk575ldxHhUZ6ScgsZrAmZ42ZIspQj6aGEBq7u2tlRPDNlu8KzZ yo5kpwtjAnx7bVWjQpaNlRS3bGinUmDAD7udagFeqtaRXceLIcKZDGvGKNIHdItKntsx 7PmQ== X-Gm-Message-State: AFqh2kpc4JheJIijdbmdiOMLKoSpG+/cjOU2lKhdMFwRlzlEXe6BaWeV TIcm5hSWao0xV8vvRgVOGzTU+3eUfLtXrw== X-Google-Smtp-Source: AMrXdXvZm4qhZ6V9PpGt8YkHMziWVZ2LFDto29nUG2/f14eB9kPKFiEuNjgYoTLo+FvaC8d6F/bJRA== X-Received: by 2002:a05:600c:502c:b0:3d3:49db:9b25 with SMTP id n44-20020a05600c502c00b003d349db9b25mr1462389wmr.26.1671540005993; Tue, 20 Dec 2022 04:40:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:05 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 5/9] submodule--helper: convert "foreach" to its own "--super-prefix" Date: Tue, 20 Dec 2022 13:39:52 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper foreach" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git" itself. See that earlier commit for the rationale and background. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b8b2bc776d1..2a6ced13f6d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -278,6 +278,7 @@ struct foreach_cb { int argc; const char **argv; const char *prefix; + const char *super_prefix; int quiet; int recursive; }; @@ -294,7 +295,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, char *displaypath; displaypath = get_submodule_displaypath(path, info->prefix, - get_super_prefix()); + info->super_prefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -364,10 +365,10 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, cpr.dir = path; prepare_submodule_repo_env(&cpr.env); - strvec_pushl(&cpr.args, "--super-prefix", NULL); - strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", NULL); + strvec_pushl(&cpr.args, "--super-prefix", NULL); + strvec_pushf(&cpr.args, "%s/", displaypath); if (info->quiet) strvec_push(&cpr.args, "--quiet"); @@ -391,6 +392,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; struct option module_foreach_options[] = { + OPT__SUPER_PREFIX(&info.super_prefix), OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")), OPT_BOOL(0, "recursive", &info.recursive, N_("recurse into nested submodules")), @@ -3390,8 +3392,8 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) subcmd = argv[0]; if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - strcmp(subcmd, "foreach") && strcmp(subcmd, "status") && - strcmp(subcmd, "sync") && get_super_prefix()) + strcmp(subcmd, "status") && strcmp(subcmd, "sync") && + get_super_prefix()) /* * xstrfmt() rather than "%s %s" to keep the translated * string identical to git.c's. From patchwork Tue Dec 20 12:39:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF4FEC4167B for ; Tue, 20 Dec 2022 12:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233634AbiLTMnm (ORCPT ); Tue, 20 Dec 2022 07:43:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233335AbiLTMnI (ORCPT ); Tue, 20 Dec 2022 07:43:08 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05BE61A209 for ; Tue, 20 Dec 2022 04:40:21 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id b24-20020a05600c4a9800b003d21efdd61dso8656601wmp.3 for ; Tue, 20 Dec 2022 04:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=APQFWZJOluBfdRADFJL/JOcm14XTW3WxU+DKh4pIz3M=; b=aR0trX7KyxmMUQ5BihE5H8msyKHa1S/+GpZkMGd7rVkS78Y97FWHWTaom6m/nqk6i4 mwl/y5PyXFsFa6xfBsKrx6agT22cUzDh7wZhZH2qaLOE2oF8lJUgwxhuDXEldteNfMpo R9FhO8cZpc//Ce9IZ615MCcLPw974Iaks3vWA+hK+i7Krkbf5r0pUyf36s6laegftmtA jK5o83pN5d3NFuHY5Ubvqs2bfzCSVqO+MnBzW5vBqL57E8pk6wVzl9/TErZC582kzFNj 3fkuiXWA0C45Mf0EQQ8gTz1Uuzwim2XOJ3glSRdBuTjJs/ahfHLM4w5vMydr/ROmPPuB 0O0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=APQFWZJOluBfdRADFJL/JOcm14XTW3WxU+DKh4pIz3M=; b=m8Zh1zTl5Dp8Rh3yc6Yf/9cILFwZxVPMTufvD/cIYH7lesMpXek9DlR+0SczThmrBP PGjkDbSxrohRZEpPLSbydz59Xu/puCvvpEOIoBxOFREHEXld9aQTyXr5eyhUtLI7ldN8 1zKMwopYoPia5okM4SZIcwgcIiKGoD/pKWSpTjuMamF6H3HVAronCfMcOIzkopVRxOLg pB1hAVZxyvAOmAT7xxGzzmzeo1Flk6r5Wdc8E9a2DxCbYxrrjA+jaIqqJpWwsE41r2Qp T+V/aP3DSrLMOpm68H2GDdadjZ/Cye+ovyEFhHCNgNseKd8IK1K6xwOmLzqT3n6M8Wgn hptg== X-Gm-Message-State: AFqh2kp0ShetreTS0T4rMysj/Z0fqC435CKMOpbl5N0bLTwTN3fc0eiv o4VbgBDVLoJ2ZhxWTxQ0JIiUtxrYiGracw== X-Google-Smtp-Source: AMrXdXtY+Y9bXGU+yGTJZS9pKISsOBdSCX0H+Y5pIw+kRewfKvq5JZy00+SX1JcA3T0OnAqQI+7rsw== X-Received: by 2002:a05:600c:220c:b0:3d2:3831:e5c4 with SMTP id z12-20020a05600c220c00b003d23831e5c4mr1517416wml.40.1671540007391; Tue, 20 Dec 2022 04:40:07 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:06 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 6/9] submodule--helper: convert "sync" to its own "--super-prefix" Date: Tue, 20 Dec 2022 13:39:53 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper sync" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git" itself. See that earlier commit for the rationale and background. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2a6ced13f6d..7262ce72edf 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1208,12 +1208,13 @@ static int module_summary(int argc, const char **argv, const char *prefix) struct sync_cb { const char *prefix; + const char *super_prefix; unsigned int flags; }; #define SYNC_CB_INIT { 0 } static void sync_submodule(const char *path, const char *prefix, - unsigned int flags) + const char *super_prefix, unsigned int flags) { const struct submodule *sub; char *remote_key = NULL; @@ -1244,8 +1245,7 @@ static void sync_submodule(const char *path, const char *prefix, super_config_url = xstrdup(""); } - displaypath = get_submodule_displaypath(path, prefix, - get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix, super_prefix); if (!(flags & OPT_QUIET)) printf(_("Synchronizing submodule url for '%s'\n"), @@ -1282,10 +1282,11 @@ static void sync_submodule(const char *path, const char *prefix, cpr.dir = path; prepare_submodule_repo_env(&cpr.env); - strvec_push(&cpr.args, "--super-prefix"); - strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "sync", "--recursive", NULL); + strvec_push(&cpr.args, "--super-prefix"); + strvec_pushf(&cpr.args, "%s/", displaypath); + if (flags & OPT_QUIET) strvec_push(&cpr.args, "--quiet"); @@ -1308,7 +1309,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data { struct sync_cb *info = cb_data; - sync_submodule(list_item->name, info->prefix, info->flags); + sync_submodule(list_item->name, info->prefix, info->super_prefix, + info->flags); } static int module_sync(int argc, const char **argv, const char *prefix) @@ -1319,6 +1321,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) int quiet = 0; int recursive = 0; struct option module_sync_options[] = { + OPT__SUPER_PREFIX(&info.super_prefix), OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")), OPT_BOOL(0, "recursive", &recursive, N_("recurse into nested submodules")), @@ -2887,7 +2890,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) config_name = xstrfmt("submodule.%s.url", path); config_set_in_gitmodules_file_gently(config_name, newurl); - sync_submodule(path, prefix, quiet ? OPT_QUIET : 0); + sync_submodule(path, prefix, NULL, quiet ? OPT_QUIET : 0); free(config_name); @@ -3392,8 +3395,7 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) subcmd = argv[0]; if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - strcmp(subcmd, "status") && strcmp(subcmd, "sync") && - get_super_prefix()) + strcmp(subcmd, "status") && get_super_prefix()) /* * xstrfmt() rather than "%s %s" to keep the translated * string identical to git.c's. From patchwork Tue Dec 20 12:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A743EC4332F for ; Tue, 20 Dec 2022 12:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbiLTMno (ORCPT ); Tue, 20 Dec 2022 07:43:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233199AbiLTMnI (ORCPT ); Tue, 20 Dec 2022 07:43:08 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19C7B1ADAD for ; Tue, 20 Dec 2022 04:40:21 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id v124-20020a1cac82000000b003cf7a4ea2caso10994617wme.5 for ; Tue, 20 Dec 2022 04:40:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lSawEkKO6Js8shHf0JFoncSlsLgifQEAyRvuXo8IeJc=; b=KMxrdTDhSxHA100VR24P9yRdybsxsMJVGUpnx1f5V9KcJvS5OxG7K53EhROQ0VGRm9 jY4ptFqqCZxyEc67gGLudw3UtRUgSQN1bMOplpraa1H4o4TowdAufiauMm3H4O/YNCnn 080rha1SSgkraCvXIzA8M9zyXiOvj+pe32FP3VTf2bRQaZSWrXZoe5qsly2eNywulKA9 1TgmKpTFmlOIqV3ONmYCUMGEzr+TdSOM376NQHyBGx6I3979e/7mMhp1yblmu2NUPmRt TEgpAGF4DDx4/jijbwYrYQfLHEUYkUlkpcwUdRW+SGDu8FcGOkNwm4bJO+ZlKKacqm8y io+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lSawEkKO6Js8shHf0JFoncSlsLgifQEAyRvuXo8IeJc=; b=bFSY2a69Fz4N+yjvSWTpuGgxfpB3P3lanFv3LClxKiRYah3Z8TbsBD3FdpnfIrUaTU u05jzHsjUMsNhJSt+xZmx255Pkk/TqPCSZMv9yqBtlOliIjH6VuedZwkh+cn40cggUBO P/7D0LtVlYznr/dNcC/wDks05t59a61mae1ETq21traAUKNvNS6aOERoVNhAEoE+6NQ6 DZyoFLiA6cpueGjOWv6QmjKHq9WLNJpjSh9xrIqj8CPttX2VKKOvwTVK3NJ1/w2eWSNP LZ4z4eKBnymum3j4A1p6FMSyjXNemZCbDKiDfm1ixNw5lr2u+PCmNEbjBzuelU8RSk4f q78w== X-Gm-Message-State: ANoB5pnm1oAKKV0C18ppG+ZfZl8ZKM2E4t0JjYlZl5XUxerOXq7be2MY 0ZWtFDnPP5sv7MFDTxwc8+YztIaHVZdYtQ== X-Google-Smtp-Source: AA0mqf6yqAMvaAp3ICh4zNEz0MJY4627t16YLP44/z+Gb8Q6NCjLIpRdLxHa2Aj6PlEpsYjBUOc8Tw== X-Received: by 2002:a05:600c:35ce:b0:3d1:c8e3:2452 with SMTP id r14-20020a05600c35ce00b003d1c8e32452mr35819949wmq.30.1671540008319; Tue, 20 Dec 2022 04:40:08 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:07 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 7/9] submodule--helper: convert "status" to its own "--super-prefix" Date: Tue, 20 Dec 2022 13:39:54 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper status" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git" itself. See that earlier commit for the rationale and background. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7262ce72edf..448896f1b1d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -573,6 +573,7 @@ static int module_init(int argc, const char **argv, const char *prefix) struct status_cb { const char *prefix; + const char *super_prefix; unsigned int flags; }; #define STATUS_CB_INIT { 0 } @@ -611,7 +612,7 @@ static int handle_submodule_head_ref(const char *refname UNUSED, static void status_submodule(const char *path, const struct object_id *ce_oid, unsigned int ce_flags, const char *prefix, - unsigned int flags) + const char *super_prefix, unsigned int flags) { char *displaypath; struct strvec diff_files_args = STRVEC_INIT; @@ -627,8 +628,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, die(_("no submodule mapping found in .gitmodules for path '%s'"), path); - displaypath = get_submodule_displaypath(path, prefix, - get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix, super_prefix); if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) { print_status(flags, 'U', path, null_oid(), displaypath); @@ -686,10 +686,10 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, cpr.dir = path; prepare_submodule_repo_env(&cpr.env); - strvec_push(&cpr.args, "--super-prefix"); - strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "status", "--recursive", NULL); + strvec_push(&cpr.args, "--super-prefix"); + strvec_pushf(&cpr.args, "%s/", displaypath); if (flags & OPT_CACHED) strvec_push(&cpr.args, "--cached"); @@ -713,7 +713,7 @@ static void status_submodule_cb(const struct cache_entry *list_item, struct status_cb *info = cb_data; status_submodule(list_item->name, &list_item->oid, list_item->ce_flags, - info->prefix, info->flags); + info->prefix, info->super_prefix, info->flags); } static int module_status(int argc, const char **argv, const char *prefix) @@ -723,6 +723,7 @@ static int module_status(int argc, const char **argv, const char *prefix) struct module_list list = MODULE_LIST_INIT; int quiet = 0; struct option module_status_options[] = { + OPT__SUPER_PREFIX(&info.super_prefix), OPT__QUIET(&quiet, N_("suppress submodule status output")), OPT_BIT(0, "cached", &info.flags, N_("use commit stored in the index instead of the one stored in the submodule HEAD"), OPT_CACHED), OPT_BIT(0, "recursive", &info.flags, N_("recurse into nested submodules"), OPT_RECURSIVE), @@ -3395,7 +3396,7 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) subcmd = argv[0]; if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - strcmp(subcmd, "status") && get_super_prefix()) + get_super_prefix()) /* * xstrfmt() rather than "%s %s" to keep the translated * string identical to git.c's. From patchwork Tue Dec 20 12:39:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1031C4167B for ; Tue, 20 Dec 2022 12:43:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233548AbiLTMnp (ORCPT ); Tue, 20 Dec 2022 07:43:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233509AbiLTMnK (ORCPT ); Tue, 20 Dec 2022 07:43:10 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CBFF1ADBA for ; Tue, 20 Dec 2022 04:40:21 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id v124-20020a1cac82000000b003cf7a4ea2caso10994646wme.5 for ; Tue, 20 Dec 2022 04:40:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=agLIQV1H9+TvLmB6dhIZpRFjwNfvnZsAYcGGLPPbhx4=; b=CQv3G1x9IGBbGEyuYMbPFVh0JCNu65uGXpwRU3SC2KrmdlfgQ5+JrYyx+Wp8AHi8bc lj1tc/fxoTfEpVusdsKS3Cq/spVegY0Mp2cr8arzxo+5Ur7RZcEoEfAVL8apkY3uuSaJ PRdpuoQjYPQQgKER2+KXzLycXe5YTeWset67Dm2Q7YMZaNJZjIRZHObERQC+bm0uY9Sj w3LJDLMOgutGWooO/ncisw4AFCwnBOJ4rCwcWQJ2/L7SFxgtyhWjARwA24JKRqVZWTPN y0330nvgxSFOX7CkMYP4aiqbb4eI1rtYNyct59qZCKSrxgyV/At+r4rKWEQIc0b9DV3y qm2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=agLIQV1H9+TvLmB6dhIZpRFjwNfvnZsAYcGGLPPbhx4=; b=hYkR9hb7NW4M8wp68QVlkOdx/+Zz1saQDnqbvAYK0ApHywZrkYRMAnTVXQqrZNPwgp 4lODAUmjIbmlcbK/E2N/5rm3LHlqHATyoBwMZMLvr60KGduPxjkPH9pwGsIwNHXlSOVe tEm+H7TMTsDsmU6uXUAs0T42kHdKqMb3ctc6SHkdTCvXC/J/h6fjGeYJuvNWXWvsmDPT dgGEY8daS2sg/SvHt3cDxEH6eDiOy0ld8Z1MyYMBwBQxzzuDeuMJ4RvJZvfkepZAgRir YwFEEEtPzvuTB9FHMAVIFKF8yvkwSLQQ+Iw+HDm5zdYhqUL3S3MUR0fxziavk751JBGt hZ/g== X-Gm-Message-State: AFqh2kqd/C9NB7HmOHrcvTwCb0e9rmkCbiLaOoHM+R/mFNnv/yXdYLFa YImgj+16RxhiQev4TnxUhs7dtojhu377ug== X-Google-Smtp-Source: AMrXdXtjROdPjRQ2Ln9A4yRwSxeGnAUBhryc8G3yLM614JN3SLUBXL/elGt8CJcZqt4YAs11RLvt2g== X-Received: by 2002:a05:600c:5563:b0:3d5:365b:773e with SMTP id ja3-20020a05600c556300b003d5365b773emr1805369wmb.39.1671540009318; Tue, 20 Dec 2022 04:40:09 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:08 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 8/9] submodule--helper: convert "{update,clone}" to their own "--super-prefix" Date: Tue, 20 Dec 2022 13:39:55 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper status" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git". We need to convert both of these away from the global "--super-prefix" at the same time, because "update" will call "clone", but "clone" itself didn't make use of the global "--super-prefix" for displaying paths. It was only on the list of sub-commands that accepted it because "update"'s use of it would set it in its environment. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 32 +++++++++++++------------------- git.c | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 448896f1b1d..a0aa4635a0c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -437,11 +437,13 @@ static int starts_with_dot_dot_slash(const char *const path) struct init_cb { const char *prefix; + const char *super_prefix; unsigned int flags; }; #define INIT_CB_INIT { 0 } static void init_submodule(const char *path, const char *prefix, + const char *super_prefix, unsigned int flags) { const struct submodule *sub; @@ -449,8 +451,7 @@ static void init_submodule(const char *path, const char *prefix, const char *upd; char *url = NULL, *displaypath; - displaypath = get_submodule_displaypath(path, prefix, - get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix, super_prefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -526,7 +527,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data { struct init_cb *info = cb_data; - init_submodule(list_item->name, info->prefix, info->flags); + init_submodule(list_item->name, info->prefix, info->super_prefix, + info->flags); } static int module_init(int argc, const char **argv, const char *prefix) @@ -792,6 +794,7 @@ struct summary_cb { int argc; const char **argv; const char *prefix; + const char *super_prefix; unsigned int cached: 1; unsigned int for_status: 1; unsigned int files: 1; @@ -954,7 +957,7 @@ static void generate_submodule_summary(struct summary_cb *info, } displaypath = get_submodule_displaypath(p->sm_path, info->prefix, - get_super_prefix()); + info->super_prefix); if (!missing_src && !missing_dst) { struct child_process cp_rev_list = CHILD_PROCESS_INIT; @@ -1893,6 +1896,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc) struct update_data { const char *prefix; + const char *super_prefix; char *displaypath; enum submodule_update_type update_default; struct object_id suboid; @@ -1969,7 +1973,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, char *key; const struct update_data *ud = suc->update_data; char *displaypath = get_submodule_displaypath(ce->name, ud->prefix, - get_super_prefix()); + ud->super_prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; int need_free_url = 0; @@ -2449,11 +2453,11 @@ static void update_data_to_args(const struct update_data *update_data, { enum submodule_update_type update_type = update_data->update_default; + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); if (update_data->displaypath) { strvec_push(args, "--super-prefix"); strvec_pushf(args, "%s/", update_data->displaypath); } - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->quiet) strvec_push(args, "--quiet"); @@ -2620,7 +2624,7 @@ static int update_submodules(struct update_data *update_data) update_data->displaypath = get_submodule_displaypath( update_data->sm_path, update_data->prefix, - get_super_prefix()); + update_data->super_prefix); code = update_submodule(update_data); FREE_AND_NULL(update_data->displaypath); fail: @@ -2646,6 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix) LIST_OBJECTS_FILTER_INIT; int ret; struct option module_update_options[] = { + OPT__SUPER_PREFIX(&opt.super_prefix), OPT__FORCE(&opt.force, N_("force checkout updates"), 0), OPT_BOOL(0, "init", &opt.init, N_("initialize uninitialized submodules before update")), @@ -2742,6 +2747,7 @@ static int module_update(int argc, const char **argv, const char *prefix) module_list_active(&list); info.prefix = opt.prefix; + info.super_prefix = opt.super_prefix; if (opt.quiet) info.flags |= OPT_QUIET; @@ -3368,8 +3374,6 @@ static int module_add(int argc, const char **argv, const char *prefix) int cmd_submodule__helper(int argc, const char **argv, const char *prefix) { - const char *cmd = argv[0]; - const char *subcmd; parse_opt_subcommand_fn *fn = NULL; const char *const usage[] = { N_("git submodule--helper "), @@ -3393,16 +3397,6 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) OPT_END() }; argc = parse_options(argc, argv, prefix, options, usage, 0); - subcmd = argv[0]; - - if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - get_super_prefix()) - /* - * xstrfmt() rather than "%s %s" to keep the translated - * string identical to git.c's. - */ - die(_("%s doesn't support --super-prefix"), - xstrfmt("'%s %s'", cmd, subcmd)); return fn(argc, argv, prefix); } diff --git a/git.c b/git.c index e473b4b7d72..2c31ba27040 100644 --- a/git.c +++ b/git.c @@ -610,7 +610,7 @@ static struct cmd_struct commands[] = { { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, - { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "submodule--helper", cmd_submodule__helper, RUN_SETUP }, { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG }, From patchwork Tue Dec 20 12:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13077857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7B74C4332F for ; Tue, 20 Dec 2022 12:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233777AbiLTMoU (ORCPT ); Tue, 20 Dec 2022 07:44:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbiLTMnV (ORCPT ); Tue, 20 Dec 2022 07:43:21 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12781AF0E for ; Tue, 20 Dec 2022 04:40:26 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id ja17so8594865wmb.3 for ; Tue, 20 Dec 2022 04:40:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XHxQhsaJLSC7d/3L9NJpFHqBowcryKd4uBFXreKuHaY=; b=hF0aIrLUHOZy1VeyVv63n4Yen0VdoHESYWUQD2QlH2L0gNcD65X7KVWG/ylHy++ByO NxjhLfChWNYTRWxk6jLcraQBpRLvBZ8t3qkQDCsJCyp7GwbKhxw4O0GpaqomZhpFszxF zf9iYW2t3rgyCTSnkhXyaeum8eiFsQmuYJ9Wv9kuMwM5nVkWuDhrCoul+g6AjagegQeN Q7cK7Y+Z/S6XhYCXNkeJaOrtiRXFLnirB+AjSy8saWbbTH3bfu3kmqOIfSfH1Zu6EuTh s86P7Tf08XSv0ZIF22mze86+YI9PLGIvRm95dWukbStkT6P2auupE6R4IAi1RNrHC68+ PehQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XHxQhsaJLSC7d/3L9NJpFHqBowcryKd4uBFXreKuHaY=; b=Gpk1Doz/26xPXzyt1SribVEjMcVnQp71R47I6oLtGPQJUMYO4IvvxsOPklcgyeFjuu G1P693D/MZaYe9ApAJ/p47/ZmV6rxbfIjogqiVMZ096k51nyJQ89jCABMeO4NSirp/0K UM4+/g8ynrd2u16K93iT9QDjJoMbYRFOApIbDdaVWCh3eo/MmDdwitCfGRucXlktEN9G x4TF+XuXzHYlGib8xPwSeVzfwo9OL052QpQJVNOerIq1E9YCGmQHx0KprU8wL9SkdKzS 0eWgRyFWvz89yTPWRF8AUwoOCtu2d96BS840ahXJHEzgryGcu5GYUswehPXVAHUUR6Su O/VQ== X-Gm-Message-State: ANoB5pkOYfQB/lO8QU/ztqglrkqbWZEYejv/0h/3URgTlrk80pJIyNex hafjDdwulntsDS5i2yEvN+WRypirQkEJIw== X-Google-Smtp-Source: AA0mqf7Yo3cixC4CB3qwig6mZfsVECmLkQtzbQq6OJjUHWJpEljKZH61UhwERIFG5O1eLRIOtwEuUw== X-Received: by 2002:a05:600c:384b:b0:3cf:6926:2abb with SMTP id s11-20020a05600c384b00b003cf69262abbmr35395315wmr.7.1671540010396; Tue, 20 Dec 2022 04:40:10 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003d355ad9bb7sm9630759wmq.20.2022.12.20.04.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 04:40:09 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 9/9] read-tree: add "--super-prefix" option, eliminate global Date: Tue, 20 Dec 2022 13:39:56 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.1106.g08bce9674be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "--super-prefix" option to "git" was initially added in [1] for use with "ls-files"[2], and shortly thereafter "submodule--helper"[3] and "grep"[4]. It wasn't until [5] that "read-tree" made use of it. At the time [5] made sense, but since then we've made "ls-files" recurse in-process in [6], "grep" in [7], and finally "submodule--helper" in the preceding commits. Let's also remove it from "read-tree", which allows us to remove the option to "git" itself. We can do this because the only remaining user of it is the submodule API, which will now invoke "read-tree" with its new "--super-prefix" option. It will only do so when the "submodule_move_head()" function is called. That "submodule_move_head()" function was then only invoked by "read-tree" itself, but now rather than setting an environment variable to pass "--super-prefix" between cmd_read_tree() we: - Set a new "super_prefix" in "struct unpack_trees_options". The "super_prefixed()" function in "unpack-trees.c" added in [5] will now use this, rather than get_super_prefix() looking up the environment variable we set earlier in the same process. - Add the same field to the "struct checkout", which is only needed to ferry the "super_prefix" in the "struct unpack_trees_options" all the way down to the "entry.c" callers of "submodule_move_head()". Those calls which used the super prefix all originated in "cmd_read_tree()". The only other caller is the "unlink_entry()" caller in "builtin/checkout.c", which now passes a "NULL". 1. 74866d75793 (git: make super-prefix option, 2016-10-07) 2. e77aa336f11 (ls-files: optionally recurse into submodules, 2016-10-07) 3. 89c86265576 (submodule helper: support super prefix, 2016-12-08) 4. 0281e487fd9 (grep: optionally recurse into submodules, 2016-12-16) 5. 3d415425c7b (unpack-trees: support super-prefix option, 2017-01-17) 6. 188dce131fa (ls-files: use repository object, 2017-06-22) 7. f9ee2fcdfa0 (grep: recurse in-process using 'struct repository', 2017-08-02) Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git.txt | 8 +------- builtin.h | 4 ---- builtin/checkout.c | 2 +- builtin/read-tree.c | 1 + cache.h | 2 -- entry.c | 12 ++++++------ entry.h | 6 +++++- environment.c | 13 ------------- git.c | 37 +++++-------------------------------- submodule.c | 29 ++++++++++------------------- submodule.h | 5 ++--- t/t1001-read-tree-m-2way.sh | 2 +- t/t5616-partial-clone.sh | 2 +- unpack-trees.c | 24 ++++++++++++++---------- unpack-trees.h | 1 + 15 files changed, 48 insertions(+), 100 deletions(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index 1d33e083ab8..f9a7a4554cd 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -13,8 +13,7 @@ SYNOPSIS [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] - [--super-prefix=] [--config-env==] - [] + [--config-env==] [] DESCRIPTION ----------- @@ -169,11 +168,6 @@ If you just want to run git as if it was started in `` then use details. Equivalent to setting the `GIT_NAMESPACE` environment variable. ---super-prefix=:: - Currently for internal use only. Set a prefix which gives a path from - above a repository down to its root. One use is to give submodules - context about the superproject that invoked it. - --bare:: Treat the repository as a bare repository. If GIT_DIR environment is not set, it is set to the current working diff --git a/builtin.h b/builtin.h index aa955466b4e..46cc7897898 100644 --- a/builtin.h +++ b/builtin.h @@ -51,10 +51,6 @@ * on bare repositories. * This only makes sense when `RUN_SETUP` is also set. * - * `SUPPORT_SUPER_PREFIX`: - * - * The built-in supports `--super-prefix`. - * * `DELAY_PAGER_CONFIG`: * * If RUN_SETUP or RUN_SETUP_GENTLY is set, git.c normally handles diff --git a/builtin/checkout.c b/builtin/checkout.c index a0142c815fd..cd04f0bf572 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -232,7 +232,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos, pos++; } if (!overlay_mode) { - unlink_entry(ce); + unlink_entry(ce, NULL); return 0; } if (stage == 2) diff --git a/builtin/read-tree.c b/builtin/read-tree.c index f702f9d47bb..3ce75417833 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -114,6 +114,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) int prefix_set = 0; struct lock_file lock_file = LOCK_INIT; const struct option read_tree_options[] = { + OPT__SUPER_PREFIX(&opts.super_prefix), OPT_CALLBACK_F(0, "index-output", NULL, N_("file"), N_("write resulting index to "), PARSE_OPT_NONEG, index_output_cb), diff --git a/cache.h b/cache.h index 07d40b0964b..7f7e2b5a38f 100644 --- a/cache.h +++ b/cache.h @@ -480,7 +480,6 @@ static inline enum object_type object_type(unsigned int mode) #define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE" #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" #define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" -#define GIT_SUPER_PREFIX_ENVIRONMENT "GIT_INTERNAL_SUPER_PREFIX" #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" @@ -566,7 +565,6 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir); int get_common_dir(struct strbuf *sb, const char *gitdir); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); -const char *get_super_prefix(void); const char *get_git_work_tree(void); /* diff --git a/entry.c b/entry.c index 616e4f073c1..971ab268714 100644 --- a/entry.c +++ b/entry.c @@ -383,7 +383,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca return error("cannot create submodule directory %s", path); sub = submodule_from_ce(ce); if (sub) - return submodule_move_head(ce->name, + return submodule_move_head(ce->name, state->super_prefix, NULL, oid_to_hex(&ce->oid), state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0); break; @@ -476,7 +476,7 @@ int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca, * no pathname to return. */ BUG("Can't remove entry to a path"); - unlink_entry(ce); + unlink_entry(ce, state->super_prefix); return 0; } @@ -510,10 +510,10 @@ int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca, if (!(st.st_mode & S_IFDIR)) unlink_or_warn(ce->name); - return submodule_move_head(ce->name, + return submodule_move_head(ce->name, state->super_prefix, NULL, oid_to_hex(&ce->oid), 0); } else - return submodule_move_head(ce->name, + return submodule_move_head(ce->name, state->super_prefix, "HEAD", oid_to_hex(&ce->oid), state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0); } @@ -560,12 +560,12 @@ int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca, return write_entry(ce, path.buf, ca, state, 0, nr_checkouts); } -void unlink_entry(const struct cache_entry *ce) +void unlink_entry(const struct cache_entry *ce, const char *super_prefix) { const struct submodule *sub = submodule_from_ce(ce); if (sub) { /* state.force is set at the caller. */ - submodule_move_head(ce->name, "HEAD", NULL, + submodule_move_head(ce->name, super_prefix, "HEAD", NULL, SUBMODULE_MOVE_HEAD_FORCE); } if (check_leading_path(ce->name, ce_namelen(ce), 1) >= 0) diff --git a/entry.h b/entry.h index 9be4659881e..2d4fbb88c8f 100644 --- a/entry.h +++ b/entry.h @@ -8,6 +8,7 @@ struct checkout { struct index_state *istate; const char *base_dir; int base_dir_len; + const char *super_prefix; struct delayed_checkout *delayed_checkout; struct checkout_metadata meta; unsigned force:1, @@ -48,8 +49,11 @@ int finish_delayed_checkout(struct checkout *state, int show_progress); /* * Unlink the last component and schedule the leading directories for * removal, such that empty directories get removed. + * + * The "super_prefix" is either NULL, or the "--super-prefix" passed + * down from "read-tree" et al. */ -void unlink_entry(const struct cache_entry *ce); +void unlink_entry(const struct cache_entry *ce, const char *super_prefix); void *read_blob_entry(const struct cache_entry *ce, size_t *size); int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st); diff --git a/environment.c b/environment.c index 18d042b467d..1ee3686fd8a 100644 --- a/environment.c +++ b/environment.c @@ -102,8 +102,6 @@ char *git_work_tree_cfg; static char *git_namespace; -static char *super_prefix; - /* * Repository-local GIT_* environment variables; see cache.h for details. */ @@ -121,7 +119,6 @@ const char * const local_repo_env[] = { NO_REPLACE_OBJECTS_ENVIRONMENT, GIT_REPLACE_REF_BASE_ENVIRONMENT, GIT_PREFIX_ENVIRONMENT, - GIT_SUPER_PREFIX_ENVIRONMENT, GIT_SHALLOW_FILE_ENVIRONMENT, GIT_COMMON_DIR_ENVIRONMENT, NULL @@ -234,16 +231,6 @@ const char *strip_namespace(const char *namespaced_ref) return NULL; } -const char *get_super_prefix(void) -{ - static int initialized; - if (!initialized) { - super_prefix = xstrdup_or_null(getenv(GIT_SUPER_PREFIX_ENVIRONMENT)); - initialized = 1; - } - return super_prefix; -} - static int git_work_tree_initialized; /* diff --git a/git.c b/git.c index 2c31ba27040..32a5be68a17 100644 --- a/git.c +++ b/git.c @@ -14,9 +14,8 @@ * RUN_SETUP for reading from the configuration file. */ #define NEED_WORK_TREE (1<<3) -#define SUPPORT_SUPER_PREFIX (1<<4) -#define DELAY_PAGER_CONFIG (1<<5) -#define NO_PARSEOPT (1<<6) /* parse-options is not used */ +#define DELAY_PAGER_CONFIG (1<<4) +#define NO_PARSEOPT (1<<5) /* parse-options is not used */ struct cmd_struct { const char *cmd; @@ -29,8 +28,7 @@ const char git_usage_string[] = " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" " [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]\n" " [--git-dir=] [--work-tree=] [--namespace=]\n" - " [--super-prefix=] [--config-env==]\n" - " []"); + " [--config-env==] []"); const char git_more_info_string[] = N_("'git help -a' and 'git help -g' list available subcommands and some\n" @@ -226,20 +224,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) setenv(GIT_WORK_TREE_ENVIRONMENT, cmd, 1); if (envchanged) *envchanged = 1; - } else if (!strcmp(cmd, "--super-prefix")) { - if (*argc < 2) { - fprintf(stderr, _("no prefix given for --super-prefix\n" )); - usage(git_usage_string); - } - setenv(GIT_SUPER_PREFIX_ENVIRONMENT, (*argv)[1], 1); - if (envchanged) - *envchanged = 1; - (*argv)++; - (*argc)--; - } else if (skip_prefix(cmd, "--super-prefix=", &cmd)) { - setenv(GIT_SUPER_PREFIX_ENVIRONMENT, cmd, 1); - if (envchanged) - *envchanged = 1; } else if (!strcmp(cmd, "--bare")) { char *cwd = xgetcwd(); is_bare_repository_cfg = 1; @@ -449,11 +433,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) trace_repo_setup(prefix); commit_pager_choice(); - if (!help && get_super_prefix()) { - if (!(p->option & SUPPORT_SUPER_PREFIX)) - die(_("%s doesn't support --super-prefix"), p->cmd); - } - if (!help && p->option & NEED_WORK_TREE) setup_work_tree(); @@ -504,7 +483,7 @@ static struct cmd_struct commands[] = { { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout--worker", cmd_checkout__worker, - RUN_SETUP | NEED_WORK_TREE | SUPPORT_SUPER_PREFIX }, + RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index, RUN_SETUP | NEED_WORK_TREE}, { "cherry", cmd_cherry, RUN_SETUP }, @@ -583,7 +562,7 @@ static struct cmd_struct commands[] = { { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE }, { "push", cmd_push, RUN_SETUP }, { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER }, - { "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX}, + { "read-tree", cmd_read_tree, RUN_SETUP }, { "rebase", cmd_rebase, RUN_SETUP | NEED_WORK_TREE }, { "receive-pack", cmd_receive_pack }, { "reflog", cmd_reflog, RUN_SETUP }, @@ -727,9 +706,6 @@ static void execv_dashed_external(const char **argv) struct child_process cmd = CHILD_PROCESS_INIT; int status; - if (get_super_prefix()) - die(_("%s doesn't support --super-prefix"), argv[0]); - if (use_pager == -1 && !is_builtin(argv[0])) use_pager = check_pager_config(argv[0]); commit_pager_choice(); @@ -799,9 +775,6 @@ static int run_argv(int *argcp, const char ***argv) */ trace2_cmd_name("_run_git_alias_"); - if (get_super_prefix()) - die("%s doesn't support --super-prefix", **argv); - commit_pager_choice(); strvec_push(&cmd.args, "git"); diff --git a/submodule.c b/submodule.c index 46a03473195..d730b64b072 100644 --- a/submodule.c +++ b/submodule.c @@ -2054,14 +2054,6 @@ void submodule_unset_core_worktree(const struct submodule *sub) strbuf_release(&config_path); } -static const char *get_super_prefix_or_empty(void) -{ - const char *s = get_super_prefix(); - if (!s) - s = ""; - return s; -} - static int submodule_has_dirty_index(const struct submodule *sub) { struct child_process cp = CHILD_PROCESS_INIT; @@ -2080,7 +2072,7 @@ static int submodule_has_dirty_index(const struct submodule *sub) return finish_command(&cp); } -static void submodule_reset_index(const char *path) +static void submodule_reset_index(const char *path, const char *super_prefix) { struct child_process cp = CHILD_PROCESS_INIT; prepare_submodule_repo_env(&cp.env); @@ -2089,10 +2081,10 @@ static void submodule_reset_index(const char *path) cp.no_stdin = 1; cp.dir = path; - strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); /* TODO: determine if this might overwright untracked files */ strvec_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); + strvec_pushf(&cp.args, "--super-prefix=%s%s/", + (super_prefix ? super_prefix : ""), path); strvec_push(&cp.args, empty_tree_oid_hex()); @@ -2105,10 +2097,9 @@ static void submodule_reset_index(const char *path) * For edge cases (a submodule coming into existence or removing a submodule) * pass NULL for old or new respectively. */ -int submodule_move_head(const char *path, - const char *old_head, - const char *new_head, - unsigned flags) +int submodule_move_head(const char *path, const char *super_prefix, + const char *old_head, const char *new_head, + unsigned flags) { int ret = 0; struct child_process cp = CHILD_PROCESS_INIT; @@ -2146,7 +2137,7 @@ int submodule_move_head(const char *path, if (old_head) { if (!submodule_uses_gitfile(path)) absorb_git_dir_into_superproject(path, - get_super_prefix()); + super_prefix); } else { struct strbuf gitdir = STRBUF_INIT; submodule_name_to_gitdir(&gitdir, the_repository, @@ -2155,7 +2146,7 @@ int submodule_move_head(const char *path, strbuf_release(&gitdir); /* make sure the index is clean as well */ - submodule_reset_index(path); + submodule_reset_index(path, super_prefix); } if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) { @@ -2173,9 +2164,9 @@ int submodule_move_head(const char *path, cp.no_stdin = 1; cp.dir = path; - strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); strvec_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); + strvec_pushf(&cp.args, "--super-prefix=%s%s/", + (super_prefix ? super_prefix : ""), path); if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) strvec_push(&cp.args, "-n"); diff --git a/submodule.h b/submodule.h index f90ee547d08..c55a25ca37d 100644 --- a/submodule.h +++ b/submodule.h @@ -150,9 +150,8 @@ int validate_submodule_git_dir(char *git_dir, const char *submodule_name); #define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0) #define SUBMODULE_MOVE_HEAD_FORCE (1<<1) -int submodule_move_head(const char *path, - const char *old, - const char *new_head, +int submodule_move_head(const char *path, const char *super_prefix, + const char *old_head, const char *new_head, unsigned flags); void submodule_unset_core_worktree(const struct submodule *sub); diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 516a6112fdc..3fb1b0c162d 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -370,7 +370,7 @@ test_expect_success 'read-tree supports the super-prefix' ' cat <<-EOF >expect && error: Updating '\''fictional/a'\'' would lose untracked files in it EOF - test_must_fail git --super-prefix fictional/ read-tree -u -m "$treeH" "$treeM" 2>actual && + test_must_fail git read-tree --super-prefix fictional/ -u -m "$treeH" "$treeM" 2>actual && test_cmp expect actual ' diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 2846ec6629c..f519d2a87a7 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -644,7 +644,7 @@ test_expect_success 'repack does not loosen promisor objects' ' grep "loosen_unused_packed_objects/loosened:0" trace ' -test_expect_failure 'lazy-fetch in submodule succeeds' ' +test_expect_success 'lazy-fetch in submodule succeeds' ' # setup test_config_global protocol.file.allow always && diff --git a/unpack-trees.c b/unpack-trees.c index 8a762aa0772..2b8e5da4c21 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -71,7 +71,7 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { ? ((o)->msgs[(type)]) \ : (unpack_plumbing_errors[(type)]) ) -static const char *super_prefixed(const char *path) +static const char *super_prefixed(const char *path, const char *super_prefix) { /* * It is necessary and sufficient to have two static buffers @@ -83,7 +83,6 @@ static const char *super_prefixed(const char *path) static unsigned idx = ARRAY_SIZE(buf) - 1; if (super_prefix_len < 0) { - const char *super_prefix = get_super_prefix(); if (!super_prefix) { super_prefix_len = 0; } else { @@ -236,7 +235,8 @@ static int add_rejected_path(struct unpack_trees_options *o, return -1; if (!o->show_all_errors) - return error(ERRORMSG(o, e), super_prefixed(path)); + return error(ERRORMSG(o, e), super_prefixed(path, + o->super_prefix)); /* * Otherwise, insert in a list for future display by @@ -263,7 +263,8 @@ static void display_error_msgs(struct unpack_trees_options *o) error_displayed = 1; for (i = 0; i < rejects->nr; i++) strbuf_addf(&path, "\t%s\n", rejects->items[i].string); - error(ERRORMSG(o, e), super_prefixed(path.buf)); + error(ERRORMSG(o, e), super_prefixed(path.buf, + o->super_prefix)); strbuf_release(&path); } string_list_clear(rejects, 0); @@ -290,7 +291,8 @@ static void display_warning_msgs(struct unpack_trees_options *o) warning_displayed = 1; for (i = 0; i < rejects->nr; i++) strbuf_addf(&path, "\t%s\n", rejects->items[i].string); - warning(ERRORMSG(o, e), super_prefixed(path.buf)); + warning(ERRORMSG(o, e), super_prefixed(path.buf, + o->super_prefix)); strbuf_release(&path); } string_list_clear(rejects, 0); @@ -312,7 +314,8 @@ static int check_submodule_move_head(const struct cache_entry *ce, if (o->reset) flags |= SUBMODULE_MOVE_HEAD_FORCE; - if (submodule_move_head(ce->name, old_id, new_id, flags)) + if (submodule_move_head(ce->name, o->super_prefix, old_id, new_id, + flags)) return add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name); return 0; } @@ -415,6 +418,7 @@ static int check_updates(struct unpack_trees_options *o, int i, pc_workers, pc_threshold; trace_performance_enter(); + state.super_prefix = o->super_prefix; state.force = 1; state.quiet = 1; state.refresh_cache = 1; @@ -445,7 +449,7 @@ static int check_updates(struct unpack_trees_options *o, if (ce->ce_flags & CE_WT_REMOVE) { display_progress(progress, ++cnt); - unlink_entry(ce); + unlink_entry(ce, o->super_prefix); } } @@ -2959,8 +2963,8 @@ int bind_merge(const struct cache_entry * const *src, if (a && old) return o->quiet ? -1 : error(ERRORMSG(o, ERROR_BIND_OVERLAP), - super_prefixed(a->name), - super_prefixed(old->name)); + super_prefixed(a->name, o->super_prefix), + super_prefixed(old->name, o->super_prefix)); if (!a) return keep_entry(old, o); else @@ -3021,7 +3025,7 @@ int stash_worktree_untracked_merge(const struct cache_entry * const *src, if (worktree && untracked) return error(_("worktree and untracked commit have duplicate entries: %s"), - super_prefixed(worktree->name)); + super_prefixed(worktree->name, o->super_prefix)); return merged_entry(worktree ? worktree : untracked, NULL, o); } diff --git a/unpack-trees.h b/unpack-trees.h index 6ab0d74c84d..3a7b3e5f007 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -75,6 +75,7 @@ struct unpack_trees_options { skip_cache_tree_update; enum unpack_trees_reset_type reset; const char *prefix; + const char *super_prefix; int cache_bottom; struct pathspec *pathspec; merge_fn_t fn;