[PATCH 1/2] Add possibility to store configuration in ~/.config/git/config file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]