git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Add possibility to store configuration in ~/.config/git/config file
@ 2012-05-25 19:47 NGUYEN Huynh Khoi Nguyen
  2012-05-25 19:47 ` [PATCH 2/2] Test File Name: t1306-second-config-file.sh NGUYEN Huynh Khoi Nguyen
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: NGUYEN Huynh Khoi Nguyen @ 2012-05-25 19:47 UTC (permalink / raw)
  To: git; +Cc: Matthieu.Moy, NGUYEN Huynh Khoi Nguyen

git will store its configuration in ~/.config/git/config file if this file
exists and ~/.gitconfig file doesn't, otherwise git store its configuration
in ~/.gitconfig as usual
---
 builtin/config.c |   31 ++++++++++++++++++++++++++++---
 config.c         |   15 ++++++++++++++-
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 33c8820..dc890d5 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -171,8 +171,20 @@ static int get_value(const char *key_, const char *regex_)
 	if (!local) {
 		const char *home = getenv("HOME");
 		local = repo_config = git_pathdup("config");
-		if (home)
-			global = xstrdup(mkpath("%s/.gitconfig", home));
+		if (home) {
+			char gitconfig_path[PATH_MAX], config_path[PATH_MAX];
+			FILE *gitconfig_file, *config_file;
+
+			sprintf(gitconfig_path, "%s/.gitconfig", home);
+			sprintf(config_path, "%s/.config/git/config", home);
+			gitconfig_file = fopen(gitconfig_path, "r");
+			config_file = fopen(config_path, "r");
+
+			if (gitconfig_file==NULL && config_file!=NULL)
+				global = xstrdup(mkpath("%s/.config/git/config", home));
+			else
+				global = xstrdup(mkpath("%s/.gitconfig", home));
+		}
 		if (git_config_system())
 			system_wide = git_etc_gitconfig();
 	}
@@ -381,7 +393,20 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	if (use_global_config) {
 		char *home = getenv("HOME");
 		if (home) {
-			char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
+			char gitconfig_path[PATH_MAX], config_path[PATH_MAX];
+			FILE *gitconfig_file, *config_file;
+			char *user_config;
+
+			sprintf(gitconfig_path, "%s/.gitconfig", home);
+			sprintf(config_path, "%s/.config/git/config", home);
+			gitconfig_file = fopen(gitconfig_path, "r");
+			config_file = fopen(config_path, "r");
+
+			if (gitconfig_file==NULL && config_file!=NULL)
+				user_config = xstrdup(mkpath("%s/.config/git/config", home));
+			else
+				user_config = xstrdup(mkpath("%s/.gitconfig", home));
+
 			given_config_file = user_config;
 		} else {
 			die("$HOME not set");
diff --git a/config.c b/config.c
index eeee986..998dbbc 100644
--- a/config.c
+++ b/config.c
@@ -962,7 +962,20 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 	home = getenv("HOME");
 	if (home) {
 		char buf[PATH_MAX];
-		char *user_config = mksnpath(buf, sizeof(buf), "%s/.gitconfig", home);
+		char gitconfig_path[PATH_MAX], config_path[PATH_MAX];
+		FILE *gitconfig_file, *config_file;
+		char *user_config;
+
+		sprintf(gitconfig_path, "%s/.gitconfig", home);
+		sprintf(config_path, "%s/.config/git/config", home);
+		gitconfig_file = fopen(gitconfig_path, "r");
+		config_file = fopen(config_path, "r");
+
+		if (gitconfig_file==NULL && config_file!=NULL)
+			user_config = mksnpath(buf, sizeof(buf), "%s/.config/git/config", home);
+		else
+			user_config = mksnpath(buf, sizeof(buf), "%s/.gitconfig", home);
+
 		if (!access(user_config, R_OK)) {
 			ret += git_config_from_file(fn, user_config, data);
 			found += 1;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] Add possibility to store configuration in ~/.config/git/config file
@ 2012-05-28 16:16 nguyenhu
  0 siblings, 0 replies; 13+ messages in thread
From: nguyenhu @ 2012-05-28 16:16 UTC (permalink / raw)
  To: jaseemabid; +Cc: git


jaseem abid <jaseemabid@gmail.com>wrote:
> If a new config file gets introduced at `~/.config/git/config`, what
> will be the new order of config file precedence?
>
> `/etc/gitconfig` > `~/.gitconfig` > `~/.config/git/config`  >  
> `.git/config` or
> `/etc/gitconfig` >  `~/.config/git/config` > `~/.gitconfig` > `.git/config` ?
>
> What will be the new flag to access it? I mean anything new like
> --system / --global going to be introduced?

The new order would be:
`/etc/gitconfig` >  `~/.config/git/config` > `~/.gitconfig` > `.git/config`

There won't be new flag to access it.
You can access it with --global only if ~/.gitconfig doesn't exist.

But I will try to create another patch _only_ for reading first. So if  
git doesn't find a value in ~/.gitconfig or if this file doesn't  
exist, git will search this value in ~/.config/git/config if this file  
exists.
But for the time being, I don't know how to do it.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-05-28 21:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 19:47 [PATCH 1/2] Add possibility to store configuration in ~/.config/git/config file NGUYEN Huynh Khoi Nguyen
2012-05-25 19:47 ` [PATCH 2/2] Test File Name: t1306-second-config-file.sh NGUYEN Huynh Khoi Nguyen
2012-05-25 20:30 ` [PATCH 1/2] Add possibility to store configuration in ~/.config/git/config file Jeff King
2012-05-25 21:25   ` Junio C Hamano
2012-05-25 21:44     ` Jeff King
2012-05-26 10:15       ` Nguyen Thai Ngoc Duy
2012-05-26 21:54         ` Jeff King
2012-05-28 21:05           ` David Aguilar
2012-05-26  9:05     ` Matthieu Moy
2012-05-25 21:26 ` jaseem abid
2012-05-26  8:53 ` Matthieu Moy
2012-05-26 21:49   ` Jeff King
  -- strict thread matches above, loose matches on Subject: below --
2012-05-28 16:16 nguyenhu

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).