Re: Minor documentation problems [RFC PATCH]

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

 



On Thu, 02 Nov 2006 11:40:23 +0100
Matthieu Moy <Matthieu.Moy@xxxxxxx> wrote:

> * http://www.kernel.org/pub/software/scm/cogito/docs/cg-commit.1.html
>   Mentions .git/config, but not ~/.gitconfig (which is indeed _the_
>   place where I think most people want to set their name and email).
> 
>   Side note: it can be interesting to have a command to do this.
>   For example, bzr has "bzr whoami 'me <myself@xxxxxxxxx>'", which
>   avoids having to learn the config file syntax.

This is the git version :

$ git repo-config user.email "myself@xxxxxxxxx"
$ git repo-config user.name "me"

Unfortunately repo-config doesn't update ~/.gitconfig only
the .git/config file.

The patch below adds a --global option to allow:

$ git repo-config --global user.email "myself@xxxxxxxxx"
$ git repo-config --global user.name "me"

Although the syntax is a bit depressing, it would seem to
be the path of least resistance.

The patch below always updates ~/.gitconfig but perhaps it
should respect GIT_CONFIG and/or GIT_CONFIG_LOCAL
environment variables.

Sean

diff --git a/builtin-repo-config.c b/builtin-repo-config.c
index f60cee1..8c2b58a 100644
--- a/builtin-repo-config.c
+++ b/builtin-repo-config.c
@@ -127,9 +127,20 @@ free_strings:
 	return ret;
 }
 
+static int set_config(int global, const char* key, const char* value,
+		const char* value_regex, int multi_replace)
+{
+	if (global)
+		return git_global_config_set_multivar(key, value,
+				value_regex, multi_replace);
+	else
+		return git_config_set_multivar(key, value,
+				value_regex, multi_replace);
+}
+
 int cmd_repo_config(int argc, const char **argv, const char *prefix)
 {
-	int nongit = 0;
+	int nongit = 0, global = 0;
 	setup_git_directory_gently(&nongit);
 
 	while (1 < argc) {
@@ -139,6 +150,8 @@ int cmd_repo_config(int argc, const char
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
+		else if (!strcmp(argv[1], "--global"))
+			global = 1;
 		else
 			break;
 		argc--;
@@ -150,9 +163,9 @@ int cmd_repo_config(int argc, const char
 		return get_value(argv[1], NULL);
 	case 3:
 		if (!strcmp(argv[1], "--unset"))
-			return git_config_set(argv[2], NULL);
+			return set_config(global, argv[2], NULL, NULL, 0);
 		else if (!strcmp(argv[1], "--unset-all"))
-			return git_config_set_multivar(argv[2], NULL, NULL, 1);
+			return set_config(global, argv[2], NULL, NULL, 1);
 		else if (!strcmp(argv[1], "--get"))
 			return get_value(argv[2], NULL);
 		else if (!strcmp(argv[1], "--get-all")) {
@@ -165,12 +178,12 @@ int cmd_repo_config(int argc, const char
 			return get_value(argv[2], NULL);
 		} else
 
-			return git_config_set(argv[1], argv[2]);
+			return set_config(global, argv[1], argv[2], NULL, 0);
 	case 4:
 		if (!strcmp(argv[1], "--unset"))
-			return git_config_set_multivar(argv[2], NULL, argv[3], 0);
+			return set_config(global, argv[2], NULL, argv[3], 0);
 		else if (!strcmp(argv[1], "--unset-all"))
-			return git_config_set_multivar(argv[2], NULL, argv[3], 1);
+			return set_config(global, argv[2], NULL, argv[3], 1);
 		else if (!strcmp(argv[1], "--get"))
 			return get_value(argv[2], argv[3]);
 		else if (!strcmp(argv[1], "--get-all")) {
@@ -183,13 +196,13 @@ int cmd_repo_config(int argc, const char
 			return get_value(argv[2], argv[3]);
 		} else if (!strcmp(argv[1], "--replace-all"))
 
-			return git_config_set_multivar(argv[2], argv[3], NULL, 1);
+			return set_config(global, argv[2], argv[3], NULL, 1);
 		else
 
-			return git_config_set_multivar(argv[1], argv[2], argv[3], 0);
+			return set_config(global, argv[1], argv[2], argv[3], 0);
 	case 5:
 		if (!strcmp(argv[1], "--replace-all"))
-			return git_config_set_multivar(argv[2], argv[3], argv[4], 1);
+			return set_config(global, argv[2], argv[3], argv[4], 1);
 	case 1:
 	default:
 		usage(git_config_set_usage);
diff --git a/cache.h b/cache.h
index d0a1657..5f7c599 100644
--- a/cache.h
+++ b/cache.h
@@ -402,6 +402,8 @@ extern int git_config_int(const char *,
 extern int git_config_bool(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_global_config_set(const char*, const char*);
+extern int git_global_config_set_multivar(const char*, const char*, const char*, int);
 extern int check_repository_format_version(const char *var, const char *value);
 
 #define MAX_GITNAME (1000)
diff --git a/config.c b/config.c
index e8f0caf..0393b65 100644
--- a/config.c
+++ b/config.c
@@ -529,22 +529,16 @@ int git_config_set(const char* key, cons
  * - the config file is removed and the lock file rename()d to it.
  *
  */
-int git_config_set_multivar(const char* key, const char* value,
+int git_config_file_set_multivar(char* config_filename,
+	const char* key, const char* value,
 	const char* value_regex, int multi_replace)
 {
 	int i, dot;
 	int fd = -1, in_fd;
 	int ret;
-	char* config_filename;
 	char* lock_file;
 	const char* last_dot = strrchr(key, '.');
 
-	config_filename = getenv("GIT_CONFIG");
-	if (!config_filename) {
-		config_filename = getenv("GIT_CONFIG_LOCAL");
-		if (!config_filename)
-			config_filename  = git_path("config");
-	}
 	config_filename = xstrdup(config_filename);
 	lock_file = xstrdup(mkpath("%s.lock", config_filename));
 
@@ -742,3 +736,36 @@ out_free:
 }
 
 
+int git_config_set_multivar(const char* key, const char* value,
+	const char* value_regex, int multi_replace)
+{
+	char* config_filename;
+	config_filename = getenv("GIT_CONFIG");
+	if (!config_filename) {
+		config_filename = getenv("GIT_CONFIG_LOCAL");
+		if (!config_filename)
+			config_filename  = git_path("config");
+	}
+	return git_config_file_set_multivar(config_filename, key, value,
+				value_regex, multi_replace);
+}
+
+int git_global_config_set_multivar(const char* key, const char* value,
+	const char* value_regex, int multi_replace)
+{
+	int ret = -1;
+	const char *home = getenv("HOME");
+	if (home) {
+		char * global = xstrdup(mkpath("%s/.gitconfig", home));
+		ret = git_config_file_set_multivar(global, key, value,
+				value_regex, multi_replace);
+		free(global);
+	}
+	return ret;
+}
+
+int git_global_config_set(const char* key, const char* value)
+{
+	return git_global_config_set_multivar(key, value, NULL, 0);
+}
+
-
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]