From: Sean <seanlkml@sympatico.ca>
To: Matthieu Moy <Matthieu.Moy@imag.fr>
Cc: git <git@vger.kernel.org>
Subject: Re: Minor documentation problems [RFC PATCH]
Date: Thu, 2 Nov 2006 07:39:43 -0500 [thread overview]
Message-ID: <BAYC1-PASMTP018DA61B5F35F9603DF8A8AEFF0@CEZ.ICE> (raw)
In-Reply-To: <vpqmz7a1694.fsf@ecrins.imag.fr>
On Thu, 02 Nov 2006 11:40:23 +0100
Matthieu Moy <Matthieu.Moy@imag.fr> 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@myisp.com>'", which
> avoids having to learn the config file syntax.
This is the git version :
$ git repo-config user.email "myself@myisp.com"
$ 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@myisp.com"
$ 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);
+}
next prev parent reply other threads:[~2006-11-02 12:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-02 10:40 Minor documentation problems Matthieu Moy
2006-11-02 11:41 ` Petr Baudis
2006-11-02 13:20 ` Matthieu Moy
2006-11-02 12:39 ` Sean [this message]
2006-11-02 13:29 ` Minor documentation problems [RFC PATCH] Matthieu Moy
2006-11-02 13:54 ` Johannes Schindelin
2006-11-02 14:30 ` Sean
2006-11-02 14:51 ` Johannes Schindelin
2006-11-02 15:44 ` [PATCH] Add --global option to git-repo-config Sean
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=BAYC1-PASMTP018DA61B5F35F9603DF8A8AEFF0@CEZ.ICE \
--to=seanlkml@sympatico.ca \
--cc=Matthieu.Moy@imag.fr \
--cc=git@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).