Re: [PATCH v3 1/2] submodule: prepare URL helpers for reuse
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 28, 2026, 03:38 UTC
- Message-ID
- <xmqq4id1zktq.fsf@gitster.g>
- In-Reply-To
- <fc300295ffaef49b592307a90ac3e58bb803b7ca.1795814853.git.gitgitgadget@gmail.com>
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 8 quoted lines
> From: Alessio Attilio <attilio.alessio@protonmail.com> > > 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.
Show 6 quoted lines
> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com> > --- > 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.<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?
Show 11 quoted lines
> 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.