From: Junio C Hamano Date: Sat, 28 Nov 2026 03:38:57 GMT Subject: Re: [PATCH v3 1/2] submodule: prepare URL helpers for reuse Message-ID: In-Reply-To: "Alessio Attilio via GitGitGadget" writes: > 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 so they can be shared with git status. > > Pass the repository explicitly to the resolver instead of relying on > the_repository, and update existing callers to use the shared helpers. This preparatory extraction may make the next patch easier to read. Removing the get_default_remote() wrapper that has only one caller, and calling repo_default_remote(repo) directly is safe too, because repo_default_remote() returns a pointer owned by repo->remote_state (or a static "origin" string) and repo_config_get_string() does not invalidate remote_state before relative_url() runs. > Signed-off-by: Alessio Attilio > --- > builtin/submodule--helper.c | 63 ++++++------------------------------- > submodule.c | 41 ++++++++++++++++++++++++ > submodule.h | 3 ++ > 3 files changed, 54 insertions(+), 53 deletions(-) While this takes 'repo', the fallback when remote..url is unset still calls xgetcwd(). For current callers ('submodule--helper' and 'git status' under RUN_SETUP | NEED_WORK_TREE), the working directory is already the superproject worktree root, so behavior is preserved. Still, if a future caller passes a 'struct repository *' for another worktree or subrepository, xgetcwd() will resolve relative URLs against the process working directory instead of repo->worktree. Using remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd(); may make the helper genuinely repository-aware, perhaps? In any case, the "repository-aware" change should be a separate step, outside the "move code around" step, right? > diff --git a/submodule.h b/submodule.h > index 1a465a1208..2028f272c4 100644 > --- a/submodule.h > +++ b/submodule.h > @@ -62,6 +62,9 @@ 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(struct repository *repo, const char *url, > + const char *up_path, int quiet); > +char *get_submodule_up_path(const char *path); The header names the second parameter 'url', while the definition in submodule.c names it 'rel_url'. It would help to add comments above the declarations of these two functions and to document that callers free the returned string, that 'up_path' may be NULL, and that get_submodule_up_path() expects a non-empty 'path' (because it indexes path[strlen(path) - 1]). It would match the surrounding declarations in this header file.