Git development
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Pieter de Bie <pdebie@ai.rug.nl>,
	Git Mailinglist <git@vger.kernel.org>
Subject: Re: [PATCH 1/2] clone: respect the settings in $HOME/.gitconfig and /etc/gitconfig
Date: Mon, 30 Jun 2008 12:57:16 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.1.00.0806301233560.9925@racer> (raw)
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

  reply	other threads:[~2008-06-30 12:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27  9:35 Using url.insteadOf in git-clone Pieter de Bie
2008-06-27 12:55 ` [PATCH 1/2] clone: respect the settings in $HOME/.gitconfig and /etc/gitconfig Johannes Schindelin
2008-06-27 12:56   ` [PATCH 2/2] clone: respect url.insteadOf setting in global configs Johannes Schindelin
2008-06-27 16:08     ` Daniel Barkalow
2008-06-29 20:12     ` Pieter de Bie
2008-06-29 21:50       ` Johannes Schindelin
2008-06-27 16:05   ` [PATCH 1/2] clone: respect the settings in $HOME/.gitconfig and /etc/gitconfig Daniel Barkalow
2008-06-27 22:40     ` Junio C Hamano
2008-06-29 18:31       ` Daniel Barkalow
2008-06-29 20:36         ` Junio C Hamano
2008-06-29 21:49         ` Johannes Schindelin
2008-06-29 22:47           ` Daniel Barkalow
2008-06-30  0:41             ` Johannes Schindelin
2008-06-30  1:54               ` Daniel Barkalow
2008-06-30  1:20             ` Junio C Hamano
2008-06-30  2:21               ` Daniel Barkalow
2008-06-30  3:47               ` Daniel Barkalow
2008-06-30 11:57                 ` Johannes Schindelin [this message]
2008-06-30 16:47                   ` Daniel Barkalow
2008-06-30  6:20           ` Junio C Hamano
2008-06-30  6:25             ` Junio C Hamano
2008-06-30  6:40               ` Jeff King
2008-06-30  6:44                 ` Junio C Hamano
2008-06-30 11:37             ` Johannes Schindelin
2008-06-27 17:11 ` Using url.insteadOf in git-clone Junio C Hamano
2008-06-29 18:59   ` Pieter de Bie

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=alpine.DEB.1.00.0806301233560.9925@racer \
    --to=johannes.schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pdebie@ai.rug.nl \
    /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