From patchwork Sat Nov 19 12:41:20 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: 13049709 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 02496C4332F for ; Sat, 19 Nov 2022 12:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232098AbiKSMlh (ORCPT ); Sat, 19 Nov 2022 07:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbiKSMlg (ORCPT ); Sat, 19 Nov 2022 07:41:36 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CEC6A6A5 for ; Sat, 19 Nov 2022 04:41:34 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id vv4so9760127ejc.2 for ; Sat, 19 Nov 2022 04:41:34 -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=+0kVJPrcxV2Y2760PKx7s3eI1MtlXEdJGronuXW6Qbs=; b=PvkJjxV1QbPiOGqBS8vr4m2wbYOZx/cWY1NxUUlbxCo0An6auX/7UlLoaZ/LR5Pl7K DAsIiAYxLWFawTHk9e5wfD/qA3GvFMK6OURut5nn9x1HJC1dU2YxHcsttlln1QTgjEOT nRv86lHhAXo4Kud0FR6x5z2s/eHK5gRBAFVMjFh5YvzcV5cpU1R8z+2KqfsTz9UohRkv u7fUMV3z2a72BWWqIV+8LT/996rYjO5yGUqT9dEnmTLviRVrToQjbpr6GKZSiI86rDMi o+LP0A0K+7qo3hS+lOhO6opzICNBo0oybtkp74bL6hrD0jFscBxqcfeatQxv6VwFvgvT Mbxg== 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=+0kVJPrcxV2Y2760PKx7s3eI1MtlXEdJGronuXW6Qbs=; b=4zn15rbDqFLv/NZ1YEXQCOCvDp8QPGnktSNfgh17DnXRPyrsfXiDRFnRh71/yQfciz CLXeLGdKQaQPTszvfBSS9ZfMNirvIPBZ3SzR6f+fGDCV6QA5PxCrTHRThXrq3BgPCN5h 6/i4xtbbO3hbjgJO5OpN91DnI9mjkBlpVRJZnaY3REY8sQilS7T9HfMvcTJwqGP8+ujC T2LJKKH/Esj4hRD0itgLO1tqyB/hiD6KiZiXs9bcbhXQI4yKVzFiTZAiYsMjTevb6jF9 xgiGGW/vfvxhafWAvOKH/rxkK7ZMmJHg8t1wcLNLlScaG74y3Tgmskez8ZTFoG6fFR4F JUtw== X-Gm-Message-State: ANoB5pngd1ek2RNdPhCHlAxIEQBG9Dsr8KWcGNtL2MgaumhYN93Ha/wt R33/QFnc2XQXOhaqj15oHU6b6YmeZOm9RQ== X-Google-Smtp-Source: AA0mqf7vOkGq2y223L7PyezaG+cOnTGZMnkdEFwOAHYLH9zp+2/b1BrLbXJyGUdoOlaErviPhs1vcQ== X-Received: by 2002:a17:907:9151:b0:7ae:df97:c03d with SMTP id l17-20020a170907915100b007aedf97c03dmr1451724ejs.125.1668861692931; Sat, 19 Nov 2022 04:41:32 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:32 -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 v3 1/9] read-tree + fetch tests: test failing "--super-prefix" interaction Date: Sat, 19 Nov 2022 13:41:20 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 Sat Nov 19 12:41:21 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: 13049712 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 B6315C4332F for ; Sat, 19 Nov 2022 12:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232634AbiKSMln (ORCPT ); Sat, 19 Nov 2022 07:41:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbiKSMlh (ORCPT ); Sat, 19 Nov 2022 07:41:37 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE208776F7 for ; Sat, 19 Nov 2022 04:41:35 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id i10so19047835ejg.6 for ; Sat, 19 Nov 2022 04:41:35 -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=FXZT36h6eub7H/Vcec8yPX/20sUW+f+ZwuuUbq0jw0o=; b=FxJI6W9vEMKpFiLhhOGqcQCHFWgcLRMdPeGcravGG4rpdbqDpmmwcPQA4BSeU7hQOw EwbTQOsXuoTg0wCXdmZPxGNGalMiJFz490X92cSMxQXly2G2W+yOq/wQ0sc20ozZEwVD N1kzJJ19lOZoMxmn6dH8rl5VC8xUmAgLuxxl1jTetofxJCPcyYdeaputqVwqlFr1DopE X6VTxFRCHjbwhDYcxEIunwYF/P2hPKi9RMKJRvSXi18sRpxI4Jj5VzUU5d32OBfA4mJo 0nODfd2kvoAKkgLYrbbs7OfLrOHxhphYF/9g3FtKYn1Kcz17C29vD8qh8Ua61Vwj3hon BLrQ== 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=FXZT36h6eub7H/Vcec8yPX/20sUW+f+ZwuuUbq0jw0o=; b=oU9PJibtzcu9qkz0hHlg5ZBOZ22mKA1QDFnU7i9EKRjOoaLOCVY/YbddL71FU/CHPO MbmLQ2+9OSzbSAk0jwdqG5Ibj9PZIH7H4g+Y3naMrsY18nt3wqLo+9GQ1uS22BPsuavw LVKF1zup1vFj9A5TQHcqA4EKoi2i3lqYuJZdMZ7Ns4WTwxmcwnsv4NBP2WI+jnuwbBOs TkmSjhj56PbxoXC6LSEnmMqUPR67u72BWeBT1GKmc/PlHwKTIijjW9xQ2Bd+63Mq3KbQ G4h5BMsJNW8H5NPjgIN09lMQJmj4XMwZnXYmPpAgbVXlgsuNXfsw/M0eb4jbvW+iCUDA v79w== X-Gm-Message-State: ANoB5pkGLMiYZlPuMHzP27xTnNn7h1Q9bKXeF6FpKBalkNeuZJGxzjP4 EBZQ6AUKSxP/rNmUtrsOgdE0DXnpcPJ++g== X-Google-Smtp-Source: AA0mqf5V+LpDjMCgQuGvMKagUlSPIVrj7TjtZiD2pV59xPs8EoQN5AEkD0VCU3d/EDgK2EPXnvZtAg== X-Received: by 2002:a17:906:b46:b0:7ad:a030:4816 with SMTP id v6-20020a1709060b4600b007ada0304816mr985755ejg.765.1668861693926; Sat, 19 Nov 2022 04:41:33 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:33 -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 v3 2/9] submodule.c & submodule--helper: pass along "super_prefix" param Date: Sat, 19 Nov 2022 13:41:21 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 05bfe20a469..24e13f6e899 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 c75e9e86b06..dc220d3348b 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 c47358097fd..d339ce3b62c 100644 --- a/submodule.c +++ b/submodule.c @@ -2139,7 +2139,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, @@ -2313,7 +2314,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; @@ -2321,8 +2323,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); @@ -2335,7 +2337,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; @@ -2384,7 +2387,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 Sat Nov 19 12:41:22 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: 13049711 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 C58C4C43217 for ; Sat, 19 Nov 2022 12:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232947AbiKSMl6 (ORCPT ); Sat, 19 Nov 2022 07:41:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbiKSMli (ORCPT ); Sat, 19 Nov 2022 07:41:38 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC8937D519 for ; Sat, 19 Nov 2022 04:41:36 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id bj12so18962771ejb.13 for ; Sat, 19 Nov 2022 04:41:36 -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=ssYWGGouKBApoA2quB1y6MP5G+A6+oXdhcQDh/W8eDk=; b=JNolCjAboqLzxUXx0L8HkB9dENQMQos35vbfG/DmMBi5UcDIb4rC1OXG34QdskxyWi /tFQkYxEgnPdu7TxuTgtKYtrA+1F74IMDMesLWaTV293VbJvHjpA3hNMPDbPFn3faiIq 44Q54rbudDRXb5B9ApN5IusHtSeI3VrsrpXb0mDBDJKygRIUNW4p/Vm1W0SoWbp/1Ait Ydywo6OW+gpr++kEPjkNQ4bB1fwScKMDlB7ajuhkHiNlsXFVq4TLN+63VBiRa8G+zQ+S faxp8U6VDDuQw7jq4gQWVHudMTqE1HgfIc7sStesVYlMEh9KoxUNVQQRZqReKJDBsy9b sstA== 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=ssYWGGouKBApoA2quB1y6MP5G+A6+oXdhcQDh/W8eDk=; b=sz9QQG3C/ikAbLGvPkpWG8kD2q0PSuvCVttIyTHTk6C3quR/s3AQKkcEAHavJQVF0H hqWg6zJi334MTQkn9sdZu7yqqteEjM47phWdC6Nimu81xjRe/ZDUNzb/YUw9naKmUOpH qa6p1cnPAPI+IlXNIC7paHN96zl9PYPOluyAC0MAyVeB48CK7NLMUbq06NSvv1IzCas8 vn6vFz3c1n/I9wAeURKaw0lzo8oB2RuKYVslebfESPLdxnmh1k4UPuv2eJt8d2rBCViv iZdIzLrScpZzDnpDwJAtNjYPbB9rPWeP6pFEViWA83CWuzzPKjYl4W+Lb4pW87uRy7gY CEFA== X-Gm-Message-State: ANoB5plodulTwmQrY2avrvMWGX4BdC4A4xmDptoIV+bYJj/PDLN7eSf/ BRXpBDBz5aaYtyq6U7PGBvz0jOpV3IgmqQ== X-Google-Smtp-Source: AA0mqf6+XEyW0qWBQmFcciHuZenLOQDVlNSCPfi+FDhafH1ehwJ7en7hTCL/es3Tf6qZcwyKVE4yqQ== X-Received: by 2002:a17:906:6d88:b0:7ad:b86b:3ff with SMTP id h8-20020a1709066d8800b007adb86b03ffmr9715101ejt.448.1668861694879; Sat, 19 Nov 2022 04:41:34 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:34 -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 v3 3/9] submodule--helper: don't use global --super-prefix in "absorbgitdirs" Date: Sat, 19 Nov 2022 13:41:22 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 | 33 ++++++++------------------------- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index dc220d3348b..9f6ebc64140 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 10202a7f126..b1b7e1a837e 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 d339ce3b62c..3383c47c719 100644 --- a/submodule.c +++ b/submodule.c @@ -2269,7 +2269,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; @@ -2303,7 +2304,7 @@ static void relocate_single_git_dir_into_superproject(const char *path) real_old_git_dir[off] == real_new_git_dir[off]) off++; fprintf(stderr, _("Migrating git directory of '%s%s' from '%s' to '%s'\n"), - get_super_prefix_or_empty(), path, + super_prefix ? super_prefix : "", path, real_old_git_dir + off, real_new_git_dir + off); relocate_gitdir(path, real_old_git_dir, real_new_git_dir); @@ -2323,10 +2324,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); @@ -2380,7 +2382,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..31526937d95 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -866,30 +866,11 @@ 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_when_finished "rm -rf super; \ - rm -rf sub; \ - rm super-sub.trace" && + rm -rf sub" && create_super super && create_sub sub && @@ -904,10 +885,12 @@ test_expect_success "stray submodule super-prefix warning" ' test_path_is_dir super/dir_1/dir_2/sub/.git && - GIT_TRACE2_EVENT="$PWD/super-sub.trace" \ - git -C super submodule absorbgitdirs && - - ! have_t2_error_event super-sub.trace + cat >expect <<-\EOF && + Migrating git directory of '\''dir_1/dir_2/sub'\'' from '\''dir_1/dir_2/sub/.git'\'' to '\''.git/modules/dir_1/dir_2/sub'\'' + EOF + git -C super submodule absorbgitdirs >out 2>actual && + test_cmp expect actual && + test_must_be_empty out ' # On a case-insensitive file system, confirm that the daemon From patchwork Sat Nov 19 12:41:23 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: 13049713 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 4B177C43219 for ; Sat, 19 Nov 2022 12:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233792AbiKSMmB (ORCPT ); Sat, 19 Nov 2022 07:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232440AbiKSMli (ORCPT ); Sat, 19 Nov 2022 07:41:38 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D176DFF6 for ; Sat, 19 Nov 2022 04:41:37 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id kt23so19038732ejc.7 for ; Sat, 19 Nov 2022 04:41:37 -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=5mCAjkSY1TGHxqypYwQ90x30RUo/JYzcijoSCTILXqk=; b=bdzdiKsp7avsxJ5bxgzgPaMVl55O61Y6nuGVc0IFP5KyxmbS8Ars8mfAI8jK7cZVs0 0wtd10l9qVfK172cWy1ao4KPdYpuxmUigfpsRPcYyqBh0TbiTPNc+QGkZjFtds3XHMJp M6lrWBmyVs/2gX/z12pH5BdZpD3dezEBSjsqjaVY3FlOrXRBHNv68qpi8Nwu8d+S86qp OjP2F3A8TkVNQ62WlwmmnIFR8+7trYH7Fi+6urPIUpOb9uO3OzdbJMrp8aGxILySjx7S O0MioaMhU0XmExmVks2bsgThS30x8vhhqeHIP8zyLI3aF9MFwkH2UrZR6L6nqkuEJ5YP y3/A== 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=5mCAjkSY1TGHxqypYwQ90x30RUo/JYzcijoSCTILXqk=; b=qo6wjjqLpKqwXb7pc3yCGaohJGTvLOUHXq1py7GKG01V63f8oaQAe2pqgE6g5HPbUX 2tNKx4w1J5nqSbDFfJfDRArn+dCzOqwawwT/dV/sb1E5cHjAhIniUn6ZuR+v3yUj9RJq Iuta38ht2/KIriUhvzUI18yDQkJZbLc6A5zg+JFBGT9xj43h2xwjeD2WfsNZ2KxRbVic GSs+7/158IxhyeuoLatxqRSIfRF4hLU1hdaBKCMzbil5JO3UNU3qpizdvkkNGINjM7o9 IDy0hfkFP8NZ7YrZlIGdZR1UVkSdt3IuXQik8XJE73Q8EvrlVLS+Mu+sobxcUCrU2lqi EDmQ== X-Gm-Message-State: ANoB5pk5tsthxN4FtIfj5fmUALx1S5r9DsdVGwtyq4rramTLRQwjLAtk 12YkvtcmHpsS3Au8DDEc7fwbdv6AeJ2fkg== X-Google-Smtp-Source: AA0mqf6WjCQ9BrFTfg9s7YRJeQbOUiTvBayBS33ApaaChWLsl+oSPcVVwAae14sPfyNJuORil/RU9g== X-Received: by 2002:a17:906:4c98:b0:7ad:b9f3:a66a with SMTP id q24-20020a1709064c9800b007adb9f3a66amr9661575eju.282.1668861695931; Sat, 19 Nov 2022 04:41:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:35 -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 v3 4/9] submodule--helper: convert "foreach" to its own "--super-prefix" Date: Sat, 19 Nov 2022 13:41:23 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 9f6ebc64140..7c6f367fa00 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 Sat Nov 19 12:41:24 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: 13049715 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 167EFC4332F for ; Sat, 19 Nov 2022 12:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbiKSMmK (ORCPT ); Sat, 19 Nov 2022 07:42:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbiKSMlw (ORCPT ); Sat, 19 Nov 2022 07:41:52 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F76885155 for ; Sat, 19 Nov 2022 04:41:38 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id f18so19095475ejz.5 for ; Sat, 19 Nov 2022 04:41:38 -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=zHmq0KJH1RMch2HUOcWaDb3YGfM8DqE3qdp/tfVsyZk=; b=Q3I1FkFSOUM150MqIz67qNAABr55hhtauopTwzaen0dj5RYmljpgp7xOz3ijHJMltF o+ep8E+kh2OdNOvxGI/szt9UNROqQS7pE55hp1v2W3jbRd2MnqH6i+XNqbBLrlGhH9uS IKYfTvZVvT5H/fFld9noAhBmEptEyvyjsRPQvH+Ki54ExLJi3JOUgEw08cBHiv8+V0Wq btesgBDtBTu+QHKRF7Znx964udwlTHAm6UYAUuT7CSkxTooCEX/mnSYOkvr5iwVc9uXy 2X8NgnF9tIMB3o19HgczLOcN54zzLxFGT83wzVFngKLTqucGkWR3ZLWFYPOzGWFu8q7f Telw== 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=zHmq0KJH1RMch2HUOcWaDb3YGfM8DqE3qdp/tfVsyZk=; b=RzAZ9qZ6aUIR+OLSzgA6BCd3PBta8DznIePDGACYD5iCxwn5Ecph4AXcDvVtLfLaCb TnrdZtXUfwWN0koLhDoJabdltUrxP6EZu4jXgx+U35eeeo8j6jCYreAJ05jHzXwGW/Vn tV+zggNAMG0nXvYclWM9fKRSqBX4Jt9hqfACrWkhrdCjemtKp+mv0nrUdR2cnRus1YuS tmQR4chuZOGGnGT/C8UFIHI9Mv5YtnnyWZnx2tyo1VuM3976Fjz95VGnhBBDmdjqZVvI EhmB01ry4qN15vyz3ulLkcmgALo7/5YoxwbwzBhUHXegC8XVil87WYK7ZdH9jukcejZY 3kzA== X-Gm-Message-State: ANoB5ply1lFhGRq08TMwpFZYj+J2RJZMNDpU8yCATRsbz1VNfIW6UZzU NeTIhwrr6gSgcNWpDfw2taeWoHRWmNZhuQ== X-Google-Smtp-Source: AA0mqf7DV1fnoLDp5PeuCyLmyfJnFRBWcpiQ0yaTOBAHpAPZr6PQ8ZX5L/lBikBqxq/P7t7bP9wz8Q== X-Received: by 2002:a17:906:7fd6:b0:78d:b5be:e5f with SMTP id r22-20020a1709067fd600b0078db5be0e5fmr9220329ejs.601.1668861696816; Sat, 19 Nov 2022 04:41:36 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:36 -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 v3 5/9] submodule--helper: convert "sync" to its own "--super-prefix" Date: Sat, 19 Nov 2022 13:41:24 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 7c6f367fa00..7ac51c3506d 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 Sat Nov 19 12:41:25 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: 13049714 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 CB590C4332F for ; Sat, 19 Nov 2022 12:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233933AbiKSMmG (ORCPT ); Sat, 19 Nov 2022 07:42:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232761AbiKSMlx (ORCPT ); Sat, 19 Nov 2022 07:41:53 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BC6B79344 for ; Sat, 19 Nov 2022 04:41:39 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id n21so19014627ejb.9 for ; Sat, 19 Nov 2022 04:41:39 -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=h6fnov29Km6PoPkq5gQ0mLszmdabuUvwCuWXWxGqimY=; b=qpXy6Sk9RcbAmtPwNRApKNGH1MoYqL24l1WIE0akA1REPhuR9W2/epTiEoiTXxOI0K SqoMeSZL85ekdcHOIvnaeUt6KnsBLBdhCZPgBNIn9b7N0kvVDxYNQw62kPTDrhkN3RYx ig7u6MsFEFeGdaxXRbGZpADnNHQqHvxQq8OMAEt7z5EJj1EhSio+hEpwQw/5IG/K9oBN KP0FglkOt4J51Ookfp6SHqMZST8EGPZAPYVtdS0xvmx/waz0UN3vLxnzxvRyRadKM7Ka o03D6UTQshnHKITyJbI2PFcXkR6DDWyb4+nlD2mecPzlWJedisjri2PegbOzhnc2rqRC iHaQ== 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=h6fnov29Km6PoPkq5gQ0mLszmdabuUvwCuWXWxGqimY=; b=J6GVFNk+tMILUDW1W54ZcQ0dvd8Z1xKq8w1KPcnxiULnuBlLVAfblaY9nHIRHVwZiu R7wJ0RUYyMWvZUV0Yqh69PEo5mh2do7s3PZ5Arl8+RXH025+8PQyIUP/yIUMFbzeFj4Y MsDzchTWFnd5xa6AlyZ90X04Yu/xB/oILbHd0ESvVU91ZOd5epaqkMWg36cP2ven+AKz HMakSxe6O9dkinIDk+tyAHdhNSqadOBhmfI3eLywA7tRB2RZMIjHk8qZ/Y89wntEd9XD GvT5aHmX0803cdO5cD32Nto1B92g56ilxFNCyDd1tvNOC68lJU5q3w8cuXpIR6QrTKiN O4uw== X-Gm-Message-State: ANoB5pkZWWkuJIGkkiPHytGdaMMHmgyFmx51VoFWRq2nknN4i8N4XK0c jDzUnuN13hzwRMoBRmZbt8KixJajC72G0A== X-Google-Smtp-Source: AA0mqf5P5wduADJmEG3r7ZmObsEwMEugNMRgv44JXqNvMTIlJTc3ZZkVZ69uKiQl16K9+wclKHfWuw== X-Received: by 2002:a17:906:6892:b0:78d:ab48:bc84 with SMTP id n18-20020a170906689200b0078dab48bc84mr9851428ejr.22.1668861697713; Sat, 19 Nov 2022 04:41:37 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:37 -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 v3 6/9] submodule--helper: convert "status" to its own "--super-prefix" Date: Sat, 19 Nov 2022 13:41:25 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 7ac51c3506d..8a186b61b9d 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 Sat Nov 19 12:41:26 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: 13049716 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 98742C433FE for ; Sat, 19 Nov 2022 12:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232547AbiKSMmM (ORCPT ); Sat, 19 Nov 2022 07:42:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233606AbiKSMly (ORCPT ); Sat, 19 Nov 2022 07:41:54 -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 676958CF0C for ; Sat, 19 Nov 2022 04:41:40 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id ft34so18969514ejc.12 for ; Sat, 19 Nov 2022 04:41:40 -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=dvx+E1XZAvvtVIY/FYVscLmSEGgszPvEUCZwSz5aFtg=; b=BxFJ0KMeNu/SNaAeH3Y6wRwTIanvetRKdLEf2+jgh07xgKLeVjWBbuoPlX9g1/M6BW zqNzUXW60dLMNUtbMQWpJ17fWqkC5lA4+ZFzhn8zLYkMGv8lJgJlgvZrW9M9zOFsLsl/ ZkXIm1dwwgx3fcDkZJGY1XyFYhS3YlVLoKaAhU/iGDFTBCRXepYhqnX2AIXRNvl/O9T0 JPCugD98U2OFlJzEizppe+ZjWHFABOKmXGy44avNcz8BQj7UcidE2CItgY95NrpScY0Y 5/W1yBdrKiXpeY+R6gTCDdcZ8vxk35LQva35xcpXXxmhOST9VDeKT43R9heR/tuFAgE2 KO+g== 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=dvx+E1XZAvvtVIY/FYVscLmSEGgszPvEUCZwSz5aFtg=; b=Ix8cTyR1oI5OTTYWesBCvJc8mSvPYLVeg/1EvJnTFfDDpb7WliccF3VDRnkQkZPhSH 0h8xjqyhBbFqaezx2V3V71SC6e/GtadHxvTjqQmfBpZZQcZqmn40UcX/NF29TKr1VF+U OqVU1HsC6I9k1eKw39CwUntQTehRoXds1F1BdlluPNlN4bDUM3VU1GPyxmJQZZZibQW1 i/BWQGRiQ0REGVv126ebWoXmxXlykqMrbacQoCrOyoH/28+GHOUyylpcAfSmy/GkBkJy /RQ3VuZIxqU/UGMdGgyrgppIaVw+imIpty4OA7mGaeVbf4qUS6bF4vTE30wUG4G1abXl Ti7w== X-Gm-Message-State: ANoB5plTb1w3bFl+B9UZo0CBYL6dNBGxZiE5rt5at3jDWYPBJ9/v2ayV NoytSzpifWRrLtA/2gpy6REeNspkq6tqgA== X-Google-Smtp-Source: AA0mqf6oc+g9X/uARoY6sfkFwhj7dlo1rqMY7EJFvfoM1yNcQkksnFtQ5TFKqvA5mj0+oTiTGa8yhQ== X-Received: by 2002:a17:906:f858:b0:78d:b654:8af9 with SMTP id ks24-20020a170906f85800b0078db6548af9mr1347423ejb.660.1668861698626; Sat, 19 Nov 2022 04:41:38 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:37 -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 v3 7/9] submodule--helper: convert "{update,clone}" to their own "--super-prefix" Date: Sat, 19 Nov 2022 13:41:26 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 8a186b61b9d..b1945a06da1 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 b1b7e1a837e..2bca22cfd9a 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 Sat Nov 19 12:41:27 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: 13049718 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 B5C32C433FE for ; Sat, 19 Nov 2022 12:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234058AbiKSMmR (ORCPT ); Sat, 19 Nov 2022 07:42:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233765AbiKSMly (ORCPT ); Sat, 19 Nov 2022 07:41:54 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A652C8C790 for ; Sat, 19 Nov 2022 04:41:40 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id i10so19048124ejg.6 for ; Sat, 19 Nov 2022 04:41:40 -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=fXVIz9WCsWsiMyLy6e5RxDupZGnyo0FkkivtPW31m7U=; b=o9/ak9WeKti8Bx9bTo850uHNIBQplVTagnQbyjgXFnmveykUauzkEisUifiGcwS6vj 7FFWbwnZmMawZqe/gLaOCBLACq2HW9FtrShsZAZ3xsub8JnwbKyD/wrQAkYXC2T4ZmEt gPMby1rZQR1hh+JyHwDpKESwWzxN9eqaD+LClN1UeQztSKEA7A1efwqiN1Oj0B8GZJyv DSvk8EouDSdQcQvg3MH8jV4qUyScpmlPM/+CvX1XP2BLqbxMG6Gn9Xdty51EF0tLUcTu 4gjM0UDrNsXdQsResguQGNNtp4zz14H58Ho/GfqKuQLBNpPg76LlDouQjeSc7z8Hfbpk M6FQ== 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=fXVIz9WCsWsiMyLy6e5RxDupZGnyo0FkkivtPW31m7U=; b=NPHXQBu1tm4XNbbn3IJgfikduZRcJT/7J+Ut0/Z/BwG1ImoBsFxXFq6EwLKWSyyhGQ GXt5XsD1lp7BN5q65glkYoLDCH1pdygeIA4Nz6W5+yuVeol1q1tgjSb3vPhP6Q51nR0E mbA+ZhyuAziPBGD1+ksK2mmGRhyp/nEh/qA8ZgXAVifXRTMvjELLIEexQnB1CF6997g8 ltcJAJCZfrTgd56xyQGTsusmH1q9yLg29mVyBfK+SQX7+5x0x/P3NYcopzXQvY/MSa9R 7xN9OVXueigOwp/IWBVYQk96Ka2/sLnrKjYRvhmhTDXPqkNAgpnkpDFqyYtDfHimjYzP TFIA== X-Gm-Message-State: ANoB5pny5ZKag5K1WQN/Mb3FlS5SlHrw8a0FmhrzFoet3ob5xT6cfWVY RbYW33HMwFVEU89XtEBaONzAfDGVMMf2iA== X-Google-Smtp-Source: AA0mqf4vcHOC8aP26sk7JhCJaVXImz0HfHQ57cLnYKBCpzWsmGYZtvwqYDqP1bcHJ3cqWLsuqAiJOQ== X-Received: by 2002:a17:906:79c4:b0:778:e3e2:8311 with SMTP id m4-20020a17090679c400b00778e3e28311mr9698308ejo.342.1668861699566; Sat, 19 Nov 2022 04:41:39 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:38 -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 v3 8/9] read-tree: add "--super-prefix" option, eliminate global Date: Sat, 19 Nov 2022 13:41:27 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 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 | 23 +++++++++++++---------- unpack-trees.h | 1 + 15 files changed, 47 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 8901a34d6bf..8264b7e5241 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 2a132392fbe..dc008fb45e8 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -231,7 +231,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 f4cbe460b97..4b6f22e58c1 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 26ed03bd6de..a4a0377b800 100644 --- a/cache.h +++ b/cache.h @@ -504,7 +504,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" @@ -590,7 +589,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 2bca22cfd9a..00baaf23590 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 3383c47c719..f8497793790 100644 --- a/submodule.c +++ b/submodule.c @@ -2048,14 +2048,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; @@ -2074,7 +2066,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); @@ -2083,10 +2075,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()); @@ -2099,10 +2091,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; @@ -2140,7 +2131,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, @@ -2149,7 +2140,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, NULL); } if (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) { @@ -2167,9 +2158,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 bae812156c4..61c02285454 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,7 @@ 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, NULL, old_id, new_id, flags)) return add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name); return 0; } @@ -415,6 +417,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 +448,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); } } @@ -2958,8 +2961,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 @@ -3020,7 +3023,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 efb9edfbb27..9b81e284073 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -74,6 +74,7 @@ struct unpack_trees_options { dry_run; enum unpack_trees_reset_type reset; const char *prefix; + const char *super_prefix; int cache_bottom; struct pathspec *pathspec; merge_fn_t fn; From patchwork Sat Nov 19 12:41:28 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: 13049717 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 D430CC4332F for ; Sat, 19 Nov 2022 12:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232615AbiKSMmP (ORCPT ); Sat, 19 Nov 2022 07:42:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbiKSMly (ORCPT ); Sat, 19 Nov 2022 07:41:54 -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 2C1C58DA78 for ; Sat, 19 Nov 2022 04:41:42 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id gv23so19094287ejb.3 for ; Sat, 19 Nov 2022 04:41:42 -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=I3MzBb6i1dbRkOGAq3WpDodouuNlqx43saw6/vaxp/g=; b=XT87Hd8q8apReiC/wvESFq9V0ERP4sWwH9spGK1C47zshkoB0u05ZxvWNQfCVK8J44 P4k3CQXxfpL/Or8SCt/cThSW1S4ayTO0o6rXYnGLKc9XpdyyOgsWFawGWMgmJQrvPgyu LLwMIhzhqou3ODrbWg/bNHLH8X2Aww+rVlBDE1zYBQ8+tBmN8UEHlAT8rVav+X1VyuOB HoP22KE7fQ13PEjvBaPXMHkfJZbN7LWdmNkIaoilA3ED9ZxSVbHo2aNqO9LlUwbdxcXW qKv+FZZiXG8aybRkowaVd5LONuYuTgCoSHBtC0x1NAZEmxtG3iHakeI2aTe1QcaZRv32 WAZQ== 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=I3MzBb6i1dbRkOGAq3WpDodouuNlqx43saw6/vaxp/g=; b=Od9BCZctwjbdVReG9aTT0CdlewKn9+VYaU9pnfc+c7kfhgyVBBypEwS08L1Lnw3Klk M/dDR3B7Izk8GqcWBHCzaOAJenXBo8eHChj1dVl5NvaGCdwuZ3VmrLaOKbyTqO66D+c1 bsbXwDjTG44pKvDBTh2yKKw3flBaXKYi75RO8GMunyC2maPPkzsPgy0/7pxCnLpSzgX0 aBR5d0HaxV0TudnmxHzUcuJEaGrLGEU44F4nsdNdmQbOUzerP5Az13LNOd59K8nzdVE8 f6GXOwtMB3ZXf3DSdhSeGOU5881IQnr7TVant/xoPB8BHDLFrZKgCuR5r52MN4+JI2go fAdA== X-Gm-Message-State: ANoB5pkNUuf3/H/hRqsHOO0+0ACNMQtxAE9ox5sDIgs55wCsM++SmVqq HtYTSt9zZcSX/3Jy8cBY0m4dUAzhjdalvg== X-Google-Smtp-Source: AA0mqf6DXWYT6erKiKFY2HRVwnPHQ/X7cTMkzAADb3To2liLIeqnCJVUjwVtUEJVuXB7FACCpaVJWg== X-Received: by 2002:a17:906:4cc1:b0:7ae:50c6:fd0a with SMTP id q1-20020a1709064cc100b007ae50c6fd0amr9137957ejt.184.1668861700187; Sat, 19 Nov 2022 04:41:40 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id la19-20020a170907781300b007b29eb8a4dbsm2909276ejc.13.2022.11.19.04.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 04:41:39 -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 v3 9/9] fetch: rename "--submodule-prefix" to "--super-prefix" Date: Sat, 19 Nov 2022 13:41:28 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1509.g9445af83948 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In preceding commits we've introduced a command-level "--super-prefix" option, which unlike the "git --super-prefix" it replaced doesn't rely on setenv() or getenv(), it's just a normal command-line option that the command passes down. Since we've done that, let's rename the "--submodule-prefix" option added in 7dce19d374a (fetch/pull: Add the --recurse-submodules option, 2010-11-12) to "--super-prefix" for consistency. This: * Allows us to use OPT__SUPER_PREFIX(). * Leaves an unspecified "--super-prefix" with a "NULL" value, rather than an empty string, as is the case with the other "--super-prefix" users. We coerce the NULL to "" in submodule.c before using it. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/fetch-options.txt | 5 ----- builtin/fetch.c | 7 +++---- submodule.c | 23 +++++++++++------------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 622bd84768b..20cbd2c2910 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -241,11 +241,6 @@ endif::git-pull[] linkgit:git-config[1]. ifndef::git-pull[] ---submodule-prefix=:: - Prepend to paths printed in informative messages - such as "Fetching submodule foo". This option is used - internally when recursing over submodules. - --recurse-submodules-default=[yes|on-demand]:: This option is used internally to temporarily provide a non-negative default value for the --recurse-submodules diff --git a/builtin/fetch.c b/builtin/fetch.c index 7378cafeec9..353bcd36d24 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -74,7 +74,7 @@ static struct string_list deepen_not = STRING_LIST_INIT_NODUP; static struct strbuf default_rla = STRBUF_INIT; static struct transport *gtransport; static struct transport *gsecondary; -static const char *submodule_prefix = ""; +static const char *super_prefix; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND; @@ -195,8 +195,7 @@ static struct option builtin_fetch_options[] = { OPT_SET_INT_F(0, "refetch", &refetch, N_("re-fetch without negotiating common commits"), 1, PARSE_OPT_NONEG), - { OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, N_("dir"), - N_("prepend this to submodule path output"), PARSE_OPT_HIDDEN }, + OPT__SUPER_PREFIX(&super_prefix), OPT_CALLBACK_F(0, "recurse-submodules-default", &recurse_submodules_default, N_("on-demand"), N_("default for recursive fetching of submodules " @@ -2300,7 +2299,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) add_options_to_argv(&options); result = fetch_submodules(the_repository, &options, - submodule_prefix, + super_prefix, recurse_submodules, recurse_submodules_default, verbosity < 0, diff --git a/submodule.c b/submodule.c index f8497793790..3e0aaaa2af0 100644 --- a/submodule.c +++ b/submodule.c @@ -1376,7 +1376,7 @@ struct submodule_parallel_fetch { int changed_count; struct strvec args; struct repository *r; - const char *prefix; + const char *super_prefix; int command_line_option; int default_option; int quiet; @@ -1567,7 +1567,7 @@ get_fetch_task_from_index(struct submodule_parallel_fetch *spf, if (task->repo) { if (!spf->quiet) strbuf_addf(err, _("Fetching submodule %s%s\n"), - spf->prefix, ce->name); + spf->super_prefix, ce->name); spf->index_count++; return task; @@ -1629,7 +1629,7 @@ get_fetch_task_from_changed(struct submodule_parallel_fetch *spf, if (!spf->quiet) strbuf_addf(err, _("Fetching submodule %s%s at commit %s\n"), - spf->prefix, task->sub->path, + spf->super_prefix, task->sub->path, find_unique_abbrev(cs_data->super_oid, DEFAULT_ABBREV)); @@ -1687,11 +1687,10 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, strvec_pushv(&cp->args, task->git_args.v); strvec_pushv(&cp->args, spf->args.v); strvec_push(&cp->args, task->default_argv); - strvec_push(&cp->args, "--submodule-prefix"); + strvec_push(&cp->args, "--super-prefix"); - strbuf_addf(&submodule_prefix, "%s%s/", - spf->prefix, - task->sub->path); + strbuf_addf(&submodule_prefix, "%s%s/", spf->super_prefix, + task->sub->path); strvec_push(&cp->args, submodule_prefix.buf); *task_cb = task; @@ -1707,7 +1706,7 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, spf->oid_fetch_tasks_nr--; strbuf_addf(&submodule_prefix, "%s%s/", - spf->prefix, task->sub->path); + spf->super_prefix, task->sub->path); child_process_init(cp); prepare_submodule_repo_env_in_gitdir(&cp->env); @@ -1717,7 +1716,7 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, strvec_init(&cp->args); strvec_pushv(&cp->args, spf->args.v); strvec_push(&cp->args, "on-demand"); - strvec_push(&cp->args, "--submodule-prefix"); + strvec_push(&cp->args, "--super-prefix"); strvec_push(&cp->args, submodule_prefix.buf); /* NEEDSWORK: have get_default_remote from submodule--helper */ @@ -1813,7 +1812,7 @@ static int fetch_finish(int retvalue, struct strbuf *err, int fetch_submodules(struct repository *r, const struct strvec *options, - const char *prefix, int command_line_option, + const char *super_prefix, int command_line_option, int default_option, int quiet, int max_parallel_jobs) { @@ -1835,7 +1834,7 @@ int fetch_submodules(struct repository *r, spf.command_line_option = command_line_option; spf.default_option = default_option; spf.quiet = quiet; - spf.prefix = prefix; + spf.super_prefix = super_prefix ? super_prefix : ""; if (!r->worktree) goto out; @@ -1847,7 +1846,7 @@ int fetch_submodules(struct repository *r, for (i = 0; i < options->nr; i++) strvec_push(&spf.args, options->v[i]); strvec_push(&spf.args, "--recurse-submodules-default"); - /* default value, "--submodule-prefix" and its value are added later */ + /* default value, "--super-prefix" and its value are added later */ calculate_changed_submodule_paths(r, &spf.changed_submodule_names); string_list_sort(&spf.changed_submodule_names);