From patchwork Wed Nov 9 00:47:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 13037009 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 0D21AC433FE for ; Wed, 9 Nov 2022 00:47:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbiKIArg (ORCPT ); Tue, 8 Nov 2022 19:47:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiKIAr3 (ORCPT ); Tue, 8 Nov 2022 19:47:29 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5CB661763 for ; Tue, 8 Nov 2022 16:47:27 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-373582569edso149515167b3.2 for ; Tue, 08 Nov 2022 16:47:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i/h0Sp69CAAj6L95ExUwzsRdpopQ26Y/9QJJvEoKlgY=; b=nm/e+uTw/YjdyXIGPi+eksMerKXd3YdO5cOs2itxfNWAZu+X5XfYTj4bIYE8N+jIK4 dcO4hoRBi8qj/Oy3GPhT2J2L7NYeUnJpafuYnw5TEMOeAYJEIWQ2iJDyrYegspTjqhf0 lsqRu3aM9cBZ6pO7/P+EpwNnQBz90dr8Q1fRfflQGS2LwiN5nPmhm7wmW4JDImTfu+sF vBw4kymo2crJJVr4R20+Y20lvHhoweww6ke7+mxe/+jVOCkcSgMjg6qqY6PIiqlzFwNn aXZltVJ13xayv+GSqCFwzEpKW8bg43rT8jlgOBb75DeFpCTCAyL8IeSlcU4MiXIjPG3v noLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i/h0Sp69CAAj6L95ExUwzsRdpopQ26Y/9QJJvEoKlgY=; b=YZOyWSin1Rawb5j1D8HkEReSUF1hcRGFEFh6/imOKruoI34HvtbjwY9tkOueaAP9JD dDXU3hIHeDEJm4gpsojZnZJFVuLoYprWUsKZDRyFZVT0uk4fsnosQy/cvdesQoOifKkQ mfnZQexEQmifLjtY9D01rDzdtom4IZQJ7ub6xdZx1kC9JkSZWSmiPU7PKVcbZYkguk7y zVyVb89JBIkjk90SgK9Z4zKsI1K/hK70l4UunEUEkU+ijx/NbHdfafJl8kZQ32PQbIwG lI3wPuxAH+BiIzBgtkHYC+BCYH4rggBFh6fKrtcPkNyr68phBQ9rqlW3AY45JL017jsN 91yA== X-Gm-Message-State: ACrzQf3Tgze0yADPNgvPut1WjtUe4d0AjETcExygM+geTpsEOqXlDWvy QbIy3PQIjSPktB0e10D8ISXhFzUmdxQHadyNMQDhhIfaioQg3zO9Fzsqw2al3aqSO7pYrNPdHDY O+fo4Y8LtvvOO7oTmylKFdWeJOfHcjxEIlrxvZXWpwgHBBUDC90MN5bZxTFgNdnE= X-Google-Smtp-Source: AMsMyM4/izXnKMoyha9WC2hfpUsO1HtznfdpBMQohakKp2ObGizmFPmLW9xf5OP/+QlUjCz4ZoG7K1gtNNRknw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a0d:c087:0:b0:368:52a0:9173 with SMTP id b129-20020a0dc087000000b0036852a09173mr988065ywd.191.1667954847171; Tue, 08 Nov 2022 16:47:27 -0800 (PST) Date: Tue, 8 Nov 2022 16:47:05 -0800 In-Reply-To: <20221109004708.97668-1-chooglen@google.com> Mime-Version: 1.0 References: <20221109004708.97668-1-chooglen@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221109004708.97668-2-chooglen@google.com> Subject: [RFC PATCH 1/4] submodule--helper: teach --toplevel-cwd-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The top-level "--super-prefix" option (i.e. "git --super-prefix") is overloaded: - "git submodule--helper" passes the relative path between the top-level "git" process's cwd and the current repository - "git read-tree" passes the path from the root of top-level superproject's tree to the the current repository. In both cases, "--super-prefix" is only used to display meaningful paths from the superproject to a nested submodule. Let's address this overloading by breaking it up into its constituent use cases. Teach "git submodule--helper" the "--toplevel-cwd-prefix" option, which replaces its usage of "git --super-prefix". (A future patch will address the "git read-tree" use case.) This value is only used in builtin/submodule--helper.c, but it is stored in submodule.c, since it may be needed by other builtins in the future. When "--toplevel-cwd-prefix" is provided, paths to submodules in the working tree should be prefixed by it when they are printed, making the paths relative to the top-level process's cwd. This is the only way the prefix is used in "git submodule--helper", and all of its subcommands already conform to this behavior (even the ones that weren't marked SUPPORT_SUPER_PREFIX) because they all use get_submodule_displaypath() when printing paths to submodules. As such, we can say that all of "git submodule--helper" supports (and should continue to support) this flag, so we drop the constraint that "--toplevel-cwd-prefix" is only allowed for certain subcommands. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 52 +++++++++++++----------------- submodule.c | 26 ++++++++++++--- submodule.h | 10 ++++++ t/t7412-submodule-absorbgitdirs.sh | 13 ++++++-- 4 files changed, 64 insertions(+), 37 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c75e9e86b0..acb838e4d6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -115,18 +115,18 @@ 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) { - const char *super_prefix = get_super_prefix(); + const char *toplevel_cwd_prefix = get_toplevel_cwd_prefix(); - if (prefix && super_prefix) { - BUG("cannot have prefix '%s' and superprefix '%s'", - prefix, super_prefix); + if (prefix && toplevel_cwd_prefix) { + BUG("cannot have prefix '%s' and toplevel_cwd_prefix '%s'", + prefix, toplevel_cwd_prefix); } else if (prefix) { struct strbuf sb = STRBUF_INIT; char *displaypath = xstrdup(relative_path(path, prefix, &sb)); strbuf_release(&sb); return displaypath; - } else if (super_prefix) { - return xstrfmt("%s%s", super_prefix, path); + } else if (toplevel_cwd_prefix) { + return xstrfmt("%s%s", toplevel_cwd_prefix, path); } else { return xstrdup(path); } @@ -364,9 +364,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_pushl(&cpr.args, "submodule--helper", + "--toplevel-cwd-prefix", NULL); strvec_pushf(&cpr.args, "%s/", displaypath); - strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", + strvec_pushl(&cpr.args, "foreach", "--recursive", NULL); if (info->quiet) @@ -682,10 +683,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_pushl(&cpr.args, "submodule--helper", + "--toplevel-cwd-prefix", NULL); strvec_pushf(&cpr.args, "%s/", displaypath); - strvec_pushl(&cpr.args, "submodule--helper", "status", - "--recursive", NULL); + strvec_pushl(&cpr.args, "status", "--recursive", NULL); if (flags & OPT_CACHED) strvec_push(&cpr.args, "--cached"); @@ -1276,10 +1277,10 @@ 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_pushl(&cpr.args, "submodule--helper", + "--toplevel-cwd-prefix", NULL); strvec_pushf(&cpr.args, "%s/", displaypath); - strvec_pushl(&cpr.args, "submodule--helper", "sync", - "--recursive", NULL); + strvec_pushl(&cpr.args, "sync", "--recursive", NULL); if (flags & OPT_QUIET) strvec_push(&cpr.args, "--quiet"); @@ -2438,11 +2439,12 @@ static void update_data_to_args(const struct update_data *update_data, { enum submodule_update_type update_type = update_data->update_default; + strvec_push(args, "submodule--helper"); if (update_data->displaypath) { - strvec_push(args, "--super-prefix"); + strvec_push(args, "--toplevel-cwd-prefix"); strvec_pushf(args, "%s/", update_data->displaypath); } - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); + strvec_pushl(args, "update", "--recursive", NULL); strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->quiet) strvec_push(args, "--quiet"); @@ -3353,14 +3355,15 @@ 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 "), NULL }; struct option options[] = { + OPT_CALLBACK_F(0, "toplevel-cwd-prefix", NULL, "path", + "path from top level cwd to working tree root", + 0, option_parse_toplevel_cwd_prefix), OPT_SUBCOMMAND("clone", &fn, module_clone), OPT_SUBCOMMAND("add", &fn, module_add), OPT_SUBCOMMAND("update", &fn, module_update), @@ -3375,21 +3378,10 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) OPT_SUBCOMMAND("set-url", &fn, module_set_url), OPT_SUBCOMMAND("set-branch", &fn, module_set_branch), OPT_SUBCOMMAND("create-branch", &fn, module_create_branch), + OPT_END() }; argc = parse_options(argc, argv, prefix, options, usage, 0); - subcmd = argv[0]; - - if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - strcmp(subcmd, "foreach") && strcmp(subcmd, "status") && - strcmp(subcmd, "sync") && strcmp(subcmd, "absorbgitdirs") && - 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/submodule.c b/submodule.c index 8fa2ad457b..a6db8c4bbe 100644 --- a/submodule.c +++ b/submodule.c @@ -28,6 +28,7 @@ static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF; static int initialized_fetch_ref_tips; static struct oid_array ref_tips_before_fetch; static struct oid_array ref_tips_after_fetch; +static const char *toplevel_cwd_prefix; /* * Check if the .gitmodules file is unmerged. Parsing of the .gitmodules file @@ -241,6 +242,21 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt, return 0; } +int option_parse_toplevel_cwd_prefix(const struct option *opt, + const char *arg, int unset) +{ + if (arg) + toplevel_cwd_prefix = arg; + return 0; +} + +const char *get_toplevel_cwd_prefix(void) +{ + if (!toplevel_cwd_prefix) + return ""; + return toplevel_cwd_prefix; +} + /* * Determine if a submodule has been initialized at a given 'path' */ @@ -2298,7 +2314,7 @@ static void relocate_single_git_dir_into_superproject(const char *path) real_new_git_dir = real_pathdup(new_gitdir.buf, 1); fprintf(stderr, _("Migrating git directory of '%s%s' from\n'%s' to\n'%s'\n"), - get_super_prefix_or_empty(), path, + get_toplevel_cwd_prefix(), path, real_old_git_dir, real_new_git_dir); relocate_gitdir(path, real_old_git_dir, real_new_git_dir); @@ -2317,10 +2333,10 @@ 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_pushl(&cp.args, "submodule--helper", - "absorbgitdirs", NULL); + strvec_push(&cp.args, "submodule--helper"); + strvec_pushf(&cp.args, "--toplevel-cwd-prefix=%s%s/", + get_toplevel_cwd_prefix(), path); + strvec_pushl(&cp.args, "absorbgitdirs", NULL); prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) die(_("could not recurse into submodule '%s'"), path); diff --git a/submodule.h b/submodule.h index b52a4ff1e7..436dbb2e11 100644 --- a/submodule.h +++ b/submodule.h @@ -54,6 +54,16 @@ int git_default_submodule_config(const char *var, const char *value, void *cb); struct option; int option_parse_recurse_submodules_worktree_updater(const struct option *opt, const char *arg, int unset); +int option_parse_toplevel_cwd_prefix(const struct option *opt, + const char *arg, int unset); +/* + * Return the relative path of the top-level process's cwd to the root of the + * working tree. When printing paths to submodules in the working tree, this + * value should be prepended to the path so that they appear relative to the + * top-level process's cwd instead of this process's cwd. + */ +const char *get_toplevel_cwd_prefix(void); + int is_tree_submodule_active(struct repository *repo, const struct object_id *treeish_name, const char *path); diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 2859695c6d..a9efebc7ec 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -54,15 +54,24 @@ test_expect_success 'setup nested submodule' ' ' test_expect_success 'absorb the git dir in a nested submodule' ' + # Touch the files so that they show up in git status + >expect.err && + >actual.err && git status >expect.1 && git -C sub1/nested rev-parse HEAD >expect.2 && - git submodule absorbgitdirs && + git submodule absorbgitdirs 2>actual.err && test -f sub1/nested/.git && test -d .git/modules/sub1/modules/nested && git status >actual.1 && git -C sub1/nested rev-parse HEAD >actual.2 && test_cmp expect.1 actual.1 && - test_cmp expect.2 actual.2 + test_cmp expect.2 actual.2 && + cat >expect.err <<-EOF && + Migrating git directory of ${SQ}sub1/nested${SQ} from + ${SQ}/Users/chooglen/Code/git/t/trash directory.t7412-submodule-absorbgitdirs/sub1/nested/.git${SQ} to + ${SQ}/Users/chooglen/Code/git/t/trash directory.t7412-submodule-absorbgitdirs/.git/modules/sub1/modules/nested${SQ} + EOF + test_cmp expect.err actual.err ' test_expect_success 're-setup nested submodule' ' From patchwork Wed Nov 9 00:47:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 13037010 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 A75ECC4332F for ; Wed, 9 Nov 2022 00:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbiKIArh (ORCPT ); Tue, 8 Nov 2022 19:47:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbiKIArb (ORCPT ); Tue, 8 Nov 2022 19:47:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 009586315C for ; Tue, 8 Nov 2022 16:47:29 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id p66-20020a257445000000b006ca0ba7608fso15350545ybc.7 for ; Tue, 08 Nov 2022 16:47:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9TMBggvmsXLMnHqWqZzz73r2bD7xlZ6JG2FqfiLNAKo=; b=i5oFoQod0AccVnCxzx3oiHLCgoLQl2uPMK9zZRIg8cjqCOQawaDNEZFLoU6bRcY0rg hq+pvr3qONexRL/LH4WqHpZtEHjAGvfNjr//1waLh6OSgmbKPxb5EZp+YTa8jeLPwd40 d01euwpb/68x7xa3nx+cg0QDYkECy2Mu6YniHkiRRfbAlcx0MOD5dJK2OHtjQoczBC3X PZryUfJSI77fi3W+MJPZcU2f2KI1IWtMGBAE7nM6JnHgkmmxkhCSGohqC3TrZ0mza9O7 Sj+OGZvwxUc+sTLDn/8p5PRemALLyENy4Cb8oDiY6G7ey0rIA3hetaZLrhTSNEbz6Fuc d4QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9TMBggvmsXLMnHqWqZzz73r2bD7xlZ6JG2FqfiLNAKo=; b=oZ4VpZOnQyQdN7ecVnnhIbfC3bVHkC2vwm8HsZuGTyOG1Uec72xp634ygEESl0Nbni XzfnOBJ2od2974XZKlnQxtDlIuEtFXBvNjLT2XdCdHRxSTe04j4GZSEuit+V7a5v1iMm l0r4reVkbrrBR5s5unU9KsaHXycQRiG8GzfQnSFYqZZM1dow10g0lDsbYjfIFc94PD+6 eC8wG+B0qpl5LhWWBJ/J0DOfaBJkBcPh1er37gzRpHosUdk5vh11vStfG4xl3skNbJkc HewXVTC1AymLIZEZT/lBOeh3kkXKFKbs8Qm2CSrUAoc6LOPc8Eby8vHuii6Slxk/GXjt 4OCA== X-Gm-Message-State: ACrzQf3HjXMWWSZLyT3ojFU8U0rE/UZuICitQzgqwL9psWdSyCOGsq4s U5RmZmdSSfiwoWvqumQyHCBx19HuPj07r5mPb9kXwf1nN2ZFe8vad4pCO8TI4iAoe13XagNXP3X zbNxGtWEiy0tfJMUvosVCc7qMc6WBkQ1UmkQL3lkXqGCg3574VvJ4a9Ccet9JrBQ= X-Google-Smtp-Source: AMsMyM7pxhlqUtwi8bVr09bRWWLUWG2DYJifxKF0iYt5yQ7IFuQ5FysAC3ZzSf/Y1qKwyn0s0Us2O3HaBLZIPg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6902:110e:b0:66d:e6dc:5f31 with SMTP id o14-20020a056902110e00b0066de6dc5f31mr56683703ybu.628.1667954849087; Tue, 08 Nov 2022 16:47:29 -0800 (PST) Date: Tue, 8 Nov 2022 16:47:06 -0800 In-Reply-To: <20221109004708.97668-1-chooglen@google.com> Mime-Version: 1.0 References: <20221109004708.97668-1-chooglen@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221109004708.97668-3-chooglen@google.com> Subject: [RFC PATCH 2/4] fetch: refactor --submodule-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since "git fetch" learned to recurse into submodules [1], it has passed "--submodule-prefix=" to print full paths to the submodules being fetched. This is the same value as "--super-prefix"'s when calling "git read-tree --recurse-submodules", as well as "git (grep|ls-files) --recurse-submodules" before they were implemented in-process [2] [3], (when they used repository.submodule_prefix to replace "--super-prefix). Let's standardize the way we pass such prefixes. Having a per-command "--submodule-prefix" is preferable to a top-level "--super-prefix", since it gives us fine-grained control over which commands support it and which don't, and we can preserve the effort-saving properties of the top-level flag by sharing an implementation under the hood. Refactor "git fetch" so that "--submodule-prefix" is stored in repository.submodule_prefix, and create functions in submodule.h for parsing and reading its value. Also, mark it with PARSE_OPT_HIDDEN and drop it from our documentation. We will follow this pattern for "git read-tree" in the next commit. Since we've previously documented that repository.submodule_prefix is only set for submodules, introduce repository.is_submodule for distinguishing between the_repository and a submodule (although, this turns out to be unused, since no caller uses repository.submodule_prefix for that purpose). [1] 7dce19d374 (fetch/pull: Add the --recurse-submodules option, 2010-11-12) [2] 188dce131f (ls-files: use repository object, 2017-06-22) [3] f9ee2fcdfa (grep: recurse in-process using 'struct repository', 2017-08-02) Signed-off-by: Glen Choo --- Documentation/fetch-options.txt | 5 ----- builtin/fetch.c | 7 +++---- repository.c | 1 + repository.h | 9 +++++++-- submodule.c | 35 +++++++++++++++++++++------------ submodule.h | 12 +++++++++-- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 622bd84768..20cbd2c291 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 b06e454cbd..78a46389ff 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -74,7 +74,6 @@ 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 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 +194,9 @@ 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_CALLBACK_F(0, "submodule-prefix", NULL, "path", + "path from top-level superproject root to current repo root", + PARSE_OPT_HIDDEN, option_parse_submodule_prefix), OPT_CALLBACK_F(0, "recurse-submodules-default", &recurse_submodules_default, N_("on-demand"), N_("default for recursive fetching of submodules " @@ -2297,7 +2297,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) add_options_to_argv(&options); result = fetch_submodules(the_repository, &options, - submodule_prefix, recurse_submodules, recurse_submodules_default, verbosity < 0, diff --git a/repository.c b/repository.c index 5d166b692c..1d454a0ac4 100644 --- a/repository.c +++ b/repository.c @@ -229,6 +229,7 @@ int repo_submodule_init(struct repository *subrepo, } } + subrepo->is_submodule = 1; subrepo->submodule_prefix = xstrfmt("%s%s/", superproject->submodule_prefix ? superproject->submodule_prefix : diff --git a/repository.h b/repository.h index 24316ac944..1bc4afc2b6 100644 --- a/repository.h +++ b/repository.h @@ -119,10 +119,15 @@ struct repository { */ char *worktree; + /* + * Whether this struct represents a submodule of this process's main + * repository. + */ + int is_submodule; + /* * Path from the root of the top-level superproject down to this - * repository. This is only non-NULL if the repository is initialized - * as a submodule of another repository. + * repository. */ char *submodule_prefix; diff --git a/submodule.c b/submodule.c index a6db8c4bbe..d84345a0b4 100644 --- a/submodule.c +++ b/submodule.c @@ -257,6 +257,21 @@ const char *get_toplevel_cwd_prefix(void) return toplevel_cwd_prefix; } +int option_parse_submodule_prefix(const struct option *opt, + const char *arg, int unset) +{ + if (arg) + the_repository->submodule_prefix = xstrdup(arg); + return 0; +} + +const char *get_submodule_prefix(void) +{ + if (!the_repository->submodule_prefix) + return ""; + return the_repository->submodule_prefix; +} + /* * Determine if a submodule has been initialized at a given 'path' */ @@ -1392,7 +1407,6 @@ struct submodule_parallel_fetch { int changed_count; struct strvec args; struct repository *r; - const char *prefix; int command_line_option; int default_option; int quiet; @@ -1583,7 +1597,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); + get_submodule_prefix(), ce->name); spf->index_count++; return task; @@ -1645,7 +1659,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, + get_submodule_prefix(), task->sub->path, find_unique_abbrev(cs_data->super_oid, DEFAULT_ABBREV)); @@ -1692,8 +1706,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, task = get_fetch_task_from_changed(spf, err); if (task) { - struct strbuf submodule_prefix = STRBUF_INIT; - child_process_init(cp); cp->dir = task->repo->gitdir; prepare_submodule_repo_env_in_gitdir(&cp->env); @@ -1705,13 +1717,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, strvec_push(&cp->args, task->default_argv); strvec_push(&cp->args, "--submodule-prefix"); - strbuf_addf(&submodule_prefix, "%s%s/", - spf->prefix, - task->sub->path); - strvec_push(&cp->args, submodule_prefix.buf); + strvec_pushf(&cp->args, "%s%s/", + get_submodule_prefix(), + task->sub->path); *task_cb = task; - strbuf_release(&submodule_prefix); string_list_insert(&spf->seen_submodule_names, task->sub->name); return 1; } @@ -1723,7 +1733,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); + get_submodule_prefix(), task->sub->path); child_process_init(cp); prepare_submodule_repo_env_in_gitdir(&cp->env); @@ -1829,7 +1839,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, + int command_line_option, int default_option, int quiet, int max_parallel_jobs) { @@ -1851,7 +1861,6 @@ int fetch_submodules(struct repository *r, spf.command_line_option = command_line_option; spf.default_option = default_option; spf.quiet = quiet; - spf.prefix = prefix; if (!r->worktree) goto out; diff --git a/submodule.h b/submodule.h index 436dbb2e11..f2701c4869 100644 --- a/submodule.h +++ b/submodule.h @@ -55,7 +55,7 @@ struct option; int option_parse_recurse_submodules_worktree_updater(const struct option *opt, const char *arg, int unset); int option_parse_toplevel_cwd_prefix(const struct option *opt, - const char *arg, int unset); + const char *arg, int unset); /* * Return the relative path of the top-level process's cwd to the root of the * working tree. When printing paths to submodules in the working tree, this @@ -63,6 +63,15 @@ int option_parse_toplevel_cwd_prefix(const struct option *opt, * top-level process's cwd instead of this process's cwd. */ const char *get_toplevel_cwd_prefix(void); +int option_parse_submodule_prefix(const struct option *opt, + const char *arg, int unset); +/* + * Return the path from the root of the top-level superproject to root of this + * repository. When printing paths to submodules in a tree, this value should be + * prepended to the path so that they originate from the top-level + * superproject's tree instead of this repository's tree. + */ +const char *get_submodule_prefix(void); int is_tree_submodule_active(struct repository *repo, const struct object_id *treeish_name, @@ -100,7 +109,6 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce); void check_for_new_submodule_commits(struct object_id *oid); int fetch_submodules(struct repository *r, const struct strvec *options, - const char *prefix, int command_line_option, int default_option, int quiet, int max_parallel_jobs); From patchwork Wed Nov 9 00:47:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 13037011 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 2F684C4332F for ; Wed, 9 Nov 2022 00:47:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiKIArj (ORCPT ); Tue, 8 Nov 2022 19:47:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiKIArf (ORCPT ); Tue, 8 Nov 2022 19:47:35 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C5506317A for ; Tue, 8 Nov 2022 16:47:31 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id k15-20020a170902c40f00b001887cd71fe6so5833258plk.5 for ; Tue, 08 Nov 2022 16:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oeR4dEm7EC+Hi2MuKEGYUDm0GjsVRwESUlqokgrh6QA=; b=qwXGrUS8mdigMPxVhquX6BBREHgMbWT3NNlWNVIeVMRwotJVWhLaF/VV7t1HMP1o5N i4p8LPSwDDd8jqQvT+4J6Q/3oizVon4dux0gMSafq5EqboDkE0x/aj6UPHOrxBQd0G1r wNPDgbzjfz/Um9aP8pW/EKSd1PlVdJtNTfm4SzM2I1KZCHa1zoJWhghIjtsmAu2lulaS WbMk/h9zeAm0sCusMVZsEwprPba0riV1f8IkW+f0XYPbWdEcxZC2fJ4qGKZOT2fxU+yx 0EW7SRvgFlO9/TVRxwor9ZExcbqsN/W+V1aX5ZYLKwIrtLavLhIGK1N/wgmEMnukfypX eCyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oeR4dEm7EC+Hi2MuKEGYUDm0GjsVRwESUlqokgrh6QA=; b=A1cl6keyT8W4HmZYbU1UVUzmDt2ZrxbBGWb+dQAdVHbCKinb8gxhj5K6ZpjyQCHFLw XaMpnrwOBiglA9B2AuK0htn3dtX9r2+25Yq4cmY60ieTVG4Pfxse4dfS286verkcQm/Z q+0R3uvjUfyh9Z8zSh3qut1ox6tjLUOTCTYPKTSW1PMWw3b4f9TE9wAHzz6Xdh6UxT2u BxWhFsArQ3OpTlI1y5IVFTtapVkrCr7l+BpNRpqwBKMT90EOZ7JIsRs1rR+tp77RBbml o0uKSeQFCLHICvIXggV0eXfdQe4u7eHHH+6SCTsZIcIGYabIufP+Zyb3bgOnC9BUB1E7 Eezg== X-Gm-Message-State: ACrzQf3VSl027NUVA6fnv006s8sGeMuuBaXjraSj1KjnLxqQKq2rQ7B5 sDZMBK5gtljfWjEfO0I2RUS8DyIe1Fm5vkwBiLnurYkHJ+Z1jqBDimlyucWGj/rPYpLYumV6M4g unEEHtiPAIkXs1YwdqXFPG3IGjc+USlHSZ13ZK4Aan70MBMGij63KWDzNZO71Mww= X-Google-Smtp-Source: AMsMyM79nCjnmf39QYDlAON3hqg42IMBXlJZXSocB5VVrcgAWUmgD2LECcL3WUJqDfCatF4ykBXNEK5xUtcLeQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a62:be14:0:b0:56d:9eed:61eb with SMTP id l20-20020a62be14000000b0056d9eed61ebmr1097146pff.4.1667954850698; Tue, 08 Nov 2022 16:47:30 -0800 (PST) Date: Tue, 8 Nov 2022 16:47:07 -0800 In-Reply-To: <20221109004708.97668-1-chooglen@google.com> Mime-Version: 1.0 References: <20221109004708.97668-1-chooglen@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221109004708.97668-4-chooglen@google.com> Subject: [RFC PATCH 3/4] read-tree: teach --submodule-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Following the precedent of previous commit, teach "git read-tree" the "--submodule-prefix" flag, replacing its use of the global "--super-prefix" flag. This also fixes an existing bug where "git --super-prefix= read-tree" (typically invoked by "git restore") in a partial clone with submodules could fail because we fetch promisor objects with "git fetch", but "git fetch" doesn't support "--super-prefix". Signed-off-by: Glen Choo --- builtin/read-tree.c | 4 ++++ submodule.c | 22 +++++++------------ t/t1001-read-tree-m-2way.sh | 4 ++-- t/t5616-partial-clone.sh | 43 +++++++++++++++++++++++++++++++++++++ unpack-trees.c | 32 +++++++++++++-------------- 5 files changed, 73 insertions(+), 32 deletions(-) diff --git a/builtin/read-tree.c b/builtin/read-tree.c index f4cbe460b9..7aedab6951 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -148,6 +148,10 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) OPT_CALLBACK_F(0, "recurse-submodules", NULL, "checkout", "control recursive updating of submodules", PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater), + OPT_CALLBACK_F(0, "submodule-prefix", NULL, "path", + "internal, path from root of top-level superproject tree to this repo", + PARSE_OPT_HIDDEN, option_parse_submodule_prefix), + OPT__QUIET(&opts.quiet, N_("suppress feedback messages")), OPT_END() }; diff --git a/submodule.c b/submodule.c index d84345a0b4..d3d6abc816 100644 --- a/submodule.c +++ b/submodule.c @@ -2073,14 +2073,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; @@ -2108,10 +2100,11 @@ 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_push(&cp.args, "read-tree"); + strvec_pushf(&cp.args, "--submodule-prefix=%s%s/", + get_submodule_prefix(), path); + strvec_pushl(&cp.args, "-u", "--reset", NULL); strvec_push(&cp.args, empty_tree_oid_hex()); @@ -2191,9 +2184,10 @@ 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_push(&cp.args, "read-tree"); + strvec_pushf(&cp.args, "--submodule-prefix=%s%s/", + get_submodule_prefix(), path); + strvec_push(&cp.args, "--recurse-submodules"); if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) strvec_push(&cp.args, "-n"); diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 516a6112fd..9cfba1a2af 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -366,11 +366,11 @@ test_expect_success 'a/b (untracked) vs a, plus c/d case test.' ' test -f a/b ' -test_expect_success 'read-tree supports the super-prefix' ' +test_expect_success 'read-tree supports --submodule-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 --submodule-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 037941b95d..9bec57a047 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_success 'setup src repo with submodules' ' + test_config_global protocol.file.allow always && + + 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) && + + 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" +' + +test_expect_success 'lazy-fetch in submodule succeeds' ' + test_when_finished "rm -rf src-super src-sub client" && + + test_config_global protocol.file.allow always && + 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 diff --git a/unpack-trees.c b/unpack-trees.c index bae812156c..930a2a46f1 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 *submodule_prefixed(const char *path) { /* * It is necessary and sufficient to have two static buffers @@ -79,28 +79,28 @@ static const char *super_prefixed(const char *path) * error() using the unpack_*_errors[] templates we see above. */ static struct strbuf buf[2] = {STRBUF_INIT, STRBUF_INIT}; - static int super_prefix_len = -1; + static int submodule_prefix_len = -1; 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; + if (submodule_prefix_len < 0) { + const char *submodule_prefix = get_submodule_prefix(); + if (!submodule_prefix) { + submodule_prefix_len = 0; } else { int i; for (i = 0; i < ARRAY_SIZE(buf); i++) - strbuf_addstr(&buf[i], super_prefix); - super_prefix_len = buf[0].len; + strbuf_addstr(&buf[i], submodule_prefix); + submodule_prefix_len = buf[0].len; } } - if (!super_prefix_len) + if (!submodule_prefix_len) return path; if (++idx >= ARRAY_SIZE(buf)) idx = 0; - strbuf_setlen(&buf[idx], super_prefix_len); + strbuf_setlen(&buf[idx], submodule_prefix_len); strbuf_addstr(&buf[idx], path); return buf[idx].buf; @@ -236,7 +236,7 @@ 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), submodule_prefixed(path)); /* * Otherwise, insert in a list for future display by @@ -263,7 +263,7 @@ 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), submodule_prefixed(path.buf)); strbuf_release(&path); } string_list_clear(rejects, 0); @@ -290,7 +290,7 @@ 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), submodule_prefixed(path.buf)); strbuf_release(&path); } string_list_clear(rejects, 0); @@ -2958,8 +2958,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)); + submodule_prefixed(a->name), + submodule_prefixed(old->name)); if (!a) return keep_entry(old, o); else @@ -3020,7 +3020,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)); + submodule_prefixed(worktree->name)); return merged_entry(worktree ? worktree : untracked, NULL, o); } From patchwork Wed Nov 9 00:47:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 13037012 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 5E353C4332F for ; Wed, 9 Nov 2022 00:47:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbiKIAry (ORCPT ); Tue, 8 Nov 2022 19:47:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbiKIArf (ORCPT ); Tue, 8 Nov 2022 19:47:35 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90B7A627E1 for ; Tue, 8 Nov 2022 16:47:33 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id q62-20020a25d941000000b006cac1a4000cso15411304ybg.14 for ; Tue, 08 Nov 2022 16:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VeKu1cchG/zF3Aum8UkZ44ZUHzDLNKYFOqMsM2VsPlQ=; b=ryk5PDRvakKCaFUQxCkf5cZENUKwOSsrSG4jehHQ7b6ZOt0MUCJFtjxMlMC/PW1KvW xA56P6SPSF51HAnVHSA2jxK3y8+5q3VHfsQu8kilzrympVzlGARD8mBRBFOQJBPjv/4f SVFFncPPq9jnCDamYi9VOxoSdjkH3JZ4DteO+g+UpgCr2lACkOHMRHWbLDkgyKrdsX9x SrAiGrdvLAJOch1FI9clRAUGLeqSrtOciQV3ZqDLsh5Z1LeofdW5rRIj4lD1cCZozQIy 8FrAAxwr2MSrWnsw6oR3JQfOhbbD4hAkj7wtzUG7xsaXZOxIZSCC6MZAY4QVawnuPyvi YVRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VeKu1cchG/zF3Aum8UkZ44ZUHzDLNKYFOqMsM2VsPlQ=; b=ec58c/N6ZNPJBGSwX8vq5N3Escnpm3gCn3d4bpXcdGDmKXqmZGnZDJjdyGGdM4/2ql BUeq/L3wsojp+4u6aA9J9ZVb5fW3gZtNRCaHfP9wz8mOGD9zfKUr1hLau9Lzh4EA6i1d j98PE4lnUc1kaANkvBT1PB3jku5x1xE3ba6kXih0mjtwTyJbY8a3xsld34cepJrQeIgn 7KQWnap680qL9O38UAFRuUqzwWf3qYopiVCK8Lh6BFjfy2TLeYCGNUxiVh1DwrlYr9G5 b8f6/nZ5g1b4aeBp9HKx/ViPJsWOkoCIHQMGTIBHm8ATlJlTPEW+oDjFU/IhEYWUrXVm EQMg== X-Gm-Message-State: ACrzQf1fjMW/H2oWhMCWcH91TllwGf/iDNenKXOOxPIRjhKpDzUMLh4I gusgOaV6b2KRAYNxGdv1nxIe9iCDPfXL85NipNTYl61wNCAw5HgDtI9CTb4eF403aI4zJt3uvgH hTZw2sGQwP9au/M1uAhRWFgPO5laLGkmbilZ4AyQBCZSHwqh3+r8ne8SVdbKjt1k= X-Google-Smtp-Source: AMsMyM5JKQjifmVpmMnPIvj6ZOBtBzS9cI6Vzwq/CAj05EaiNa2cs5n24CEHNlfuuVCuhYaE8+X2mx8MasHs3Q== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a25:d609:0:b0:6ca:6c0c:9caa with SMTP id n9-20020a25d609000000b006ca6c0c9caamr58598586ybg.557.1667954852836; Tue, 08 Nov 2022 16:47:32 -0800 (PST) Date: Tue, 8 Nov 2022 16:47:08 -0800 In-Reply-To: <20221109004708.97668-1-chooglen@google.com> Mime-Version: 1.0 References: <20221109004708.97668-1-chooglen@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221109004708.97668-5-chooglen@google.com> Subject: [RFC PATCH 4/4] git: remove --super-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It has no more users, and prospective new users can use per-command flags instead, e.g. "git fetch --submodule-prefix" or "git submodule--helper --toplevel-cwd-prefix". Now that this flag is gone, also remove a now-defunct test from t/t7527-builtin-fsmonitor.sh. Signed-off-by: Glen Choo --- Documentation/git.txt | 7 +---- builtin.h | 4 --- cache.h | 2 -- environment.c | 13 ---------- git.c | 40 +++++------------------------ t/t7527-builtin-fsmonitor.sh | 50 ------------------------------------ 6 files changed, 8 insertions(+), 108 deletions(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index 1d33e083ab..85c7d9500e 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -13,7 +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 +169,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 8901a34d6b..8264b7e524 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/cache.h b/cache.h index 26ed03bd6d..a4a0377b80 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/environment.c b/environment.c index 18d042b467..1ee3686fd8 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 fb69e60591..5548619aea 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,7 +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==]\n" " []"); const char git_more_info_string[] = @@ -226,20 +225,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 +434,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 +484,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 }, @@ -539,7 +519,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 }, @@ -583,7 +563,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 }, @@ -610,7 +590,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 }, @@ -727,9 +707,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 +776,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(&args, "git"); diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh index 4abc74db2b..d11cb1854c 100755 --- a/t/t7527-builtin-fsmonitor.sh +++ b/t/t7527-builtin-fsmonitor.sh @@ -860,56 +860,6 @@ test_expect_success 'submodule always visited' ' my_match_and_clean ' -# If a submodule has a `sub/.git/` directory (rather than a file -# pointing to the super's `.git/modules/sub`) and `core.fsmonitor` -# turned on in the submodule and the daemon is not yet started in -# 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" -} - -test_expect_success "stray submodule super-prefix warning" ' - test_when_finished "rm -rf super; \ - rm -rf sub; \ - rm super-sub.trace" && - - create_super super && - create_sub sub && - - # Copy rather than submodule add so that we get a .git dir. - cp -R ./sub ./super/dir_1/dir_2/sub && - - git -C super/dir_1/dir_2/sub config core.fsmonitor true && - - git -C super submodule add ../sub ./dir_1/dir_2/sub && - git -C super commit -m "add sub" && - - 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 -' - # On a case-insensitive file system, confirm that the daemon # notices when the .git directory is moved/renamed/deleted # regardless of how it is spelled in the the FS event.