Merge branch 'js/empty-config-section-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 30 May 2018 12:51:26 +0000 (21:51 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 May 2018 12:51:26 +0000 (21:51 +0900)
Error codepath fix.

* js/empty-config-section-fix:
config: a user-provided invalid section is not a BUG

1  2 
config.c
diff --combined config.c
index f47fcaf88e96c0c836484ccbccac1f1e023d8315,0205052978825bc77a91823ea24014ce45f3fabb..2c573ad3dd275faa4264b8429b275bb9670d5e04
+++ b/config.c
@@@ -9,14 -9,13 +9,14 @@@
  #include "config.h"
  #include "repository.h"
  #include "lockfile.h"
 -#include "exec_cmd.h"
 +#include "exec-cmd.h"
  #include "strbuf.h"
  #include "quote.h"
  #include "hashmap.h"
  #include "string-list.h"
  #include "utf8.h"
  #include "dir.h"
 +#include "color.h"
  
  struct config_source {
        struct config_source *prev;
@@@ -103,7 -102,7 +103,7 @@@ static int config_buf_ungetc(int c, str
        if (conf->u.buf.pos > 0) {
                conf->u.buf.pos--;
                if (conf->u.buf.buf[conf->u.buf.pos] != c)
 -                      die("BUG: config_buf can only ungetc the same character");
 +                      BUG("config_buf can only ungetc the same character");
                return c;
        }
  
@@@ -190,7 -189,7 +190,7 @@@ static int prepare_include_condition_pa
                strbuf_realpath(&path, cf->path, 1);
                slash = find_last_dir_sep(path.buf);
                if (!slash)
 -                      die("BUG: how is this possible?");
 +                      BUG("how is this possible?");
                strbuf_splice(pat, 0, 1, path.buf, slash - path.buf);
                prefix = slash - path.buf + 1 /* slash */;
        } else if (!is_absolute_path(pat->buf))
@@@ -1068,15 -1067,6 +1068,15 @@@ int git_config_expiry_date(timestamp_t 
        return 0;
  }
  
 +int git_config_color(char *dest, const char *var, const char *value)
 +{
 +      if (!value)
 +              return config_error_nonbool(var);
 +      if (color_parse(value, dest) < 0)
 +              return -1;
 +      return 0;
 +}
 +
  static int git_default_core_config(const char *var, const char *value)
  {
        /* This needs a better name */
        }
  
        if (!strcmp(var, "core.safecrlf")) {
 +              int eol_rndtrp_die;
                if (value && !strcasecmp(value, "warn")) {
 -                      safe_crlf = SAFE_CRLF_WARN;
 +                      global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
                        return 0;
                }
 -              safe_crlf = git_config_bool(var, value);
 +              eol_rndtrp_die = git_config_bool(var, value);
 +              global_conv_flags_eol = eol_rndtrp_die ?
 +                      CONV_EOL_RNDTRP_DIE : CONV_EOL_RNDTRP_WARN;
                return 0;
        }
  
                return 0;
        }
  
 +      if (!strcmp(var, "core.checkroundtripencoding")) {
 +              check_roundtrip_encoding = xstrdup(value);
 +              return 0;
 +      }
 +
        if (!strcmp(var, "core.notesref")) {
                notes_ref_name = xstrdup(value);
                return 0;
                return 0;
        }
  
 +      if (!strcmp(var, "core.commitgraph")) {
 +              core_commit_graph = git_config_bool(var, value);
 +              return 0;
 +      }
 +
        if (!strcmp(var, "core.sparsecheckout")) {
                core_apply_sparse_checkout = git_config_bool(var, value);
                return 0;
                return 0;
        }
  
 +      if (!strcmp(var, "core.partialclonefilter")) {
 +              return git_config_string(&core_partial_clone_filter_default,
 +                                       var, value);
 +      }
 +
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
  }
@@@ -1452,7 -1424,7 +1452,7 @@@ int git_default_config(const char *var
        if (starts_with(var, "mailmap."))
                return git_default_mailmap_config(var, value);
  
 -      if (starts_with(var, "advice."))
 +      if (starts_with(var, "advice.") || starts_with(var, "color.advice"))
                return git_default_advice_config(var, value);
  
        if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
@@@ -1514,7 -1486,6 +1514,7 @@@ static int do_config_from_file(config_f
                void *data, const struct config_options *opts)
  {
        struct config_source top;
 +      int ret;
  
        top.u.file = f;
        top.origin_type = origin_type;
        top.do_ungetc = config_file_ungetc;
        top.do_ftell = config_file_ftell;
  
 -      return do_config_from(&top, fn, data, opts);
 +      flockfile(f);
 +      ret = do_config_from(&top, fn, data, opts);
 +      funlockfile(f);
 +      return ret;
  }
  
  static int git_config_from_stdin(config_fn_t fn, void *data)
@@@ -1546,8 -1514,10 +1546,8 @@@ int git_config_from_file_with_options(c
  
        f = fopen_or_warn(filename, "r");
        if (f) {
 -              flockfile(f);
                ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,
                                          filename, f, data, opts);
 -              funlockfile(f);
                fclose(f);
        }
        return ret;
@@@ -1587,7 -1557,7 +1587,7 @@@ int git_config_from_blob_oid(config_fn_
        unsigned long size;
        int ret;
  
 -      buf = read_sha1_file(oid->hash, &type, &size);
 +      buf = read_object_file(oid, &type, &size);
        if (!buf)
                return error("unable to load config blob object '%s'", name);
        if (type != OBJ_BLOB) {
@@@ -1814,7 -1784,7 +1814,7 @@@ static int configset_add_value(struct c
        l_item->value_index = e->value_list.nr - 1;
  
        if (!cf)
 -              die("BUG: configset_add_value has no source");
 +              BUG("configset_add_value has no source");
        if (cf->name) {
                kv_info->filename = strintern(cf->name);
                kv_info->linenr = cf->linenr;
@@@ -2359,7 -2329,7 +2359,7 @@@ static int store_aux_event(enum config_
  
        if (type == CONFIG_EVENT_SECTION) {
                if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
-                       BUG("Invalid section name '%s'", cf->var.buf);
+                       return error("invalid section name '%s'", cf->var.buf);
  
                /* Is this the section we were looking for? */
                store->is_keys_section =
@@@ -3208,7 -3178,7 +3208,7 @@@ const char *current_config_origin_type(
        else if(cf)
                type = cf->origin_type;
        else
 -              die("BUG: current_config_origin_type called outside config callback");
 +              BUG("current_config_origin_type called outside config callback");
  
        switch (type) {
        case CONFIG_ORIGIN_BLOB:
        case CONFIG_ORIGIN_CMDLINE:
                return "command line";
        default:
 -              die("BUG: unknown config origin type");
 +              BUG("unknown config origin type");
        }
  }
  
@@@ -3234,7 -3204,7 +3234,7 @@@ const char *current_config_name(void
        else if (cf)
                name = cf->name;
        else
 -              die("BUG: current_config_name called outside config callback");
 +              BUG("current_config_name called outside config callback");
        return name ? name : "";
  }