do not die when error in config parsing of buf occurs
If a config parsing error in a file occurs we can die and let the user fix the issue. This is different for the buf parsing function since it can be used to parse blobs of .gitmodules files. If a parsing error occurs here we should proceed since otherwise a database containing such an error in a single revision could be rendered unusable. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Heiko Voigt committed
Jul 12, 2013 at 00:48 UTC
b2dc09455a9ed5521c2e84fc67d8dacf2c28c39f
1 file changed
+8
-2
config.c
+8
-2
@@ -21,6 +21,7 @@ struct config_source {
21
} buf;
22
} u;
23
const char *name;
24
+ int die_on_error;
25
int linenr;
26
int eof;
27
struct strbuf value;
@@ -442,7 +443,10 @@ static int git_parse_source(config_fn_t fn, void *data)
443
if (get_value(fn, data, var) < 0)
444
break;
445
}
445
- die("bad config file line %d in %s", cf->linenr, cf->name);
446
+ if (cf->die_on_error)
447
+ die("bad config file line %d in %s", cf->linenr, cf->name);
448
+ else
449
+ return error("bad config file line %d in %s", cf->linenr, cf->name);
450
}
451
452
static int parse_unit_factor(const char *end, uintmax_t *val)
@@ -940,7 +944,7 @@ int git_default_config(const char *var, const char *value, void *dummy)
944
}
945
946
/*
943
- * All source specific fields in the union, name and the callbacks
947
+ * All source specific fields in the union, die_on_error, name and the callbacks
948
* fgetc, ungetc, ftell of top need to be initialized before calling
949
* this function.
950
*/
@@ -977,6 +981,7 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
981
982
top.u.file = f;
983
top.name = filename;
984
+ top.die_on_error = 1;
985
top.fgetc = config_file_fgetc;
986
top.ungetc = config_file_ungetc;
987
top.ftell = config_file_ftell;
@@ -997,6 +1002,7 @@ int git_config_from_buf(config_fn_t fn, const char *name, const char *buf,
1002
top.u.buf.len = len;
1003
top.u.buf.pos = 0;
1004
top.name = name;
1005
+ top.die_on_error = 0;
1006
top.fgetc = config_buf_fgetc;
1007
top.ungetc = config_buf_ungetc;
1008
top.ftell = config_buf_ftell;