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

Re: [PATCH v1 2/3] config: introduce repo_config_set* functions

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 11, 2021, 20:24 UTC
Message-ID
<xmqq7ddel9te.fsf@gitster.g>
In-Reply-To
<20211111171643.13805-3-chooglen@google.com>
Glen Choo <chooglen@google.com> writes:
Show 12 quoted lines
> We have git_config_set() that sets a config value for the_repository's
> config file, and repo_config_get* that reads config values from a struct
> repository. Thus, it seems reasonable to have to have
> repo_git_config_set() that can set values for a config file of a struct
> repository.
>
> Implement repo_config_set() and repo_config_set_gently(), which
> take struct repository. However, unlike other instances where struct
> repository is added to a repo_* function, this patch does not change the
> implementations of git_config_set() or git_config_set_gently(); those
> functions use the_repository much deeper in their call chain through
> git_pathdup(). Mark this inconsistency as NEEDSWORK.

Being able to only affect "config" in the_repository->gitdir is less flexible than being able to affect "config" in repo->gitdir for any repository is good. Do we need a similar thing for repo->commondir as well?

Show 23 quoted lines
> +/*
> + * Sets a config value in a repository.
> + */
> +int repo_config_set_gently(struct repository *r, const char *key,
> +			   const char *value)
> +{
> +	int ret;
> +	char *path;
> +
> +	path = repo_git_path(r, "config");
> +	ret = git_config_set_in_file_gently(path, key, value);
> +	free(path);
> +	return ret;
> +}
> +
> +void repo_config_set(struct repository *r, const char *key, const char *value)
> +{
> +	char *path;
> +
> +	path = repo_git_path(r, "config");
> +	git_config_set_in_file(path, key, value);
> +	free(path);
> +}
Many questions:
 - What do these do for an existing key?  Add another value?
   Replace existing one?  If the latter, what do we plan to do with
   multi-valued keys?
 - Don't we need an interface to remove, rename, etc.?
 - If we call repo_config_set(repo, "key", "value") and then call
   repo_git_config_string(repo, "key", &value) on the same
   repository, do we read the value back or do we give a stale
   value?
 - A change like this should make existing config_set() that only
   works on the_repository into a thin wrapper, e.g.
	void git_config_set(const char *keyu, const char **value)
	{
		repo_config_set(the_repository, key, value);
	}
   But that is not happening here.  What prevents us from doing so?
Thanks.
Previous: Glen ChooNext: Glen Choo
Message 4 of 7 in “make create_branch() accept any repository”
  1. 0/3 make create_branch() accept any repositoryGlen Choo, Nov 11, 2021
  2. 1/3 refs/files-backend: remove the_repositoryGlen Choo, Nov 11, 2021
  3. 2/3 config: introduce repo_config_set* functionsGlen Choo, Nov 11, 2021
  4. Junio C HamanoNov 11, 2021
  5. Glen ChooNov 12, 2021
  6. Glen ChooNov 15, 2021
  7. 3/3 branch: remove implicit the_repository from create_branch()Glen Choo, Nov 11, 2021

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.