Code

Increase length of function name buffer
[git.git] / config.c
index 3e077d4c6ca4f7162e3a3254e1b3e90db33270ff..3cae3901aa9b50e8d04a8ce2633a1a1ef8ed0f6c 100644 (file)
--- a/config.c
+++ b/config.c
@@ -103,6 +103,11 @@ static char *parse_value(void)
        }
 }
 
+static inline int iskeychar(int c)
+{
+       return isalnum(c) || c == '-';
+}
+
 static int get_value(config_fn_t fn, char *name, unsigned int len)
 {
        int c;
@@ -113,7 +118,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len)
                c = get_next_char();
                if (c == EOF)
                        break;
-               if (!isalnum(c))
+               if (!iskeychar(c))
                        break;
                name[len++] = tolower(c);
                if (len >= MAXNAME)
@@ -181,7 +186,7 @@ static int get_base_var(char *name)
                        return baselen;
                if (isspace(c))
                        return get_extended_base_var(name, baselen, c);
-               if (!isalnum(c) && c != '.')
+               if (!iskeychar(c) && c != '.')
                        return -1;
                if (baselen > MAXNAME / 2)
                        return -1;
@@ -244,9 +249,9 @@ int git_config_bool(const char *name, const char *value)
                return 1;
        if (!*value)
                return 0;
-       if (!strcasecmp(value, "true"))
+       if (!strcasecmp(value, "true") || !strcasecmp(value, "yes"))
                return 1;
-       if (!strcasecmp(value, "false"))
+       if (!strcasecmp(value, "false") || !strcasecmp(value, "no"))
                return 0;
        return git_config_int(name, value) != 0;
 }
@@ -279,18 +284,38 @@ int git_default_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.legacyheaders")) {
+               use_legacy_headers = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (!strcmp(var, "core.compression")) {
+               int level = git_config_int(var, value);
+               if (level == -1)
+                       level = Z_DEFAULT_COMPRESSION;
+               else if (level < 0 || level > Z_BEST_COMPRESSION)
+                       die("bad zlib compression level %d", level);
+               zlib_compression_level = level;
+               return 0;
+       }
+
        if (!strcmp(var, "user.name")) {
-               safe_strncpy(git_default_name, value, sizeof(git_default_name));
+               strlcpy(git_default_name, value, sizeof(git_default_name));
                return 0;
        }
 
        if (!strcmp(var, "user.email")) {
-               safe_strncpy(git_default_email, value, sizeof(git_default_email));
+               strlcpy(git_default_email, value, sizeof(git_default_email));
                return 0;
        }
 
        if (!strcmp(var, "i18n.commitencoding")) {
-               safe_strncpy(git_commit_encoding, value, sizeof(git_commit_encoding));
+               strlcpy(git_commit_encoding, value, sizeof(git_commit_encoding));
+               return 0;
+       }
+
+       if (!strcmp(var, "pager.color")) {
+               pager_use_color = git_config_bool(var,value);
                return 0;
        }
 
@@ -330,19 +355,18 @@ int git_config(config_fn_t fn)
                home = getenv("HOME");
                filename = getenv("GIT_CONFIG_LOCAL");
                if (!filename)
-                       filename = repo_config = strdup(git_path("config"));
+                       filename = repo_config = xstrdup(git_path("config"));
        }
 
        if (home) {
-               char *user_config = strdup(mkpath("%s/.gitconfig", home));
+               char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
                if (!access(user_config, R_OK))
                        ret = git_config_from_file(fn, user_config);
                free(user_config);
        }
 
        ret += git_config_from_file(fn, filename);
-       if (repo_config)
-               free(repo_config);
+       free(repo_config);
        return ret;
 }
 
@@ -526,8 +550,8 @@ int git_config_set_multivar(const char* key, const char* value,
                if (!config_filename)
                        config_filename  = git_path("config");
        }
-       config_filename = strdup(config_filename);
-       lock_file = strdup(mkpath("%s.lock", config_filename));
+       config_filename = xstrdup(config_filename);
+       lock_file = xstrdup(mkpath("%s.lock", config_filename));
 
        /*
         * Since "key" actually contains the section name and the real
@@ -546,7 +570,7 @@ int git_config_set_multivar(const char* key, const char* value,
        /*
         * Validate the key and while at it, lower case it for matching.
         */
-       store.key = (char*)malloc(strlen(key)+1);
+       store.key = xmalloc(strlen(key) + 1);
        dot = 0;
        for (i = 0; key[i]; i++) {
                unsigned char c = key[i];
@@ -554,7 +578,7 @@ int git_config_set_multivar(const char* key, const char* value,
                        dot = 1;
                /* Leave the extended basename untouched.. */
                if (!dot || i > store.baselen) {
-                       if (!isalnum(c) || (i == store.baselen+1 && !isalpha(c))) {
+                       if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {
                                fprintf(stderr, "invalid key: %s\n", key);
                                free(store.key);
                                ret = 1;
@@ -614,7 +638,7 @@ int git_config_set_multivar(const char* key, const char* value,
                        } else
                                store.do_not_match = 0;
 
-                       store.value_regex = (regex_t*)malloc(sizeof(regex_t));
+                       store.value_regex = (regex_t*)xmalloc(sizeof(regex_t));
                        if (regcomp(store.value_regex, value_regex,
                                        REG_EXTENDED)) {
                                fprintf(stderr, "Invalid pattern: %s\n",
@@ -714,8 +738,7 @@ int git_config_set_multivar(const char* key, const char* value,
 out_free:
        if (0 <= fd)
                close(fd);
-       if (config_filename)
-               free(config_filename);
+       free(config_filename);
        if (lock_file) {
                unlink(lock_file);
                free(lock_file);