From patchwork Thu Dec 15 09:32:42 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: 13074005 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 03725C4332F for ; Thu, 15 Dec 2022 09:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbiLOJdV (ORCPT ); Thu, 15 Dec 2022 04:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbiLOJdD (ORCPT ); Thu, 15 Dec 2022 04:33:03 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 511552DDD for ; Thu, 15 Dec 2022 01:32:59 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id c17so26163309edj.13 for ; Thu, 15 Dec 2022 01:32:59 -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=/qDY3IPj2/xenHISiRFCOuHSiEkYq9I3l+Etnk4wQn8=; b=T3goYIeCy+DAPXK/Y2OAyH+umtAr5opURM/7gpWyTKnL7APMNpJp8Lsdsz9TZ05uDM D8UfPAUry4nU28KvetRYZAO1H00MSd07gHy5RT3Ml4HxQQtK9cjcI7w69jVKRd7Be1uL lAn0P8b3WsauxnzxK4w8X0UYAoGg8qri2Dy3dl7OTrMTSLETWQNPVzgMWOo/zPBMkFIR hvGG7UTSUI1iWBHAGp9p+7HsJ//eDJSHyORJ0yQxxPmx+cq2MjHQ9zWgx2hrqFHLQc9N U4HFrst+AI13PgSNAarucuV47/LfGq93SP6b6Bhv4qjBBvEH1lZ080PjA9/K4+pPc/fp lF1g== 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=/qDY3IPj2/xenHISiRFCOuHSiEkYq9I3l+Etnk4wQn8=; b=q2e7XEaXLr9w9eFztqqv1v6lySq6hpw64bwSNoqrvMmkXocPkVDGts51Y7/dCAo978 EMWD5CSAJW2ljXjuiQSODxnM1T2nwgALII9d34e7xaAp8ZTwbNdMUZHDG5JFJ9Sbaf06 w9GMc6UFRrNjmjTuxA7f+OGk6Hhdm3kYjbQd6AYbBu0MqunL86sgVjy0Q9j3llVOsEl+ bJ2a1OE390o72nrDu78i2sjrLZ0B72Q7WiXvWWxJUxJjeknK1tLMfVQT+6NQ/MrS0KqF BU+xjMcRLCzjEbrlVa96fd6ssYQ4i3G9ZrGssFUkl963tIEQBILWu3obdqyR5teTgWPv 5Ptg== X-Gm-Message-State: ANoB5pkV6xQMnNXeXBU53EoDodQKOh6Z8EEaXkR+Ws4k3C0JL/DFaZZq B3F0NH7G9rp/EoIXQobxos0GQT8RhCCpTA== X-Google-Smtp-Source: AA0mqf7OCWzWrM/i0E0ZUhON5AfKRmOcvwIU8k/GUQxZowinUpH8YdWSomN14C6JZs/yY9qZW1n99w== X-Received: by 2002:a05:6402:3643:b0:461:78ef:56f2 with SMTP id em3-20020a056402364300b0046178ef56f2mr24355209edb.34.1671096777431; Thu, 15 Dec 2022 01:32:57 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:32:56 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 1/9] submodule absorbgitdirs tests: add missing "Migrating git..." tests Date: Thu, 15 Dec 2022 10:32:42 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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..d556342ea57 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 + DO_IT=1 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 Thu Dec 15 09:32:43 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: 13074003 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 F2AE5C4332F for ; Thu, 15 Dec 2022 09:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbiLOJdR (ORCPT ); Thu, 15 Dec 2022 04:33:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbiLOJdC (ORCPT ); Thu, 15 Dec 2022 04:33:02 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E3120BCB for ; Thu, 15 Dec 2022 01:33:00 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id ud5so50873890ejc.4 for ; Thu, 15 Dec 2022 01:33:00 -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=duhIhRObTCIhUHol1lqkMZxVr2N04VUvo01VQYLo6pk=; b=I0xZBfXGJwAiisKtFv9xP5++oO3x6DskvyPL8UfPN7zzeJ0tiiTeWeoTVbf8EGOFSk ffYN7j/JQT0jf+84Pea7ua39PeHn9FW71jCdh79d3eDhQ8Gb0hRRZiEjdwyaxuT1OU7C 5B9KzNv6JK0lZAiCR0F0fkw1JmgGrSJ0bn+YOwN36aamrwMAi56g0gtEFUdWxbPnjcwc U/DJB6mfgpiWLmQWedfX1Rk/DfD/b/N2QWHHfGQzsaeM4fVVUAE3lf2MCcrI+28GPIKN la+62R0iTX9MT/3UaJDbhDsdWuPw+BoLEhOtFzt1hSyExgL4mOwfwhGdffx0N+230K1e Bokg== 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=duhIhRObTCIhUHol1lqkMZxVr2N04VUvo01VQYLo6pk=; b=umb6a05YQnVg4nFgcIqUS8WtVwbKC7USF8etOWE+UTr3uyUY72jNecU6EDOE7WYpzZ yFR/iPsIrS0f13h1ikfKEGzXktzU45ug0pXKLx8LaNHRoVb3IMOjB1+qKIzCpG/V+z6B qdB8nfqUo+MSBbHj0vaYbBoCCwb86MTTc3NSyS+6RjGGRwI5x+G5MtskvL782BJugZu8 IS1z46lx1LzZG+IA2uxnv9y4ljuhJc6SciIAfUPec6Iqf4PrV4qBbGH6qFY69gKUq+RM 42SFg0qsvOw83tZqKYp9XBBnW9l9h/vtWEIwHP4QDluE81s/6HuE2Cp4beeIbnUneKh6 JgTw== X-Gm-Message-State: ANoB5pnrtRc3aLbm8VqjrhMnykzzxxJ+AvifwSGkagoSD02jyD1Y49lz HyQzYuljSQEIDP12MMHd+uzF+XUfXcqQCw== X-Google-Smtp-Source: AA0mqf7GN8MlVy+gcgMI72dNCN8pfCjN5BX9Jo6tnUbEyDutZ9x0/8wO/oO5wsHJmuNKUKo5ng9GiQ== X-Received: by 2002:a17:906:411b:b0:7c0:a48b:2dff with SMTP id j27-20020a170906411b00b007c0a48b2dffmr12784984ejk.43.1671096778375; Thu, 15 Dec 2022 01:32:58 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:32:57 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 2/9] read-tree + fetch tests: test failing "--super-prefix" interaction Date: Thu, 15 Dec 2022 10:32:43 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 Thu Dec 15 09:32:44 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: 13074006 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 7A5DAC4332F for ; Thu, 15 Dec 2022 09:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbiLOJdZ (ORCPT ); Thu, 15 Dec 2022 04:33:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbiLOJdF (ORCPT ); Thu, 15 Dec 2022 04:33:05 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079CD52153 for ; Thu, 15 Dec 2022 01:33:01 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id vv4so50866735ejc.2 for ; Thu, 15 Dec 2022 01:33:01 -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=dyN7nwnlNpOizsuhYNzwQc06JrpwZuYxkgeYscrCIRg=; b=RiXJ7sXRxygbIQrM6qLccj+MqRnd8JjeN2vY1F++7Dqa8W7roTMycmEh4Xq8CmL0sd LcLjsjL0dbZiBM4e/v8mfKGHADN/lcXtinWrc8Pvtwpa4cBBmReDKhvLwlXMkM0OxHN3 JDcXmQT2ZprZ3Kcg6b10DMsj1zueJzigJ13ACIeDi8dXOJgh/2K6feWVQXVlZ7/q4UGO 7E36bOw2UUTGxgufMMHyBaTBA1RMCQ507qypF53wioy3OI+ATuy7LevsE9wgZaqgGkz8 jYO4topN/ivg/2gAeUSwjChiwFP23/yJ0wa26hGB8YKwV6VpzwnC6VwQSEhzsNtUdfAI SMLw== 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=dyN7nwnlNpOizsuhYNzwQc06JrpwZuYxkgeYscrCIRg=; b=Hi6dEW9cYl7DOL0AuAKN8kwcMqprPelPx/CwBw6ZltInXnRAFIykWQu2tOsm7xoYXT pUMonwU6P9fNAmU437om/97WB0jOJYhiT4EceTKppfVScrkWjvclI+s8blpzEqlApU1v Y5+CAh2r4gqcrxObawQnl9BbIiDyLOi/vUtaBcZpAzIX0RWJuIeNpR/uXDpgWRcsjtQC d2+90V/KMQ765+7SjmFhEVPB0GrfcaTmTazo4WCpekshnrFug5gSZvXwmsPiU9/tdtpQ DllA4ZtCpGbQUOiyWUBx3X85N8DlHmJkSm7H1q5IDh9N/ZiaL4fLyeTux27nPKxxoY1J WOEw== X-Gm-Message-State: ANoB5pl02oM98FH+VT9NK8E02tol17LR+99ty2DbkjKwYIu3unrTumDl XhQl0/BevKzrRVPF2JEufz2NSb0SjA2bxg== X-Google-Smtp-Source: AA0mqf6mieLf4vqQ4i8APjkWeuIqbaqMxqeehr0+SG8bE9BaEB/fwArq5iI96YqYH9JkwlIBYnJ3gw== X-Received: by 2002:a17:906:3781:b0:7ac:8e6a:a674 with SMTP id n1-20020a170906378100b007ac8e6aa674mr23002226ejc.2.1671096779460; Thu, 15 Dec 2022 01:32:59 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:32:58 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 3/9] submodule.c & submodule--helper: pass along "super_prefix" param Date: Thu, 15 Dec 2022 10:32:44 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 passs "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 it 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 Thu Dec 15 09:32:45 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: 13074008 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 4BBE9C4332F for ; Thu, 15 Dec 2022 09:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbiLOJdc (ORCPT ); Thu, 15 Dec 2022 04:33:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbiLOJdG (ORCPT ); Thu, 15 Dec 2022 04:33:06 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB18D20BC8 for ; Thu, 15 Dec 2022 01:33:02 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id t17so50890982eju.1 for ; Thu, 15 Dec 2022 01:33:02 -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=Z/pKtmSFLa0JR7iXGPLpiKz8l//uvCQrA5FyBN7pmhM=; b=B+iLAXniVSrduArZGdizKnPbNFXtxh0kgiALkC36o4QyXfM4jzlS5l1cPX0mwNwciY N9cXYvSsMtfUyNj+KGoFJtCXZTIPcgHQl10nDT1uYQMfFKjsh1kK1AOXsR59wvD5KiE7 t+7UfvOVabrXaGMKXH2p0ujSzpMbvRD9h5jtgdfoAD5bo7PCOC8xC8eO5S7wKWn6NLJe XgOxeGxYDDuiSEQVdFhD+RfT7dH6VjYp8ZZMUJS7hMq66EFsXeOK3yAoOP4mcnJg0jYb QDM28eEj1TC+bVztaRyO0V0zzcPT4pplg65ZLdSDFDp06fhQ8xD0hJfYsBpPGhc8WZDN K51A== 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=Z/pKtmSFLa0JR7iXGPLpiKz8l//uvCQrA5FyBN7pmhM=; b=06U6P82DFBsGshOBedXaXZEEitCfbhB2oVoAO/3TGPtK5nOy6cPdHTVMGJrY8J7ogS iv/pL5Uw/FsqTq02MkNr43nkvx4Ey5EYvXX1oxUGhuaoAH5HBPlS4X1js66IxfFnlg/H oGeI4CnvOtHYFwHyvo6UK3WJUimUfpDEz37NjLm1QJRZJEfNV/blxq/NIpDv2DiYkOp7 eVI83Ca4Crsu1U2Bt3cWUs9iYOE8qQwBBE2hihY2/BJtYjVePbDCiWyenUol0U6zi5mC JN4FESzwDWCbz4A/+9B77xXxdWV/mTcls2yEcmOwdNYdEWZBKXMa/xn+XUNVNWu4J1bx z8oA== X-Gm-Message-State: ANoB5plVcifWHZSTmlR1m/lNCHKlVxyWMlg0b3usYlFJ01et7fy0gB4V K8dRNPDYSCHG/CjFgL+WKsPvnJlcToL3mg== X-Google-Smtp-Source: AA0mqf4QjbZLIynG4TB6XFVJCUGicyemKHUvSoJbD3meA5xRDJuoKGi/mMmGAb4R5G76nBT4Gr/x5g== X-Received: by 2002:a17:907:2072:b0:7c1:5ee1:4c57 with SMTP id qp18-20020a170907207200b007c15ee14c57mr14204734ejb.8.1671096780553; Thu, 15 Dec 2022 01:33:00 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:32:59 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 4/9] submodule--helper: don't use global --super-prefix in "absorbgitdirs" Date: Thu, 15 Dec 2022 10:32:45 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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, which we can do here as this is based on a change[4] to make it predictable (until [4] it contained absolute paths). We could also remove the test entirely (as [5] 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[6], 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/patch-1.1-34b54fdd9bb-20221109T020347Z-avarab@gmail.com/ 5. https://lore.kernel.org/git/20221109004708.97668-5-chooglen@google.com/ 6. 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: 13074007 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 72544C00145 for ; Thu, 15 Dec 2022 09:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbiLOJd3 (ORCPT ); Thu, 15 Dec 2022 04:33:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbiLOJdG (ORCPT ); Thu, 15 Dec 2022 04:33:06 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE6472EF39 for ; Thu, 15 Dec 2022 01:33:03 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id gh17so50894183ejb.6 for ; Thu, 15 Dec 2022 01:33:03 -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=vJskAIxH9NEG2Wvc5PBdWTC1TF0l9Jk4ceguWbwKZaM=; b=ht0PzduAq/qvhuyY3MwWfXhUVXUkKKQFkM/vfnvjK4U8EhUPaLqKw96cBlxl0PYv0Q OSKg/KNLaGzPYgUmJm/H3J7W0EK4eFERT3nHFos8uSGWK0BjmYCK8XSNxYAvsGTgNny8 fLXgxUKen04MdlYm0gR31w0oou35HnpbdyeuoYBb6z0fXmzmEts9Fo1VgsTdDn7ZpNa0 dsc9afeVjJQJVW+nM4WqJXAwofQVV5KOaDkoOjheG8DMyDfp/LPsfrvUmBrrQXzY3AWN tGygxUKMdVuF1d4OSoYyJg+kzq3zf0FJHfyWweE4EUuQm5gaHXU21G2hIszWtNPjS65F zQ+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=vJskAIxH9NEG2Wvc5PBdWTC1TF0l9Jk4ceguWbwKZaM=; b=1i18eNNwuTWni2p8QF1WLSq9QqzZ1nPAm0mPR3k6lss+o4KiIC3Af+ZjuzkRavSXxe f42L+eEkl2cEfl1RBdyA70f79/rbxJk0jUeObgRa4ct4Apyjdnd5llQkYsKdQtkOVM1V OKJmi0M3jo9aY/pES8ac5ssZ6UQdAU7tZM2p6RJiN98dwaJp87qwCL1pboPYfqQNTr58 8QXKjRuILPY0gOvFWNqltFD5NjrCPyH4AWzB17B5XJNImQvZFurU8LKw6Ap90zIyPKqu VliqUH0IIGqogjbLUtAWJX8pOS8zSD9N+P+zl7NlHQxjDtAm7k6Digd9mEEZVKJwda3e lG/Q== X-Gm-Message-State: ANoB5plbC0WcIPajgeZ1oKGNL6fURrENVH4CwP4QvVXJlclFAyBrwAHJ Bt7LNzTHM7g2LVAc51wlfFE2VwPCo/HciQ== X-Google-Smtp-Source: AA0mqf5rH8Bwah4AIrCGqZOabk6juGiYWLoInbpOV6w2ZftUMSiZlksDJm6tS6m3u8AUbWrYQq9hyw== X-Received: by 2002:a17:907:d38c:b0:7c1:9020:72a9 with SMTP id vh12-20020a170907d38c00b007c1902072a9mr9689645ejc.43.1671096781619; Thu, 15 Dec 2022 01:33:01 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:00 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 5/9] submodule--helper: convert "foreach" to its own "--super-prefix" Date: Thu, 15 Dec 2022 10:32:46 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 Thu Dec 15 09:32:47 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: 13074009 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 3276DC4332F for ; Thu, 15 Dec 2022 09:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbiLOJdf (ORCPT ); Thu, 15 Dec 2022 04:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbiLOJdG (ORCPT ); Thu, 15 Dec 2022 04:33:06 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B602C650 for ; Thu, 15 Dec 2022 01:33:04 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id u19so32360973ejm.8 for ; Thu, 15 Dec 2022 01:33:04 -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=wIHC85V9uhi1fT0ZMThc1Uwkld8TJa8CRuqYUoItrJ0=; b=XtkhyBF7z7Eabw6T/szZJxyOfuzFs0oCpJFUp8x38iwlGXqgIohibuFkbtH7m9Sp+j GzOk5wu8KQQLj/ywR949HSj8NDncv44Z0JuPVIIc00L9dcG4l4+ed2PyTb72PKO3ponA RYKu4Tu6XKhvO3BJjrlVh8816KyozU+RPdOLl4f4TUiRFa0fdJYFONcbzROcLfTNFJnp OZXYawrfEHnoR1+Vl389CAfYwUiZ2urFFxg/ZwCPNnkVr/d4stLMVRTc97C11lr2LiN7 zsWQenYNelN+vKNSEA/g0ko0YD/82Ez+rRGAKsiVTNugsU8Q1nu02JqTSmxfMYCeFoyd VSjQ== 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=wIHC85V9uhi1fT0ZMThc1Uwkld8TJa8CRuqYUoItrJ0=; b=taRbEer+8DS7HVNY115YEgJPvnjih1Xn51xA+g26OID6ddlFrdgbr6dJGUgXkwtLHN 7xEzps7b02zu9fn6OQkaKsxakJfAv9abrTStaq5QowGosZK7k4e2VoSyvBbCaKy2lSJ+ qSe3AxC5LsgvUYoOVOCUxF24+MsWbY8SXGKvhpGD1Rm5/j9YHfFiGb1aTcry6kAqKIW3 L+xUPeueHrAMjzxu8bfWSWH7ZZ/avUrRiUYx8jyDx8k70um2hHZUrrh9FwaHmLe0xZhm S/6czEbwueuEHbgmB4Z32GwMk19G+PJgS6IhPJl7rZBTjxf3gu7sAp8MY/+jvfqOmq3F NIRw== X-Gm-Message-State: ANoB5pkVZS7k/f143gnaKwR4YnXl0uPOxxj5yCtPlB6qssB8aB4JLuIs k8H5LoiMIZiaW5E1qK91PuEKl5IyVm/0jQ== X-Google-Smtp-Source: AA0mqf4x57TRDAXgTEAUCukpxYQRJ3u53N0NFNx0JdNvWgjL9wnuZImgxK4dTVmVs9REeSmY81EU4w== X-Received: by 2002:a17:906:fd53:b0:7c0:a247:2f3c with SMTP id wi19-20020a170906fd5300b007c0a2472f3cmr19536852ejb.1.1671096782526; Thu, 15 Dec 2022 01:33:02 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:01 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 6/9] submodule--helper: convert "sync" to its own "--super-prefix" Date: Thu, 15 Dec 2022 10:32:47 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 Thu Dec 15 09:32: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: 13074010 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 92B8EC4332F for ; Thu, 15 Dec 2022 09:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbiLOJdi (ORCPT ); Thu, 15 Dec 2022 04:33:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbiLOJdI (ORCPT ); Thu, 15 Dec 2022 04:33:08 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 024965215C for ; Thu, 15 Dec 2022 01:33:05 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id r26so26178408edc.10 for ; Thu, 15 Dec 2022 01:33:05 -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=blhpNHmJyDrK1Aa/+dag4BqH/AmF7c765hupRCGERtU=; b=CuKVck2UXrosmO2nuYezQfMYRRXXncQpS0ZNC8QsJ7thvBagzBO+CfMLkh+jXG3sXG NAZmwTCBQJ7rNjQeDBR4o+YxnB81QS832eYwKNZ9poHLfhZgmFtVM66k7ub12XA60+5L eq+7usN5ayHy5djoBmXSr5OXyi5rNctzO42Y1QuHba0TyLvwn/yjEn9nwRrUxs+dNDti SebZycEtDr4vJES3saVMewc35jEheQO21HxkzLL7psvI2O2eUpZieYRNmIPcH7mc753Y sPHjpLE6+WltYB/RsQ+GEhLKH0j67NeLzfQgZbc6I3EQdG62bHnldH1gAxVVlGbEF37E aslw== 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=blhpNHmJyDrK1Aa/+dag4BqH/AmF7c765hupRCGERtU=; b=MQKFT+kGr5OkxtKwJe55bYYISFtvrCg+halOEjIXfwK2eJlyXlNQe9gmMqoAsnyifU tqrtOic4+dQMZZxf1Cp9kjyPOavX5HeqnwH5WOPs1FI0Kd2okyd+ZmimGVu7WVmpmX8v 51WaYUu6IYx5JlNIsy+f7/FwVce9dEUskkHzJGVq+PkcgsyrYkF2/iFXBfskpfWH8K3o +RZLaUTqzPAjsZpH4w4cEYihscHDM0DzZBm/t0dqINbPuccrOAiTHa95CpyKR0UY2u2h KhR0FfUP11whO+7FgMXelr2tHS0C3fRb4srNX+CK9+InH8z59jaIFSsehQcM0SqRz4gh i6VA== X-Gm-Message-State: ANoB5pmhBTDtKNE8nn19z3042NLVLb2+vVNepNMk46Z2EbL4QjwD/uEI 8uMjpozB+Fyk4H83AERHO1ZMB1SrVl2DSQ== X-Google-Smtp-Source: AA0mqf7bKQkNFEQ+PtVFDCjmItoCfF4YpS3bLqmGhNOaD6Mhf94xjemsPMADZDmbKRpyLC6LEU8obQ== X-Received: by 2002:aa7:cd6f:0:b0:46c:3f90:f5d9 with SMTP id ca15-20020aa7cd6f000000b0046c3f90f5d9mr24371955edb.5.1671096783447; Thu, 15 Dec 2022 01:33:03 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:02 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 7/9] submodule--helper: convert "status" to its own "--super-prefix" Date: Thu, 15 Dec 2022 10:32:48 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 Thu Dec 15 09:32: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: 13074011 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 4A2E2C4167B for ; Thu, 15 Dec 2022 09:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiLOJdl (ORCPT ); Thu, 15 Dec 2022 04:33:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230062AbiLOJdI (ORCPT ); Thu, 15 Dec 2022 04:33:08 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0262952163 for ; Thu, 15 Dec 2022 01:33:05 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id bj12so50801582ejb.13 for ; Thu, 15 Dec 2022 01:33:05 -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=HFppIDdO87weoCISXro5Z+EDPmdDKox592Gp0qF2F2A=; b=G06MfAXPcBqeUqigdfCshoPPZPHN7bvEkyIuuhLYPC4m2uOA3m514rRObGjipRbvzu coOmhYI1NMe6mSCNPk9Q4dqiutJrqD398feHNSoJXbVHZvDQkp4tmkq0KY9zhD/U6Aif VDsV8xqSeAqhezzcsWMXeg9BQrNNTnbpnEWXQrxTrY0mWGEHulykYNMGBqPtZc29oz6e DI/iePQsqWVmgDztBOlQzI8Lg+hKzmmj9cyhXEAyPmqEEbb6z59yOMUs5tjYkK7qbYk7 sO7ZFoPdP66SsOXDpfkNFLRYQJJyGgO02EGTmP5H5Crh5q6QyoNW/F81KjzFHi21x4Qw PGBw== 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=HFppIDdO87weoCISXro5Z+EDPmdDKox592Gp0qF2F2A=; b=MUE8AT7Xq8DLSYpDwl2OG93wos6P0tIrtCVkAQxY4aI00q+YhNe8T1toyU4TnvBZIY 2Gsfn217SIAgj5uuMznuPSm1cYFlZjK6Sm9cXi4bPjdFFZ0p4yk6U//AnCgUafwN8ugg djrU88EQXY4OnGwNNCS4vUEkstYQps+nzvFMRVIupM2F9pJraoUruRDKAw89cDsP89Ii uaElRVJsPdmGkz2VZNlbVgiW+5cUylRTZeyiAGdPT6JmLmupykdE8zgRi3f12knOqFBp /V/q3DFJBnv9/nHiiYzuUTT9fsB1ZW1jEB/MXT5YG7Sf6W38QEuUE3TincDhFT+o92U2 EDxw== X-Gm-Message-State: ANoB5pmhhpl3sIWvymDa37Ua6O1vg/cGRDL3pFEXHx6eJQS0qhuBEdsD 2SwpJVtKVx1AFZ4/zF2B/nOp7DGPtmALcQ== X-Google-Smtp-Source: AA0mqf4TZXypMyLpwGyvPFApCICdMf3J5+t5ng7LHpprEagPvXFu55iSc8IlWdxaxhcheQoB54AYeQ== X-Received: by 2002:a17:906:34c5:b0:7ae:e886:8ccb with SMTP id h5-20020a17090634c500b007aee8868ccbmr33294245ejb.14.1671096784454; Thu, 15 Dec 2022 01:33:04 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:03 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 8/9] submodule--helper: convert "{update,clone}" to their own "--super-prefix" Date: Thu, 15 Dec 2022 10:32:49 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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 Thu Dec 15 09:32: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: 13074015 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 A2856C4332F for ; Thu, 15 Dec 2022 09:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbiLOJdn (ORCPT ); Thu, 15 Dec 2022 04:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbiLOJdJ (ORCPT ); Thu, 15 Dec 2022 04:33:09 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A17C55F8C for ; Thu, 15 Dec 2022 01:33:07 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id bj12so50801710ejb.13 for ; Thu, 15 Dec 2022 01:33:07 -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=paYx084GFx5d6WRiHmPCv13wt+LfRAmXuK6zkGtjv/A=; b=OwAoDrPkHtBaCoY81ecIb7ee7elHD9PbHLFn9/6OERJ6W+NnhlsaT4/h5rxYdza8eE 2GhdP3jzKdYonzKzc/5zaqa3gk4KpL5XZCMJlBOPzymi8JK5X0SgUP2Cya6Msmqt2hQ/ GNlFgPpS4J9Hy8d2SOKi8djVs2XSzb4VfuUcjh4gavPOxDKPsRl53wGjublEg90f5eze 0B1m17Mh6GXVxuvOUf5TVt8+Zna7+q7+s0GYN3onp6VhdeBc42pgGVXcaAGtbNfnRX9X Cq1ufJFDbvaWY+0zdirdcIHbq+Inwtr2cHIMZiDrE1cWpu7SKPNn8XTd/6sqU3TweayS RU1A== 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=paYx084GFx5d6WRiHmPCv13wt+LfRAmXuK6zkGtjv/A=; b=IHZEHx/KTs6YyDA11yupU45Ea6WDsmcyvCnAlIfdHEcvqScx3b8GMMe7d6vtI2mLfp hFxZqkiliKnzf+Qd/X8zxRsyHXqlyt3tCHAChxH+hPiWyhDwOm5pkE+4/L4ztthniPbW UwnZ+SV2ySVmWEd8fX0Fo1n/GhZi+huNhUn72bMyWthq5T1QAnMFm0zVHgIRe/0OOaIn PBvhiyHu+qovStKmU/wdS9K1anGcT9+jGpCTphbrd2cbPHW89cS6xElvORemkbBYDGAj O3e9wUvGWd53+yFHTD/6lCu3uUT62kv4UbAOe3F7XtXvfmpEJobAypvZRrHRpNOPqNrM wamQ== X-Gm-Message-State: ANoB5pk9SerkREwtaxR+AE02CBpcTnXuWRoDEBCm7gdqwbzoc7sk8xxX ywo0QqXMD2EJ38i84qVVs9we4GYZ27p3LQ== X-Google-Smtp-Source: AA0mqf6jaTdPfRoKaAtW01QZ99C5faAqpQqjswGEnITFh0mW+Otfv9bcGGHPOYtLaJAYHO79NL54dw== X-Received: by 2002:a17:906:2442:b0:7c0:a877:1cf1 with SMTP id a2-20020a170906244200b007c0a8771cf1mr24621582ejb.12.1671096785445; Thu, 15 Dec 2022 01:33:05 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:04 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 9/9] read-tree: add "--super-prefix" option, eliminate global Date: Thu, 15 Dec 2022 10:32:50 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b 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;