From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795884827; b=nzd3y4rkvCkE4P1km+WFwXHmhCMsAzeNGga+1fB63/GVBSbrupfAHnlLXTw46urEHiO9 ydis0TWV+UPzxqsljmvOGfwfbRHLx/NgoNXHrIAbY2aErKNxt1S0FYm/hU4k6TGkJ/1N9 eE7lGAHOlTVv/kRIxDEs9QrmBa9i50KnXJk4FsYoCqxuHcs8XAwtj+Cs8yd0L/ZcZONHm Lm9U0tD+Scwdwzpk73sptniwvTeBCcR6yQERm7CsXBWTArYMaKBDgSOUYJGr/1r6XSfol wOUGLvwieRxL9fit+8XSpcBKZF7MgKbtr1+i3cDbfmffyR8noaaUXMNAaAG1TkxUWLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795884827; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=uKcHDccZQh/dh7KFrYVszI0Wo66iZsj7jD5MeNaTDv8=; b=j08EGkCW+EjOEha1g/169p/Z94L+esKrzjdvRm/DIAxjCKFDnvWAhnZtgwz46o//gsPh 5zlbf+HCLi/lSfyk59n21ryxmaXr4N4Aph6GNLLxqR/Cz7GbaVJha14YxxADRBR27Dqh7 NDsaXyAWUpHVrJ+ujnixCHIPkSFrsYW51js5ihK/Zybu3XDBPOUb7lajzkcnst3F8VDrb FnNq5yAoPRjdjsiQ0NQhy8zcx4iXlVOHwLL/FqyKJWirwoB5h1q2jPqQbs67OcZTmaN1g 8LycSY05KfRHBcEMWps+es6tq7FoUE/98TCdNw53p6Kx/k4F2NOSrWmcWcvdGijSb+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=IELze8F4; arc=none smtp.remote-ip=74.125.224.54 Received: from mail-yx1-f54.google.com (mail-yx1-f54.google.com [74.125.224.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CEFF606A32C for ; Sat, 28 Nov 2026 16:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CEFF606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=IELze8F4 Received: by mail-yx1-f54.google.com with SMTP id 956f58d0204a3-67da564d9f2so11611452d50.1 for ; Sat, 28 Nov 2026 08:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795884826; x=1796489626; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=uKcHDccZQh/dh7KFrYVszI0Wo66iZsj7jD5MeNaTDv8=; b=IELze8F4hM7MPbhidXilLGLqHm3GO3Lwbeh2IIY/rvNk1q+LsTOb2yHg2h+SMgMuaX jROSoc8hEaIsMKuWRhTMtfO3Q8KDWGMKlWrov9EDr71C5DMnNDR/8NLHGSxxxMU0Vgdr L/JNhyU0NNI8x3SXoY41Mqhd3xUjg+dqLtz57gkS5cT5ST+59aQhL9VhK5yR6AhNWUu1 UkX6Jfzd+VRzXU/iOBxFBVIdfknyxHaE5CzaFMEv+/NazwmCVCNO2TXM5kvw3LaITmyj Eu/W7m37JQuVXv6Mme8JYASh86wg1cWIYa6RXTUB4EEyeQbnlZI/3agfEeuY3n7KVYPV Accg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795884826; x=1796489626; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uKcHDccZQh/dh7KFrYVszI0Wo66iZsj7jD5MeNaTDv8=; b=DnAhyRLz8TtyMHTsVCZ7zV6oWoYdx1ByA3nnSrUP7KXwixvuC6U/u7l9ICDQpIyeds 05LyclTyRtm/yqdJYnALt45hPJikY1TDszJ/BdQx0QKaCHLf8ak4pyPpMI5R6XXwGcbn f5Mf2uwU8KJc+1qmpQC+4tEeUEGrC7lIvdLJKRbUECnmKghXspsTkcBtQll09J8rKykY s61PeG7wISujUXkrGya6cIV37hXivZR9YsXjnHNIopcCzHKwn2kdX4Z5yhSIWt9qwa3s 87H+oA713kgfUNqxpsZnSclf6eSJBGFRc8ox3/Mo8dBot8ZRO83jTVCg9nOYrpF1yVFc XaVw== X-Gm-Message-State: APuU4Z/gB3fMTWxcfan/WRxnSVXPgfF9dlTljbkC7+Hs/SNj0modbqc+ /BQ7qrGzIQValH16dhdb02L2MwUiAgxNkwZTbvIygyjxgcpkzNninjH1LxVB3VGL X-Gm-Gg: AZFdTZd9l+zG0TYGBn0dfXPTd1AWwCVxMaFMitWgDuvu2M8E3a67Ld9d5tmrFT5b8w/ CzlCMtgngI08wIssUWROlB2kZWFCET2aXz+bFglHt/DKNbkaFe2H3bNRFA4zf7OnedxQSNAMtxx cmtL0ko2Jqe9PCdKVVP8RVVN3saEBEkCVVfeZCknh+yZBsChPYic3RMZEtFg1a3UvuotWqm+v4g 1JZrp8/b+NB2GxVO8oai0lk1A3++CEDyOzePQQR47YhpUA7x/GDBKb+XCsq6eVYT/NwSCznuhMC b5aCn9R5V/BC1mZgusuA8I0a7uHxb4WaPj5doPMw1Eg3peRyULFPY1iracDTpMJ6/SvejKpRJUT xTqsf+SFbEbjo5pa5ptm5Cm3q2NI3S8p/iAo0vm2DAnDc5mIyrUmmcMqOG/4/Exw1oF3C9rjNbV hZwTFCkID5uPL60JztqgJtYZ7ESPWdxfvXk5jfpCiaO/FYLYB2LQwDjbi4ennx4p0ple6smlhvE AS63OZ1JWJDT9pRnD5KHJNjDHmhGRB4T9HyF8mj2+k7ZI7bZYohTSFahn9+H5XgkVmuKT9RSzEd pct1SzONL7v+pVjob2nJZyVnzsHx+BqtkQ== X-Received: by 2002:a05:690e:400c:b0:67d:e6f2:bd03 with SMTP id 956f58d0204a3-67df445191emr12273745d50.68.1795884826345; Sat, 28 Nov 2026 08:53:46 -0800 (PST) Received: from [127.0.0.1] ([134.138.59.129]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df3353258sm13081780d50.9.2026.11.28.08.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 08:53:45 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alessio Attilio via GitGitGadget" Date: Sat, 28 Nov 2026 16:53:40 +0000 Subject: [PATCH v4 1/3] submodule: move URL helpers into submodule.c Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alessio Attilio , Alessio Attilio From: Alessio Attilio Move the relative submodule URL resolver and the helper that computes the path back to the superproject from builtin/submodule--helper.c to submodule.c. This lets other callers reuse the helpers. Return non-relative URLs unchanged before consulting remote configuration, so the resolver handles every URL form itself. Keep the repository parameter change for the next patch. Signed-off-by: Alessio Attilio --- builtin/submodule--helper.c | 60 +++++-------------------------------- submodule.c | 50 +++++++++++++++++++++++++++++++ submodule.h | 2 ++ 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 461b682d0d..cc84968bd3 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -46,35 +46,6 @@ typedef void (*each_submodule_fn)(const struct cache_entry *list_item, void *cb_data); -static char *get_default_remote(void) -{ - return xstrdup(repo_default_remote(the_repository)); -} - -static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet) -{ - char *remoteurl, *resolved_url; - char *remote = get_default_remote(); - struct strbuf remotesb = STRBUF_INIT; - - strbuf_addf(&remotesb, "remote.%s.url", remote); - if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) { - if (!quiet) - warning(_("could not look up configuration '%s'. " - "Assuming this repository is its own " - "authoritative upstream."), - remotesb.buf); - remoteurl = xgetcwd(); - } - resolved_url = relative_url(remoteurl, rel_url, up_path); - - free(remote); - free(remoteurl); - strbuf_release(&remotesb); - - return resolved_url; -} - static int get_default_remote_submodule(const char *module_path, char **default_remote) { const struct submodule *sub; @@ -92,7 +63,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_ starts_with_dot_slash(url)) { char *oldurl = url; - url = resolve_relative_url(oldurl, NULL, 1); + url = resolve_submodule_url(oldurl, NULL, 1); free(oldurl); } } @@ -290,23 +261,6 @@ static void module_list_active(struct module_list *list) *list = active_modules; } -static char *get_up_path(const char *path) -{ - struct strbuf sb = STRBUF_INIT; - - strbuf_addstrings(&sb, "../", count_slashes(path)); - - /* - * Check if 'path' ends with slash or not - * for having the same output for dir/sub_dir - * and dir/sub_dir/ - */ - if (!is_dir_sep(path[strlen(path) - 1])) - strbuf_addstr(&sb, "../"); - - return strbuf_detach(&sb, NULL); -} - static void for_each_listed_submodule(const struct module_list *list, each_submodule_fn fn, void *cb_data) { @@ -623,7 +577,7 @@ static void init_submodule(const char *path, const char *prefix, starts_with_dot_slash(url)) { char *oldurl = url; - url = resolve_relative_url(oldurl, NULL, 0); + url = resolve_submodule_url(oldurl, NULL, 0); free(oldurl); } @@ -1453,10 +1407,10 @@ static void sync_submodule(const char *path, const char *prefix, if (sub && sub->url) { if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) { - char *up_path = get_up_path(path); + char *up_path = get_submodule_up_path(path); - sub_origin_url = resolve_relative_url(sub->url, up_path, 1); - super_config_url = resolve_relative_url(sub->url, NULL, 1); + sub_origin_url = resolve_submodule_url(sub->url, up_path, 1); + super_config_url = resolve_submodule_url(sub->url, NULL, 1); free(up_path); } else { sub_origin_url = xstrdup(sub->url); @@ -2334,7 +2288,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) { if (sub->url && (starts_with_dot_slash(sub->url) || starts_with_dot_dot_slash(sub->url))) { - url = resolve_relative_url(sub->url, NULL, 0); + url = resolve_submodule_url(sub->url, NULL, 0); need_free_url = 1; } else url = sub->url; @@ -3761,7 +3715,7 @@ static int module_add(int argc, const char **argv, const char *prefix, "of the working tree")); /* dereference source url relative to parent's url */ - to_free = resolve_relative_url(add_data.repo, NULL, 1); + to_free = resolve_submodule_url(add_data.repo, NULL, 1); add_data.realrepo = to_free; } else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) { add_data.realrepo = add_data.repo; diff --git a/submodule.c b/submodule.c index a74d1925aa..9b7bb5c2f3 100644 --- a/submodule.c +++ b/submodule.c @@ -292,6 +292,56 @@ int is_submodule_active(struct repository *repo, const char *path) return is_tree_submodule_active(repo, null_oid(the_hash_algo), path); } +static char *get_default_remote(void) +{ + return xstrdup(repo_default_remote(the_repository)); +} + +char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet) +{ + char *remoteurl, *resolved_url; + char *remote; + struct strbuf remotesb = STRBUF_INIT; + + if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url)) + return xstrdup(rel_url); + + remote = get_default_remote(); + strbuf_addf(&remotesb, "remote.%s.url", remote); + if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) { + if (!quiet) + warning(_("could not look up configuration '%s'. " + "Assuming this repository is its own " + "authoritative upstream."), + remotesb.buf); + remoteurl = xgetcwd(); + } + resolved_url = relative_url(remoteurl, rel_url, up_path); + + free(remote); + free(remoteurl); + strbuf_release(&remotesb); + + return resolved_url; +} + +char *get_submodule_up_path(const char *path) +{ + struct strbuf sb = STRBUF_INIT; + + strbuf_addstrings(&sb, "../", count_slashes(path)); + + /* + * Check if 'path' ends with slash or not + * for having the same output for dir/sub_dir + * and dir/sub_dir/ + */ + if (!is_dir_sep(path[strlen(path) - 1])) + strbuf_addstr(&sb, "../"); + + return strbuf_detach(&sb, NULL); +} + int is_submodule_populated_gently(const char *path, int *return_error_code) { int ret = 0; diff --git a/submodule.h b/submodule.h index 1a465a1208..82972781b4 100644 --- a/submodule.h +++ b/submodule.h @@ -62,6 +62,8 @@ int is_tree_submodule_active(struct repository *repo, const struct object_id *treeish_name, const char *path); int is_submodule_active(struct repository *repo, const char *path); +char *resolve_submodule_url(const char *url, const char *up_path, int quiet); +char *get_submodule_up_path(const char *path); /* * Determine if a submodule has been populated at a given 'path' by checking if * the /.git resolves to a valid git repository. -- gitgitgadget