git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Alessio Attilio via GitGitGadgetNext: Alessio Attilio via GitGitGadget
Message 11 of 26 in “status: warn about stale submodule URLs”
  1. status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  2. D. Ben KnobleNov 27, 2026
  3. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  4. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  5. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  6. Junio C HamanoNov 27, 2026
  7. ATTILIO ALESSIONov 27, 2026
  8. D. Ben KnobleNov 30, 2026
  9. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  10. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  11. Junio C HamanoNov 28, 2026
  12. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  13. Junio C HamanoNov 28, 2026
  14. Junio C HamanoNov 28, 2026
  15. 0/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  16. 1/3 submodule: move URL helpers into submodule.cAlessio Attilio via GitGitGadget, Nov 28, 2026
  17. D. Ben KnobleNov 30, 2026
  18. 2/3 submodule: make URL resolution repository-awareAlessio Attilio via GitGitGadget, Nov 28, 2026
  19. D. Ben KnobleNov 30, 2026
  20. 3/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  21. Junio C HamanoNov 29, 2026
  22. 0/4 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Dec 1, 2026
  23. 1/4 submodule: share repository-aware URL resolutionAlessio Attilio via GitGitGadget, Dec 1, 2026
  24. 2/4 status: warn about submodule URL mismatchesAlessio Attilio via GitGitGadget, Dec 1, 2026
  25. 3/4 status: preserve customized submodule remotesAlessio Attilio via GitGitGadget, Dec 1, 2026
  26. 4/4 status: test submodule URL warningsAlessio Attilio via GitGitGadget, Dec 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.