X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=config.c;h=95ec34923d3fcf4d2a8fa16cbab9a5cbfe8e4f6f;hb=65b5e41e24dd76e9cc272399f458857d5b13d63e;hp=0c43d7615b68cb41b60a140bdcf26559b24cc3e0;hpb=4f629539cd99fb9fc68dbdc56812f291565d0f87;p=git.git diff --git a/config.c b/config.c index 0c43d761..95ec3492 100644 --- a/config.c +++ b/config.c @@ -11,7 +11,7 @@ #define MAXNAME (256) static FILE *config_file; -static char *config_file_name; +static const char *config_file_name; static int config_linenr; static int get_next_char(void) { @@ -222,11 +222,21 @@ int git_default_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.ignorestat")) { + assume_unchanged = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "core.symrefsonly")) { only_use_symrefs = git_config_bool(var, value); return 0; } + if (!strcmp(var, "core.warnambiguousrefs")) { + warn_ambiguous_refs = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "user.name")) { strncpy(git_default_name, value, sizeof(git_default_name)); return 0; @@ -237,6 +247,11 @@ int git_default_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "i18n.commitencoding")) { + strncpy(git_commit_encoding, value, sizeof(git_commit_encoding)); + return 0; + } + /* Add other config variables here.. */ return 0; } @@ -404,8 +419,7 @@ int git_config_set_multivar(const char* key, const char* value, const char* value_regex, int multi_replace) { int i; - struct stat st; - int fd; + int fd, in_fd; char* config_filename = strdup(git_path("config")); char* lock_file = strdup(git_path("config.lock")); const char* last_dot = strrchr(key, '.'); @@ -452,15 +466,17 @@ int git_config_set_multivar(const char* key, const char* value, /* * If .git/config does not exist yet, write a minimal version. */ - if (stat(config_filename, &st)) { - static const char contents[] = - "#\n" - "# This is the config file\n" - "#\n" - "\n"; - + in_fd = open(config_filename, O_RDONLY); + if ( in_fd < 0 ) { free(store.key); + if ( ENOENT != errno ) { + error("opening %s: %s", config_filename, + strerror(errno)); + close(fd); + unlink(lock_file); + return 3; /* same as "invalid config file" */ + } /* if nothing to unset, error out */ if (value == NULL) { close(fd); @@ -469,12 +485,10 @@ int git_config_set_multivar(const char* key, const char* value, } store.key = (char*)key; - - write(fd, contents, sizeof(contents)-1); store_write_section(fd, key); store_write_pair(fd, key, value); } else{ - int in_fd; + struct stat st; char* contents; int i, copy_begin, copy_end, new_line = 0; @@ -490,7 +504,7 @@ int git_config_set_multivar(const char* key, const char* value, store.value_regex = (regex_t*)malloc(sizeof(regex_t)); if (regcomp(store.value_regex, value_regex, REG_EXTENDED)) { - fprintf(stderr, "Invalid pattern: %s", + fprintf(stderr, "Invalid pattern: %s\n", value_regex); free(store.value_regex); return 6; @@ -531,7 +545,7 @@ int git_config_set_multivar(const char* key, const char* value, return 5; } - in_fd = open(config_filename, O_RDONLY, 0666); + fstat(in_fd, &st); contents = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, in_fd, 0); close(in_fd);