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

Re: [PATCH 4/6] submodule--helper: improve logic for fallback remote name

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Jun 17, 2025, 17:53 UTC
Message-ID
<974293a0-6f5f-4077-9977-84c07fe431ca@intel.com>
In-Reply-To
<90B8957C-9469-4D46-9026-46407AD2EC1B@gmail.com>
On 6/16/2025 7:58 PM, Lidong Yan wrote:
Show 32 quoted lines
> Jacob Keller <jacob.e.keller@intel.com> writes:
>>
>> From: Jacob Keller <jacob.keller@gmail.com>
>>
>> The repo_get_default_remote() function in submodule--helper currently
>> tries to figure out the proper remote name to use for a submodule based
>> on a few factors.
>>
>> First, it tries to find the remote for the currently checked out branch.
>> This works if the submodule is configured to checkout to a branch
>> instead of a detached HEAD state.
>>
>> In the detached HEAD state, the code calls back to using "origin", on
>> the assumption that this is the default remote name. Some users may
>> change this, such as by setting clone.defaultRemoteName, or by changing
>> the remote name manually within the submodule repository.
>>
>> As a first step to improving this situation, refactor to reuse the logic
>> from remotes_remote_for_branch(). This function uses the remote from the
>> branch if it has one. If it doesn't then it checks to see if there is
>> exactly one remote. It uses this remote first before attempting to fall
>> back to "origin".
>>
>> To allow using this helper function, introduce a repo_default_remote()
>> helper to remote.c which takes a repository structure. This helper will
>> load the remote configuration and get the "HEAD" branch. Then it will
>> call remotes_remote_for_branch to find the default remote.
> 
> Just a thought: since repo_default_remote() is only used within
> repo_get_default_remote(), and the two have very similar names,
> do you think it might be clearer to inline the former into the latter?
> 

Probably, but I can't inline it within submodule--helper.c because it needs access to static functions in remote.c which I don't think make sense to export.

I could also either move repo_get_default_remote() from submodule--helper.c into remote.c, or try to eliminate it entirely.

My original thought was that it does some submodule-specific checks which I don't want to remove but which don't seem to make sense in-context with how the other remote.c helpers were implemented. Thus, it didn't make sense to move it into remote.c, but I can't put repo_default_remote() contents into submodule--helper.c without exposing the read_config() and other static functions in remote.c

I'll think about this while resolving the memory issues and working on the next version.

Previous: Lidong YanNext: Jacob Keller
Message 7 of 17 in “submodule: improve remote lookup logic”
  1. 0/6 submodule: improve remote lookup logicJacob Keller, Jun 11, 2025
  2. 1/6 dir: move starts_with_dot(_dot)_slash to dir.hJacob Keller, Jun 11, 2025
  3. 2/6 remote: remove the_repository from some functionsJacob Keller, Jun 11, 2025
  4. 3/6 remote: check branch->merge before access in branch_releaseJacob Keller, Jun 11, 2025
  5. 4/6 submodule--helper: improve logic for fallback remote nameJacob Keller, Jun 11, 2025
  6. Lidong YanJun 17, 2025
  7. Jacob KellerJun 17, 2025
  8. Jacob KellerJun 17, 2025
  9. Junio C HamanoJun 17, 2025
  10. 5/6 submodule: move get_default_remote_submodule()Jacob Keller, Jun 11, 2025
  11. 6/6 submodule: look up remotes by URL firstJacob Keller, Jun 11, 2025
  12. Jacob KellerJun 16, 2025
  13. Junio C HamanoJun 16, 2025
  14. Jacob KellerJun 16, 2025
  15. Junio C HamanoJun 17, 2025
  16. Junio C HamanoJun 17, 2025
  17. Jacob KellerJun 17, 2025

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.