summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ec2d151)
raw | patch | inline | side by side (parent: ec2d151)
author | Linus Torvalds <torvalds@osdl.org> | |
Wed, 12 Oct 2005 01:47:34 +0000 (18:47 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 12 Oct 2005 01:47:34 +0000 (18:47 -0700) |
This starts using the "user.name" and "user.email" config variables if
they exist as the default name and email when committing. This means
that you don't have to use the GIT_COMMITTER_EMAIL environment variable
to override your email - you can just edit the config file instead.
The patch looks bigger than it is because it makes the default name and
email information non-static and renames it appropriately. And it moves
the common git environment variables into a new library file, so that
you can link against libgit.a and get the git environment without having
to link in zlib and libcrypt.
In short, most of it is renaming and moving, the real change core is
just a few new lines in "git_default_config()" that copies the user
config values to the new base.
It also changes "git-var -l" to list the config variables.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
they exist as the default name and email when committing. This means
that you don't have to use the GIT_COMMITTER_EMAIL environment variable
to override your email - you can just edit the config file instead.
The patch looks bigger than it is because it makes the default name and
email information non-static and renames it appropriately. And it moves
the common git environment variables into a new library file, so that
you can link against libgit.a and get the git environment without having
to link in zlib and libcrypt.
In short, most of it is renaming and moving, the real change core is
just a few new lines in "git_default_config()" that copies the user
config values to the new base.
It also changes "git-var -l" to list the config variables.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile | patch | blob | history | |
cache.h | patch | blob | history | |
commit-tree.c | patch | blob | history | |
config.c | patch | blob | history | |
environment.c | [new file with mode: 0644] | patch | blob |
ident.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
var.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index d345c5d116b4a1378955627bfbe74beb8f1fee93..5e7d0555ea8e63de6599b383c6dc81d879733146 100644 (file)
--- a/Makefile
+++ b/Makefile
object.o pack-check.o patch-delta.o path.o pkt-line.o \
quote.o read-cache.o refs.o run-command.o \
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
- tag.o tree.o usage.o config.o $(DIFF_OBJS)
+ tag.o tree.o usage.o config.o environment.o $(DIFF_OBJS)
LIBS = $(LIB_FILE)
LIBS += -lz
index 41cc22c1a1da749f1c5154da6df2a3e6876131e3..1a7e047d762a6f4eab05b6fc34e156c9886ceae9 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int git_config_int(const char *, const char *);
extern int git_config_bool(const char *, const char *);
+#define MAX_GITNAME (1000)
+extern char git_default_email[MAX_GITNAME];
+extern char git_default_name[MAX_GITNAME];
+
#endif /* CACHE_H */
diff --git a/commit-tree.c b/commit-tree.c
index b1ef0b590ab879fbbc93d04a2f8f488a223ea58d..030fb704e5545fbebc978f919d89caad99b327ee 100644 (file)
--- a/commit-tree.c
+++ b/commit-tree.c
char *buffer;
unsigned int size;
+ setup_ident();
+ git_config(git_default_config);
+
if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)
usage(commit_tree_usage);
}
if (!parents)
fprintf(stderr, "Committing initial tree %s\n", argv[1]);
- setup_ident();
init_buffer(&buffer, &size);
add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));
diff --git a/config.c b/config.c
index 510456ceb59d5608d13164fe976631b3ba874fd6..cf803580c9447540627fdc8db0039fa456b7b255 100644 (file)
--- a/config.c
+++ b/config.c
return 0;
}
+ if (!strcmp(var, "user.name")) {
+ strncpy(git_default_name, value, sizeof(git_default_name));
+ return 0;
+ }
+
+ if (!strcmp(var, "user.email")) {
+ strncpy(git_default_email, value, sizeof(git_default_email));
+ return 0;
+ }
+
/* Add other config variables here.. */
return 0;
}
diff --git a/environment.c b/environment.c
--- /dev/null
+++ b/environment.c
@@ -0,0 +1,75 @@
+/*
+ * We put all the git config variables in this same object
+ * file, so that programs can link against the config parser
+ * without having to link against all the rest of git.
+ *
+ * In particular, no need to bring in libz etc unless needed,
+ * even if you might want to know where the git directory etc
+ * are.
+ */
+#include "cache.h"
+
+char git_default_email[MAX_GITNAME];
+char git_default_name[MAX_GITNAME];
+int trust_executable_bit = 1;
+
+static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
+ *git_graft_file;
+static void setup_git_env(void)
+{
+ git_dir = getenv(GIT_DIR_ENVIRONMENT);
+ if (!git_dir)
+ git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ git_object_dir = getenv(DB_ENVIRONMENT);
+ if (!git_object_dir) {
+ git_object_dir = xmalloc(strlen(git_dir) + 9);
+ sprintf(git_object_dir, "%s/objects", git_dir);
+ }
+ git_refs_dir = xmalloc(strlen(git_dir) + 6);
+ sprintf(git_refs_dir, "%s/refs", git_dir);
+ git_index_file = getenv(INDEX_ENVIRONMENT);
+ if (!git_index_file) {
+ git_index_file = xmalloc(strlen(git_dir) + 7);
+ sprintf(git_index_file, "%s/index", git_dir);
+ }
+ git_graft_file = getenv(GRAFT_ENVIRONMENT);
+ if (!git_graft_file)
+ git_graft_file = strdup(git_path("info/grafts"));
+}
+
+char *get_git_dir(void)
+{
+ if (!git_dir)
+ setup_git_env();
+ return git_dir;
+}
+
+char *get_object_directory(void)
+{
+ if (!git_object_dir)
+ setup_git_env();
+ return git_object_dir;
+}
+
+char *get_refs_directory(void)
+{
+ if (!git_refs_dir)
+ setup_git_env();
+ return git_refs_dir;
+}
+
+char *get_index_file(void)
+{
+ if (!git_index_file)
+ setup_git_env();
+ return git_index_file;
+}
+
+char *get_graft_file(void)
+{
+ if (!git_graft_file)
+ setup_git_env();
+ return git_graft_file;
+}
+
+
index 562f5f18160166506e99aa4f6b5b417cbdc847d8..7a9f5672ebfa0d3fc4ba72b7b90273b11aeebee4 100644 (file)
--- a/ident.c
+++ b/ident.c
#include <time.h>
#include <ctype.h>
-static char real_email[1000];
-static char real_name[1000];
-static char real_date[50];
+static char git_default_date[50];
static void copy_gecos(struct passwd *w, char *name, int sz)
{
die("You don't exist. Go away!");
/* Get the name ("gecos") */
- copy_gecos(pw, real_name, sizeof(real_name));
+ copy_gecos(pw, git_default_name, sizeof(git_default_name));
/* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
len = strlen(pw->pw_name);
- if (len > sizeof(real_email)/2)
+ if (len > sizeof(git_default_email)/2)
die("Your sysadmin must hate you!");
- memcpy(real_email, pw->pw_name, len);
- real_email[len++] = '@';
- gethostname(real_email + len, sizeof(real_email) - len);
- if (!strchr(real_email+len, '.')) {
- len = strlen(real_email);
- real_email[len++] = '.';
- getdomainname(real_email+len, sizeof(real_email)-len);
+ memcpy(git_default_email, pw->pw_name, len);
+ git_default_email[len++] = '@';
+ gethostname(git_default_email + len, sizeof(git_default_email) - len);
+ if (!strchr(git_default_email+len, '.')) {
+ len = strlen(git_default_email);
+ git_default_email[len++] = '.';
+ getdomainname(git_default_email+len, sizeof(git_default_email)-len);
}
/* And set the default date */
- datestamp(real_date, sizeof(real_date));
+ datestamp(git_default_date, sizeof(git_default_date));
return 0;
}
int i;
if (!name)
- name = real_name;
+ name = git_default_name;
if (!email)
- email = real_email;
- strcpy(date, real_date);
+ email = git_default_email;
+ strcpy(date, git_default_date);
if (date_str)
parse_date(date_str, date, sizeof(date));
diff --git a/read-cache.c b/read-cache.c
index 4ed369acf8a62212c759c16dae8177597d02d536..693273620370e0500bc9ea2adba98a88cafc39cd 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
*/
#include "cache.h"
-int trust_executable_bit = 1;
struct cache_entry **active_cache = NULL;
unsigned int active_nr = 0, active_alloc = 0, active_cache_changed = 0;
diff --git a/sha1_file.c b/sha1_file.c
index 6e3ea232eecc0f190925568ecb86fb24c93e6c94..f0590049098b5371bc72855acc5736f9d5f61e2b 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return 0;
}
-static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
- *git_graft_file;
-static void setup_git_env(void)
-{
- git_dir = getenv(GIT_DIR_ENVIRONMENT);
- if (!git_dir)
- git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
- git_object_dir = getenv(DB_ENVIRONMENT);
- if (!git_object_dir) {
- git_object_dir = xmalloc(strlen(git_dir) + 9);
- sprintf(git_object_dir, "%s/objects", git_dir);
- }
- git_refs_dir = xmalloc(strlen(git_dir) + 6);
- sprintf(git_refs_dir, "%s/refs", git_dir);
- git_index_file = getenv(INDEX_ENVIRONMENT);
- if (!git_index_file) {
- git_index_file = xmalloc(strlen(git_dir) + 7);
- sprintf(git_index_file, "%s/index", git_dir);
- }
- git_graft_file = getenv(GRAFT_ENVIRONMENT);
- if (!git_graft_file)
- git_graft_file = strdup(git_path("info/grafts"));
-}
-
-char *get_git_dir(void)
-{
- if (!git_dir)
- setup_git_env();
- return git_dir;
-}
-
-char *get_object_directory(void)
-{
- if (!git_object_dir)
- setup_git_env();
- return git_object_dir;
-}
-
-char *get_refs_directory(void)
-{
- if (!git_refs_dir)
- setup_git_env();
- return git_refs_dir;
-}
-
-char *get_index_file(void)
-{
- if (!git_index_file)
- setup_git_env();
- return git_index_file;
-}
-
-char *get_graft_file(void)
-{
- if (!git_graft_file)
- setup_git_env();
- return git_graft_file;
-}
-
int safe_create_leading_directories(char *path)
{
char *pos = path;
index 3f13126cb8b88593fa81dda875e8e4080a27ae03..51cf86a5843acc3b6bc3d8c4be9fec0fdd0a0df5 100644 (file)
--- a/var.c
+++ b/var.c
return val;
}
+static int show_config(const char *var, const char *value)
+{
+ if (value)
+ printf("%s=%s\n", var, value);
+ else
+ printf("%s\n", var);
+ return git_default_config(var, value);
+}
+
int main(int argc, char **argv)
{
const char *val;
val = NULL;
if (strcmp(argv[1], "-l") == 0) {
+ git_config(show_config);
list_vars();
return 0;
}
+ git_config(git_default_config);
val = read_var(argv[1]);
if (!val)
usage(var_usage);