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

Re: [PATCH 2/2] submodule: port init from shell to C

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 18, 2016, 23:15 UTC
Message-ID
<xmqqmvqxehk6.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqmvqxg30y.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 17 quoted lines
>> +	strbuf_reset(&sb);
>> +	strbuf_addf(&sb, "submodule.%s.url", sub->name);
>> +	if (git_config_get_string(sb.buf, &url)) {
>> +		url = xstrdup(sub->url);
>> +		if (!url)
>> +			die(_("No url found for submodule path '%s' in .gitmodules"),
>> +				displaypath);
>
> I am assuming that this corresponds to these lines in the original
> scripted version:
>
> 		url=$(git config -f .gitmodules submodule."$name".url)
> 		test -z "$url" &&
> 		die "$(eval_gettext "No url found for submodule path...
>
> but what makes git_config_get_string() to read from ".gitmodules"
> file?  Doesn't it read from $GIT_DIR/config & ~/.gitconfig instead?

I am starting to suspect that reading of ".gitmodules" in the context of "git submodule" command is a good use case for the configset API. It wants to read variables from ".gitmodules" and the regular configuration file, and cares about where they come from, illustrated by this codepath. Read URL from .gitmodules, do something to it, and update the regular configuration file. Read Update from .gitmodules, do some verification, and selectively store it in the regular configuration file. There may be cases where you want to check if a variable is in the regular configuration file (i.e. read from there), see its value in ".gitmodules", and conditionally update the regular configuration file (i.e. write into it). The configset API was designed to help implement this kind of thing in a clean manner (i.e. initialize one, add ".gitmodules" file, and then configset_get_* on it, without affecting what you read and write with the regular config_get_*/config_set_* to the regular configuration file).

Previous: Junio C Hamano
Message 9 of 9 in “Port `git submodule init` from shell to C”
  1. 0/2 Port `git submodule init` from shell to CStefan Beller, Feb 12, 2016
  2. 1/2 submodule: port resolve_relative_url from shell to CStefan Beller, Feb 12, 2016
  3. Junio C HamanoFeb 18, 2016
  4. Duy NguyenFeb 27, 2016
  5. Johannes SixtMar 2, 2016
  6. Stefan BellerMar 2, 2016
  7. 2/2 submodule: port init from shell to CStefan Beller, Feb 12, 2016
  8. Junio C HamanoFeb 18, 2016
  9. Junio C HamanoFeb 18, 2016

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.