]> git.ipfire.org Git - thirdparty/git.git/blobdiff - config.c
War on whitespace
[thirdparty/git.git] / config.c
index a3c7b772bce1d302e60bbf02212bb4ad4da0ee7b..58d3ed5d371b6d7548f6677e65135bd3f01851d0 100644 (file)
--- a/config.c
+++ b/config.c
@@ -12,6 +12,8 @@
 static FILE *config_file;
 static const char *config_file_name;
 static int config_linenr;
+static int zlib_compression_seen;
+
 static int get_next_char(void)
 {
        int c;
@@ -299,8 +301,14 @@ 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);
+       if (!strcmp(var, "core.loosecompression")) {
+               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;
+               zlib_compression_seen = 1;
                return 0;
        }
 
@@ -310,7 +318,10 @@ int git_default_config(const char *var, const char *value)
                        level = Z_DEFAULT_COMPRESSION;
                else if (level < 0 || level > Z_BEST_COMPRESSION)
                        die("bad zlib compression level %d", level);
-               zlib_compression_level = level;
+               core_compression_level = level;
+               core_compression_seen = 1;
+               if (!zlib_compression_seen)
+                       zlib_compression_level = level;
                return 0;
        }
 
@@ -331,6 +342,11 @@ int git_default_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.deltabasecachelimit")) {
+               delta_base_cache_limit = git_config_int(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "core.autocrlf")) {
                if (value && !strcasecmp(value, "input")) {
                        auto_crlf = -1;
@@ -351,12 +367,12 @@ int git_default_config(const char *var, const char *value)
        }
 
        if (!strcmp(var, "i18n.commitencoding")) {
-               git_commit_encoding = strdup(value);
+               git_commit_encoding = xstrdup(value);
                return 0;
        }
 
        if (!strcmp(var, "i18n.logoutputencoding")) {
-               git_log_output_encoding = strdup(value);
+               git_log_output_encoding = xstrdup(value);
                return 0;
        }
 
@@ -446,6 +462,9 @@ static int matches(const char* key, const char* value)
 
 static int store_aux(const char* key, const char* value)
 {
+       const char *ep;
+       size_t section_len;
+
        switch (store.state) {
        case KEY_SEEN:
                if (matches(key, value)) {
@@ -463,12 +482,29 @@ static int store_aux(const char* key, const char* value)
                }
                break;
        case SECTION_SEEN:
-               if (strncmp(key, store.key, store.baselen+1)) {
+               /*
+                * What we are looking for is in store.key (both
+                * section and var), and its section part is baselen
+                * long.  We found key (again, both section and var).
+                * We would want to know if this key is in the same
+                * section as what we are looking for.  We already
+                * know we are in the same section as what should
+                * hold store.key.
+                */
+               ep = strrchr(key, '.');
+               section_len = ep - key;
+
+               if ((section_len != store.baselen) ||
+                   memcmp(key, store.key, section_len+1)) {
                        store.state = SECTION_END_SEEN;
                        break;
-               } else
-                       /* do not increment matches: this is no match */
-                       store.offset[store.seen] = ftell(config_file);
+               }
+
+               /*
+                * Do not increment matches: this is no match, but we
+                * just made sure we are in the desired section.
+                */
+               store.offset[store.seen] = ftell(config_file);
                /* fallthru */
        case SECTION_END_SEEN:
        case START:
@@ -585,7 +621,7 @@ static ssize_t find_beginning_of_line(const char* contents, size_t size,
        size_t equal_offset = size, bracket_offset = size;
        ssize_t offset;
 
-       for (offset = offset_-2; offset > 0 
+       for (offset = offset_-2; offset > 0
                        && contents[offset] != '\n'; offset--)
                switch (contents[offset]) {
                        case '=': equal_offset = offset; break;
@@ -911,8 +947,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
        }
 
        if (!(config_file = fopen(config_filename, "rb"))) {
-               ret = error("Could not open config file!");
-               goto out;
+               /* no config file means nothing to rename, no error */
+               goto unlock_and_out;
        }
 
        while (fgets(buf, sizeof(buf), config_file)) {
@@ -946,10 +982,10 @@ int git_config_rename_section(const char *old_name, const char *new_name)
                }
        }
        fclose(config_file);
+ unlock_and_out:
        if (close(out_fd) || commit_lock_file(lock) < 0)
                        ret = error("Cannot commit config file!");
  out:
        free(config_filename);
        return ret;
 }
-