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

Re: [PATCH 1/2] clone: respect the settings in $HOME/.gitconfig and /etc/gitconfig

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 30, 2008, 11:57 UTC
Message-ID
<alpine.DEB.1.00.0806301233560.9925@racer>
In-Reply-To
<alpine.LNX.1.00.0806292320300.19665@iabervon.org>
Hi,
On Sun, 29 Jun 2008, Daniel Barkalow wrote:
> Now, clone writes to the config file before reading any configuration, so, 
> if it's going to write to ".git/config" instead of $GIT_CONFIG, it can't 
> read from $GIT_CONFIG either. So there's no way (outside of redesigning 
> config.c) to make GIT_CONFIG useful for "clone" in particular.
Except you could read the config _before_ writing.
Or you could enhance (not redesign, as you suggest) config.c thusly:
-- snip --
diff --git a/cache.h b/cache.h
index 871f6c1..f3ea997 100644
--- a/cache.h
+++ b/cache.h
@@ -742,6 +742,7 @@ extern int git_config_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_set(const char *, const char *);
 extern int git_config_set_multivar(const char *, const char *, const char *, int);
+extern int git_config_set_multivar_in_file(const char *, const char *, const char *, int, const char *);
 extern int git_config_rename_section(const char *, const char *);
 extern const char *git_etc_gitconfig(void);
 extern int check_repository_format_version(const char *var, const char *value, void *cb);
diff --git a/config.c b/config.c
index 58749bf..41a35eb 100644
--- a/config.c
+++ b/config.c
@@ -863,23 +863,31 @@ int git_config_set(const char* key, const char* value)
  * - the config file is removed and the lock file rename()d to it.
  *
  */
-int git_config_set_multivar(const char* key, const char* value,
-	const char* value_regex, int multi_replace)
+int git_config_set_multivar(const char *key, const char *value,
+	const char *value_regex, int multi_replace)
+{
+	return git_config_set_multivar_in_file(key, value, value_regex,
+		multi_replace, NULL);
+}
+
+int git_config_set_multivar_in_file(const char *key, const char *value,
+	const char *value_regex, int multi_replace, const char *config_filename)
 {
 	int i, dot;
 	int fd = -1, in_fd;
 	int ret;
-	char* config_filename;
+	char *filename;
 	struct lock_file *lock = NULL;
 	const char* last_dot = strrchr(key, '.');
 
-	config_filename = getenv(CONFIG_ENVIRONMENT);
+	if (!config_filename)
+		config_filename = getenv(CONFIG_ENVIRONMENT);
 	if (!config_filename) {
 		config_filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
 		if (!config_filename)
-			config_filename  = git_path("config");
+			config_filename =
+				filename = xstrdup(git_path("config"));
 	}
-	config_filename = xstrdup(config_filename);
 
 	/*
 	 * Since "key" actually contains the section name and the real
@@ -1091,7 +1099,8 @@ int git_config_set_multivar(const char* key, const char* value,
 out_free:
 	if (lock)
 		rollback_lock_file(lock);
-	free(config_filename);
+	if (filename)
+		free(filename);
 	return ret;
 
 write_err_out:
-- snap --

... and then have something like

        config_filename = xstrdup(mkpath("%s/config", git_dir));

        if (safe_create_leading_directories_const(git_dir) < 0)
                die("could not create leading directories of '%s'", git_dir);
        set_git_dir(make_absolute_path(git_dir));

	[...]

	if (option_bare) {
                strcpy(branch_top, "refs/heads/");

                git_config_set_multivar_in_file("core.bare", "true",
			NULL, 0, config_filename);

	[...]

Of course, you would also have to teach init_db() to use this filename.

But frankly, I do not see the use of your "narrow" special case.  And as I 
stated in another thread, I am pretty opposed to crossing bridges that are 
miles (or an eternity) away.

So unless you present me with a sensible scenario where your "respect 
GIT_CONFIG for _reading_ in GIT_CONFIG=... git clone" makes sense, there 
is nothing to see here, please move along.

Ciao,
Dscho
Previous: Daniel BarkalowNext: Daniel Barkalow
Message 18 of 26 in “Using url.insteadOf in git-clone”
  1. Pieter de BieJun 27, 2008
  2. 1/2 clone: respect the settings in $HOME/.gitconfig and /etc/gitconfigJohannes Schindelin, Jun 27, 2008
  3. 2/2 clone: respect url.insteadOf setting in global configsJohannes Schindelin, Jun 27, 2008
  4. Daniel BarkalowJun 27, 2008
  5. Pieter de BieJun 29, 2008
  6. Johannes SchindelinJun 29, 2008
  7. Daniel BarkalowJun 27, 2008
  8. Junio C HamanoJun 27, 2008
  9. Daniel BarkalowJun 29, 2008
  10. Junio C HamanoJun 29, 2008
  11. Johannes SchindelinJun 29, 2008
  12. Daniel BarkalowJun 29, 2008
  13. Johannes SchindelinJun 30, 2008
  14. Daniel BarkalowJun 30, 2008
  15. Junio C HamanoJun 30, 2008
  16. Daniel BarkalowJun 30, 2008
  17. Daniel BarkalowJun 30, 2008
  18. Johannes SchindelinJun 30, 2008
  19. Daniel BarkalowJun 30, 2008
  20. Junio C HamanoJun 30, 2008
  21. Junio C HamanoJun 30, 2008
  22. Jeff KingJun 30, 2008
  23. Junio C HamanoJun 30, 2008
  24. Johannes SchindelinJun 30, 2008
  25. Junio C HamanoJun 27, 2008
  26. Pieter de BieJun 29, 2008

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.