Code

glossary: stop generating automatically
[git.git] / config.c
index 9ded954496af7698ef46fb971c69e4b01e2e9db3..c938aa0b15513265866b88dbb9b8217958cac376 100644 (file)
--- a/config.c
+++ b/config.c
@@ -269,6 +269,11 @@ int git_default_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.bare")) {
+               is_bare_repository_cfg = git_config_bool(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "core.ignorestat")) {
                assume_unchanged = git_config_bool(var, value);
                return 0;
@@ -305,12 +310,14 @@ int git_default_config(const char *var, const char *value)
        }
 
        if (!strcmp(var, "core.packedgitwindowsize")) {
-               int pgsz = getpagesize();
+               int pgsz_x2 = getpagesize() * 2;
                packed_git_window_size = git_config_int(var, value);
-               packed_git_window_size /= pgsz;
-               if (packed_git_window_size < 2)
-                       packed_git_window_size = 2;
-               packed_git_window_size *= pgsz;
+
+               /* This value must be multiple of (pagesize * 2) */
+               packed_git_window_size /= pgsz_x2;
+               if (packed_git_window_size < 1)
+                       packed_git_window_size = 1;
+               packed_git_window_size *= pgsz_x2;
                return 0;
        }
 
@@ -513,11 +520,23 @@ static int store_write_pair(int fd, const char* key, const char* value)
 {
        int i;
        int length = strlen(key+store.baselen+1);
+       int quote = 0;
+
+       /* Check to see if the value needs to be quoted. */
+       if (value[0] == ' ')
+               quote = 1;
+       for (i = 0; value[i]; i++)
+               if (value[i] == ';' || value[i] == '#')
+                       quote = 1;
+       if (value[i-1] == ' ')
+               quote = 1;
 
        if (write_in_full(fd, "\t", 1) != 1 ||
            write_in_full(fd, key+store.baselen+1, length) != length ||
            write_in_full(fd, " = ", 3) != 3)
                return 0;
+       if (quote && write_in_full(fd, "\"", 1) != 1)
+               return 0;
        for (i = 0; value[i]; i++)
                switch (value[i]) {
                case '\n':
@@ -537,6 +556,8 @@ static int store_write_pair(int fd, const char* key, const char* value)
                                return 0;
                        break;
                }
+       if (quote && write_in_full(fd, "\"", 1) != 1)
+               return 0;
        if (write_in_full(fd, "\n", 1) != 1)
                return 0;
        return 1;
@@ -642,6 +663,11 @@ int git_config_set_multivar(const char* key, const char* value,
                                goto out_free;
                        }
                        c = tolower(c);
+               } else if (c == '\n') {
+                       fprintf(stderr, "invalid key (newline): %s\n", key);
+                       free(store.key);
+                       ret = 1;
+                       goto out_free;
                }
                store.key[i] = c;
        }
@@ -680,11 +706,9 @@ int git_config_set_multivar(const char* key, const char* value,
 
                store.key = (char*)key;
                if (!store_write_section(fd, key) ||
-                   !store_write_pair(fd, key, value)) {
-                       ret = write_error();
-                       goto out_free;
-               }
-       } else{
+                   !store_write_pair(fd, key, value))
+                       goto write_err_out;
+       } else {
                struct stat st;
                char* contents;
                int i, copy_begin, copy_end, new_line = 0;
@@ -763,31 +787,33 @@ int git_config_set_multivar(const char* key, const char* value,
 
                        /* write the first part of the config */
                        if (copy_end > copy_begin) {
-                               write_in_full(fd, contents + copy_begin,
-                               copy_end - copy_begin);
-                               if (new_line)
-                                       write_in_full(fd, "\n", 1);
+                               if (write_in_full(fd, contents + copy_begin,
+                                                 copy_end - copy_begin) <
+                                   copy_end - copy_begin)
+                                       goto write_err_out;
+                               if (new_line &&
+                                   write_in_full(fd, "\n", 1) != 1)
+                                       goto write_err_out;
                        }
                        copy_begin = store.offset[i];
                }
 
                /* write the pair (value == NULL means unset) */
                if (value != NULL) {
-                       if (store.state == START)
-                               if (!store_write_section(fd, key)) {
-                                       ret = write_error();
-                                       goto out_free;
-                               }
-                       if (!store_write_pair(fd, key, value)) {
-                               ret = write_error();
-                               goto out_free;
+                       if (store.state == START) {
+                               if (!store_write_section(fd, key))
+                                       goto write_err_out;
                        }
+                       if (!store_write_pair(fd, key, value))
+                               goto write_err_out;
                }
 
                /* write the rest of the config */
                if (copy_begin < st.st_size)
-                       write_in_full(fd, contents + copy_begin,
-                               st.st_size - copy_begin);
+                       if (write_in_full(fd, contents + copy_begin,
+                                         st.st_size - copy_begin) <
+                           st.st_size - copy_begin)
+                               goto write_err_out;
 
                munmap(contents, st.st_size);
                unlink(config_filename);
@@ -810,6 +836,11 @@ out_free:
                free(lock_file);
        }
        return ret;
+
+write_err_out:
+       ret = write_error();
+       goto out_free;
+
 }
 
 int git_config_rename_section(const char *old_name, const char *new_name)
@@ -867,7 +898,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
                                if (buf[i] != old_name[j++])
                                        break;
                        }
-                       if (buf[i] == ']') {
+                       if (buf[i] == ']' && old_name[j] == 0) {
                                /* old_name matches */
                                ret++;
                                store.baselen = strlen(new_name);