summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/notes.c5
-rw-r--r--cache.h12
-rw-r--r--config.c117
-rw-r--r--submodule-config.c2
4 files changed, 112 insertions, 24 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 0572051762..f848b89692 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -91,7 +91,7 @@ static const char * const git_notes_get_ref_usage[] = {
};
static const char note_template[] =
- "\nWrite/edit the notes for the following object:\n";
+ N_("Write/edit the notes for the following object:");
struct note_data {
int given;
@@ -179,7 +179,8 @@ static void prepare_note_data(const unsigned char *object, struct note_data *d,
copy_obj_to_fd(fd, old_note);
strbuf_addch(&buf, '\n');
- strbuf_add_commented_lines(&buf, note_template, strlen(note_template));
+ strbuf_add_commented_lines(&buf, "\n", strlen("\n"));
+ strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)));
strbuf_addch(&buf, '\n');
write_or_die(fd, buf.buf, buf.len);
diff --git a/cache.h b/cache.h
index 6cddf2c1de..e8128fc5d6 100644
--- a/cache.h
+++ b/cache.h
@@ -1567,10 +1567,18 @@ struct git_config_source {
const char *blob;
};
+enum config_origin_type {
+ CONFIG_ORIGIN_BLOB,
+ CONFIG_ORIGIN_FILE,
+ CONFIG_ORIGIN_STDIN,
+ CONFIG_ORIGIN_SUBMODULE_BLOB,
+ CONFIG_ORIGIN_CMDLINE
+};
+
typedef int (*config_fn_t)(const char *, const char *, void *);
extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *);
-extern int git_config_from_mem(config_fn_t fn, const char *origin_type,
+extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
const char *name, const char *buf, size_t len, void *data);
extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data);
@@ -1714,7 +1722,7 @@ extern int ignore_untracked_cache_config;
struct key_value_info {
const char *filename;
int linenr;
- const char *origin_type;
+ enum config_origin_type origin_type;
enum config_scope scope;
};
diff --git a/config.c b/config.c
index bea937e4ec..584cacf148 100644
--- 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;
@@ -245,6 +245,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 +454,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 +510,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 +652,47 @@ 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";
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(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s': out of range")
+ : _("bad numeric config value '%s' for '%s': invalid unit"),
+ value, name);
+
+ switch (cf->origin_type) {
+ case CONFIG_ORIGIN_BLOB:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in blob %s: out of range")
+ : _("bad numeric config value '%s' for '%s' in blob %s: invalid unit"),
+ value, name, cf->name);
+ case CONFIG_ORIGIN_FILE:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in file %s: out of range")
+ : _("bad numeric config value '%s' for '%s' in file %s: invalid unit"),
+ value, name, cf->name);
+ case CONFIG_ORIGIN_STDIN:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in standard input: out of range")
+ : _("bad numeric config value '%s' for '%s' in standard input: invalid unit"),
+ value, name);
+ case CONFIG_ORIGIN_SUBMODULE_BLOB:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in submodule-blob %s: out of range")
+ : _("bad numeric config value '%s' for '%s' in submodule-blob %s: invalid unit"),
+ value, name, cf->name);
+ case CONFIG_ORIGIN_CMDLINE:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in command line %s: out of range")
+ : _("bad numeric config value '%s' for '%s' in command line %s: invalid unit"),
+ value, name, cf->name);
+ default:
+ die(errno == ERANGE
+ ? _("bad numeric config value '%s' for '%s' in %s: out of range")
+ : _("bad numeric config value '%s' for '%s' in %s: invalid unit"),
+ value, name, cf->name);
+ }
}
int git_config_int(const char *name, const char *value)
@@ -1105,7 +1169,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 +1189,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 +1200,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;
@@ -1179,7 +1244,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;
@@ -1390,12 +1455,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;
@@ -2476,14 +2541,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)
diff --git a/submodule-config.c b/submodule-config.c
index faedb1a489..d22a851d27 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -442,7 +442,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
parameter.commit_sha1 = commit_sha1;
parameter.gitmodules_sha1 = sha1;
parameter.overwrite = 0;
- git_config_from_mem(parse_config, "submodule-blob", rev.buf,
+ git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
config, config_size, &parameter);
strbuf_release(&rev);
free(config);