git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Lidong Yan <yldhome2d2@gmail.com>
Cc: <git@vger.kernel.org>, Jacob Keller <jacob.keller@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH 4/6] submodule--helper: improve logic for fallback remote name
Date: Tue, 17 Jun 2025 11:57:13 -0700	[thread overview]
Message-ID: <4773e9a4-778d-453f-93b0-cf37a660145e@intel.com> (raw)
In-Reply-To: <90B8957C-9469-4D46-9026-46407AD2EC1B@gmail.com>



On 6/16/2025 7:58 PM, Lidong Yan wrote:
> 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?
> 
I will try to rename this function, but I think in context it makes
sense to keep a separate function in remote.c which does the generic-ish
stuff while the submodule--helper.c function does the submodule-specific
stuff. This is because the later patches add the URL look up support to
this function.

  parent reply	other threads:[~2025-06-17 18:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11  0:52 [PATCH 0/6] submodule: improve remote lookup logic Jacob Keller
2025-06-11  0:52 ` [PATCH 1/6] dir: move starts_with_dot(_dot)_slash to dir.h Jacob Keller
2025-06-11  0:52 ` [PATCH 2/6] remote: remove the_repository from some functions Jacob Keller
2025-06-11  0:52 ` [PATCH 3/6] remote: check branch->merge before access in branch_release Jacob Keller
2025-06-11  0:52 ` [PATCH 4/6] submodule--helper: improve logic for fallback remote name Jacob Keller
2025-06-17  2:58   ` Lidong Yan
2025-06-17 17:53     ` Jacob Keller
2025-06-17 18:57     ` Jacob Keller [this message]
2025-06-17 13:30   ` Junio C Hamano
2025-06-11  0:52 ` [PATCH 5/6] submodule: move get_default_remote_submodule() Jacob Keller
2025-06-11  0:52 ` [PATCH 6/6] submodule: look up remotes by URL first Jacob Keller
2025-06-16 22:27 ` [PATCH 0/6] submodule: improve remote lookup logic Jacob Keller
2025-06-16 22:41   ` Junio C Hamano
2025-06-16 23:20     ` Jacob Keller
2025-06-17 15:09       ` Junio C Hamano
2025-06-17 16:16         ` Junio C Hamano
2025-06-17 21:28         ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4773e9a4-778d-453f-93b0-cf37a660145e@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    --cc=ps@pks.im \
    --cc=yldhome2d2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).