l10n: git.pot: v2.12.0 round 1 (239 new, 15 removed)
[gitweb.git] / config.c
index bea937e4ecf8417a910882c1aafb263e792f2e1c..c6b874a7bf763851b425d526f704966aaad129b2 100644 (file)
--- a/config.c
+++ b/config.c
@@ -24,7 +24,7 @@ struct config_source {
                        size_t pos;
                } buf;
        } u;
-       const char *origin_type;
+       enum config_origin_type origin_type;
        const char *name;
        const char *path;
        int die_on_error;
@@ -66,6 +66,8 @@ static struct key_value_info *current_config_kvi;
  */
 static enum config_scope current_parsing_scope;
 
+static int core_compression_seen;
+static int pack_compression_seen;
 static int zlib_compression_seen;
 
 /*
@@ -245,6 +247,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
 
        memset(&source, 0, sizeof(source));
        source.prev = cf;
+       source.origin_type = CONFIG_ORIGIN_CMDLINE;
        cf = &source;
 
        /* sq_dequote will write over it */
@@ -453,6 +456,8 @@ static int git_parse_source(config_fn_t fn, void *data)
        int comment = 0;
        int baselen = 0;
        struct strbuf *var = &cf->var;
+       int error_return = 0;
+       char *error_msg = NULL;
 
        /* U+FEFF Byte Order Mark in UTF8 */
        const char *bomptr = utf8_bom;
@@ -507,10 +512,40 @@ static int git_parse_source(config_fn_t fn, void *data)
                if (get_value(fn, data, var) < 0)
                        break;
        }
+
+       switch (cf->origin_type) {
+       case CONFIG_ORIGIN_BLOB:
+               error_msg = xstrfmt(_("bad config line %d in blob %s"),
+                                     cf->linenr, cf->name);
+               break;
+       case CONFIG_ORIGIN_FILE:
+               error_msg = xstrfmt(_("bad config line %d in file %s"),
+                                     cf->linenr, cf->name);
+               break;
+       case CONFIG_ORIGIN_STDIN:
+               error_msg = xstrfmt(_("bad config line %d in standard input"),
+                                     cf->linenr);
+               break;
+       case CONFIG_ORIGIN_SUBMODULE_BLOB:
+               error_msg = xstrfmt(_("bad config line %d in submodule-blob %s"),
+                                      cf->linenr, cf->name);
+               break;
+       case CONFIG_ORIGIN_CMDLINE:
+               error_msg = xstrfmt(_("bad config line %d in command line %s"),
+                                      cf->linenr, cf->name);
+               break;
+       default:
+               error_msg = xstrfmt(_("bad config line %d in %s"),
+                                     cf->linenr, cf->name);
+       }
+
        if (cf->die_on_error)
-               die(_("bad config line %d in %s %s"), cf->linenr, cf->origin_type, cf->name);
+               die("%s", error_msg);
        else
-               return error(_("bad config line %d in %s %s"), cf->linenr, cf->origin_type, cf->name);
+               error_return = error("%s", error_msg);
+
+       free(error_msg);
+       return error_return;
 }
 
 static int parse_unit_factor(const char *end, uintmax_t *val)
@@ -619,16 +654,35 @@ int git_parse_ulong(const char *value, unsigned long *ret)
 NORETURN
 static void die_bad_number(const char *name, const char *value)
 {
-       const char *reason = errno == ERANGE ?
-                            "out of range" :
-                            "invalid unit";
+       const char * error_type = (errno == ERANGE)? _("out of range"):_("invalid unit");
+
        if (!value)
                value = "";
 
-       if (cf && cf->origin_type && cf->name)
-               die(_("bad numeric config value '%s' for '%s' in %s %s: %s"),
-                   value, name, cf->origin_type, cf->name, reason);
-       die(_("bad numeric config value '%s' for '%s': %s"), value, name, reason);
+       if (!(cf && cf->name))
+               die(_("bad numeric config value '%s' for '%s': %s"),
+                   value, name, error_type);
+
+       switch (cf->origin_type) {
+       case CONFIG_ORIGIN_BLOB:
+               die(_("bad numeric config value '%s' for '%s' in blob %s: %s"),
+                   value, name, cf->name, error_type);
+       case CONFIG_ORIGIN_FILE:
+               die(_("bad numeric config value '%s' for '%s' in file %s: %s"),
+                   value, name, cf->name, error_type);
+       case CONFIG_ORIGIN_STDIN:
+               die(_("bad numeric config value '%s' for '%s' in standard input: %s"),
+                   value, name, error_type);
+       case CONFIG_ORIGIN_SUBMODULE_BLOB:
+               die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"),
+                   value, name, cf->name, error_type);
+       case CONFIG_ORIGIN_CMDLINE:
+               die(_("bad numeric config value '%s' for '%s' in command line %s: %s"),
+                   value, name, cf->name, error_type);
+       default:
+               die(_("bad numeric config value '%s' for '%s' in %s: %s"),
+                   value, name, cf->name, error_type);
+       }
 }
 
 int git_config_int(const char *name, const char *value)
@@ -772,7 +826,12 @@ static int git_default_core_config(const char *var, const char *value)
        }
 
        if (!strcmp(var, "core.logallrefupdates")) {
-               log_all_ref_updates = git_config_bool(var, value);
+               if (value && !strcasecmp(value, "always"))
+                       log_all_ref_updates = LOG_REFS_ALWAYS;
+               else if (git_config_bool(var, value))
+                       log_all_ref_updates = LOG_REFS_NORMAL;
+               else
+                       log_all_ref_updates = LOG_REFS_NONE;
                return 0;
        }
 
@@ -782,13 +841,22 @@ static int git_default_core_config(const char *var, const char *value)
        }
 
        if (!strcmp(var, "core.abbrev")) {
-               int abbrev = git_config_int(var, value);
-               if (abbrev < minimum_abbrev || abbrev > 40)
-                       return -1;
-               default_abbrev = abbrev;
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcasecmp(value, "auto"))
+                       default_abbrev = -1;
+               else {
+                       int abbrev = git_config_int(var, value);
+                       if (abbrev < minimum_abbrev || abbrev > 40)
+                               return error("abbrev length out of range: %d", abbrev);
+                       default_abbrev = abbrev;
+               }
                return 0;
        }
 
+       if (!strcmp(var, "core.disambiguate"))
+               return set_disambiguate_hint_config(var, value);
+
        if (!strcmp(var, "core.loosecompression")) {
                int level = git_config_int(var, value);
                if (level == -1)
@@ -810,6 +878,8 @@ static int git_default_core_config(const char *var, const char *value)
                core_compression_seen = 1;
                if (!zlib_compression_seen)
                        zlib_compression_level = level;
+               if (!pack_compression_seen)
+                       pack_compression_level = level;
                return 0;
        }
 
@@ -875,9 +945,6 @@ static int git_default_core_config(const char *var, const char *value)
                return 0;
        }
 
-       if (!strcmp(var, "core.pager"))
-               return git_config_string(&pager_program, var, value);
-
        if (!strcmp(var, "core.editor"))
                return git_config_string(&editor_program, var, value);
 
@@ -1073,6 +1140,18 @@ int git_default_config(const char *var, const char *value, void *dummy)
                pack_size_limit_cfg = git_config_ulong(var, value);
                return 0;
        }
+
+       if (!strcmp(var, "pack.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 pack compression level %d"), level);
+               pack_compression_level = level;
+               pack_compression_seen = 1;
+               return 0;
+       }
+
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
 }
@@ -1105,7 +1184,8 @@ static int do_config_from(struct config_source *top, config_fn_t fn, void *data)
 }
 
 static int do_config_from_file(config_fn_t fn,
-               const char *origin_type, const char *name, const char *path, FILE *f,
+               const enum config_origin_type origin_type,
+               const char *name, const char *path, FILE *f,
                void *data)
 {
        struct config_source top;
@@ -1124,7 +1204,7 @@ static int do_config_from_file(config_fn_t fn,
 
 static int git_config_from_stdin(config_fn_t fn, void *data)
 {
-       return do_config_from_file(fn, "standard input", "", NULL, stdin, data);
+       return do_config_from_file(fn, CONFIG_ORIGIN_STDIN, "", NULL, stdin, data);
 }
 
 int git_config_from_file(config_fn_t fn, const char *filename, void *data)
@@ -1135,14 +1215,14 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
        f = fopen(filename, "r");
        if (f) {
                flockfile(f);
-               ret = do_config_from_file(fn, "file", filename, filename, f, data);
+               ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
                funlockfile(f);
                fclose(f);
        }
        return ret;
 }
 
-int git_config_from_mem(config_fn_t fn, const char *origin_type,
+int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_type,
                        const char *name, const char *buf, size_t len, void *data)
 {
        struct config_source top;
@@ -1161,10 +1241,10 @@ int git_config_from_mem(config_fn_t fn, const char *origin_type,
        return do_config_from(&top, fn, data);
 }
 
-static int git_config_from_blob_sha1(config_fn_t fn,
-                                    const char *name,
-                                    const unsigned char *sha1,
-                                    void *data)
+int git_config_from_blob_sha1(config_fn_t fn,
+                             const char *name,
+                             const unsigned char *sha1,
+                             void *data)
 {
        enum object_type type;
        char *buf;
@@ -1179,7 +1259,7 @@ static int git_config_from_blob_sha1(config_fn_t fn,
                return error("reference '%s' does not point to a blob", name);
        }
 
-       ret = git_config_from_mem(fn, "blob", name, buf, size, data);
+       ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size, data);
        free(buf);
 
        return ret;
@@ -1236,7 +1316,7 @@ static int do_git_config_sequence(config_fn_t fn, void *data)
        int ret = 0;
        char *xdg_config = xdg_config_home("config");
        char *user_config = expand_user_path("~/.gitconfig");
-       char *repo_config = git_pathdup("config");
+       char *repo_config = have_git_dir() ? git_pathdup("config") : NULL;
 
        current_parsing_scope = CONFIG_SCOPE_SYSTEM;
        if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
@@ -1390,12 +1470,12 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
        if (cf->name) {
                kv_info->filename = strintern(cf->name);
                kv_info->linenr = cf->linenr;
-               kv_info->origin_type = strintern(cf->origin_type);
+               kv_info->origin_type = cf->origin_type;
        } else {
                /* for values read from `git_config_from_parameters()` */
                kv_info->filename = NULL;
                kv_info->linenr = -1;
-               kv_info->origin_type = NULL;
+               kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
        }
        kv_info->scope = current_parsing_scope;
        si->util = kv_info;
@@ -2141,7 +2221,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
                        goto out_free;
                }
 
-               fstat(in_fd, &st);
+               if (fstat(in_fd, &st) == -1) {
+                       error_errno(_("fstat on %s failed"), config_filename);
+                       ret = CONFIG_INVALID_FILE;
+                       goto out_free;
+               }
+
                contents_sz = xsize_t(st.st_size);
                contents = xmmap_gently(NULL, contents_sz, PROT_READ,
                                        MAP_PRIVATE, in_fd, 0);
@@ -2343,7 +2428,7 @@ int git_config_rename_section_in_file(const char *config_filename,
 
        if (new_name && !section_name_is_ok(new_name)) {
                ret = error("invalid section name: %s", new_name);
-               goto out;
+               goto out_no_rollback;
        }
 
        if (!config_filename)
@@ -2358,10 +2443,13 @@ int git_config_rename_section_in_file(const char *config_filename,
 
        if (!(config_file = fopen(config_filename, "rb"))) {
                /* no config file means nothing to rename, no error */
-               goto unlock_and_out;
+               goto commit_and_out;
        }
 
-       fstat(fileno(config_file), &st);
+       if (fstat(fileno(config_file), &st) == -1) {
+               ret = error_errno(_("fstat on %s failed"), config_filename);
+               goto out;
+       }
 
        if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
                ret = error_errno("chmod on %s failed",
@@ -2417,11 +2505,13 @@ int git_config_rename_section_in_file(const char *config_filename,
                }
        }
        fclose(config_file);
-unlock_and_out:
+commit_and_out:
        if (commit_lock_file(lock) < 0)
                ret = error_errno("could not write config file %s",
                                  config_filename);
 out:
+       rollback_lock_file(lock);
+out_no_rollback:
        free(filename_buf);
        return ret;
 }
@@ -2476,14 +2566,28 @@ int parse_config_key(const char *var,
 
 const char *current_config_origin_type(void)
 {
-       const char *type;
+       int type;
        if (current_config_kvi)
                type = current_config_kvi->origin_type;
        else if(cf)
                type = cf->origin_type;
        else
                die("BUG: current_config_origin_type called outside config callback");
-       return type ? type : "command line";
+
+       switch (type) {
+       case CONFIG_ORIGIN_BLOB:
+               return "blob";
+       case CONFIG_ORIGIN_FILE:
+               return "file";
+       case CONFIG_ORIGIN_STDIN:
+               return "standard input";
+       case CONFIG_ORIGIN_SUBMODULE_BLOB:
+               return "submodule-blob";
+       case CONFIG_ORIGIN_CMDLINE:
+               return "command line";
+       default:
+               die("BUG: unknown config origin type");
+       }
 }
 
 const char *current_config_name(void)