From patchwork Thu Dec 15 09:32:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13074011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A2E2C4167B for ; Thu, 15 Dec 2022 09:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiLOJdl (ORCPT ); Thu, 15 Dec 2022 04:33:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230062AbiLOJdI (ORCPT ); Thu, 15 Dec 2022 04:33:08 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0262952163 for ; Thu, 15 Dec 2022 01:33:05 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id bj12so50801582ejb.13 for ; Thu, 15 Dec 2022 01:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HFppIDdO87weoCISXro5Z+EDPmdDKox592Gp0qF2F2A=; b=G06MfAXPcBqeUqigdfCshoPPZPHN7bvEkyIuuhLYPC4m2uOA3m514rRObGjipRbvzu coOmhYI1NMe6mSCNPk9Q4dqiutJrqD398feHNSoJXbVHZvDQkp4tmkq0KY9zhD/U6Aif VDsV8xqSeAqhezzcsWMXeg9BQrNNTnbpnEWXQrxTrY0mWGEHulykYNMGBqPtZc29oz6e DI/iePQsqWVmgDztBOlQzI8Lg+hKzmmj9cyhXEAyPmqEEbb6z59yOMUs5tjYkK7qbYk7 sO7ZFoPdP66SsOXDpfkNFLRYQJJyGgO02EGTmP5H5Crh5q6QyoNW/F81KjzFHi21x4Qw PGBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HFppIDdO87weoCISXro5Z+EDPmdDKox592Gp0qF2F2A=; b=MUE8AT7Xq8DLSYpDwl2OG93wos6P0tIrtCVkAQxY4aI00q+YhNe8T1toyU4TnvBZIY 2Gsfn217SIAgj5uuMznuPSm1cYFlZjK6Sm9cXi4bPjdFFZ0p4yk6U//AnCgUafwN8ugg djrU88EQXY4OnGwNNCS4vUEkstYQps+nzvFMRVIupM2F9pJraoUruRDKAw89cDsP89Ii uaElRVJsPdmGkz2VZNlbVgiW+5cUylRTZeyiAGdPT6JmLmupykdE8zgRi3f12knOqFBp /V/q3DFJBnv9/nHiiYzuUTT9fsB1ZW1jEB/MXT5YG7Sf6W38QEuUE3TincDhFT+o92U2 EDxw== X-Gm-Message-State: ANoB5pmhhpl3sIWvymDa37Ua6O1vg/cGRDL3pFEXHx6eJQS0qhuBEdsD 2SwpJVtKVx1AFZ4/zF2B/nOp7DGPtmALcQ== X-Google-Smtp-Source: AA0mqf4TZXypMyLpwGyvPFApCICdMf3J5+t5ng7LHpprEagPvXFu55iSc8IlWdxaxhcheQoB54AYeQ== X-Received: by 2002:a17:906:34c5:b0:7ae:e886:8ccb with SMTP id h5-20020a17090634c500b007aee8868ccbmr33294245ejb.14.1671096784454; Thu, 15 Dec 2022 01:33:04 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id 1-20020a170906210100b007c1675d2626sm5457702ejt.96.2022.12.15.01.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:33:03 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Taylor Blau , Robert Coup , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v4 8/9] submodule--helper: convert "{update,clone}" to their own "--super-prefix" Date: Thu, 15 Dec 2022 10:32:49 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with a preceding commit to convert "absorbgitdirs", we can convert "submodule--helper status" to use its own "--super-prefix", instead of relying on the global "--super-prefix" argument to "git". We need to convert both of these away from the global "--super-prefix" at the same time, because "update" will call "clone", but "clone" itself didn't make use of the global "--super-prefix" for displaying paths. It was only on the list of sub-commands that accepted it because "update"'s use of it would set it in its environment. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 32 +++++++++++++------------------- git.c | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 448896f1b1d..a0aa4635a0c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -437,11 +437,13 @@ static int starts_with_dot_dot_slash(const char *const path) struct init_cb { const char *prefix; + const char *super_prefix; unsigned int flags; }; #define INIT_CB_INIT { 0 } static void init_submodule(const char *path, const char *prefix, + const char *super_prefix, unsigned int flags) { const struct submodule *sub; @@ -449,8 +451,7 @@ static void init_submodule(const char *path, const char *prefix, const char *upd; char *url = NULL, *displaypath; - displaypath = get_submodule_displaypath(path, prefix, - get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix, super_prefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -526,7 +527,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data { struct init_cb *info = cb_data; - init_submodule(list_item->name, info->prefix, info->flags); + init_submodule(list_item->name, info->prefix, info->super_prefix, + info->flags); } static int module_init(int argc, const char **argv, const char *prefix) @@ -792,6 +794,7 @@ struct summary_cb { int argc; const char **argv; const char *prefix; + const char *super_prefix; unsigned int cached: 1; unsigned int for_status: 1; unsigned int files: 1; @@ -954,7 +957,7 @@ static void generate_submodule_summary(struct summary_cb *info, } displaypath = get_submodule_displaypath(p->sm_path, info->prefix, - get_super_prefix()); + info->super_prefix); if (!missing_src && !missing_dst) { struct child_process cp_rev_list = CHILD_PROCESS_INIT; @@ -1893,6 +1896,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc) struct update_data { const char *prefix; + const char *super_prefix; char *displaypath; enum submodule_update_type update_default; struct object_id suboid; @@ -1969,7 +1973,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, char *key; const struct update_data *ud = suc->update_data; char *displaypath = get_submodule_displaypath(ce->name, ud->prefix, - get_super_prefix()); + ud->super_prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; int need_free_url = 0; @@ -2449,11 +2453,11 @@ static void update_data_to_args(const struct update_data *update_data, { enum submodule_update_type update_type = update_data->update_default; + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); if (update_data->displaypath) { strvec_push(args, "--super-prefix"); strvec_pushf(args, "%s/", update_data->displaypath); } - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->quiet) strvec_push(args, "--quiet"); @@ -2620,7 +2624,7 @@ static int update_submodules(struct update_data *update_data) update_data->displaypath = get_submodule_displaypath( update_data->sm_path, update_data->prefix, - get_super_prefix()); + update_data->super_prefix); code = update_submodule(update_data); FREE_AND_NULL(update_data->displaypath); fail: @@ -2646,6 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix) LIST_OBJECTS_FILTER_INIT; int ret; struct option module_update_options[] = { + OPT__SUPER_PREFIX(&opt.super_prefix), OPT__FORCE(&opt.force, N_("force checkout updates"), 0), OPT_BOOL(0, "init", &opt.init, N_("initialize uninitialized submodules before update")), @@ -2742,6 +2747,7 @@ static int module_update(int argc, const char **argv, const char *prefix) module_list_active(&list); info.prefix = opt.prefix; + info.super_prefix = opt.super_prefix; if (opt.quiet) info.flags |= OPT_QUIET; @@ -3368,8 +3374,6 @@ static int module_add(int argc, const char **argv, const char *prefix) int cmd_submodule__helper(int argc, const char **argv, const char *prefix) { - const char *cmd = argv[0]; - const char *subcmd; parse_opt_subcommand_fn *fn = NULL; const char *const usage[] = { N_("git submodule--helper "), @@ -3393,16 +3397,6 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix) OPT_END() }; argc = parse_options(argc, argv, prefix, options, usage, 0); - subcmd = argv[0]; - - if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && - get_super_prefix()) - /* - * xstrfmt() rather than "%s %s" to keep the translated - * string identical to git.c's. - */ - die(_("%s doesn't support --super-prefix"), - xstrfmt("'%s %s'", cmd, subcmd)); return fn(argc, argv, prefix); } diff --git a/git.c b/git.c index e473b4b7d72..2c31ba27040 100644 --- a/git.c +++ b/git.c @@ -610,7 +610,7 @@ static struct cmd_struct commands[] = { { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, - { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX }, + { "submodule--helper", cmd_submodule__helper, RUN_SETUP }, { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },