Skip to content

Commit b2dc094

Browse files
hvoigtgitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1bc8881 commit b2dc094

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

config.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct config_source {
2121
} buf;
2222
} u;
2323
const char *name;
24+
int die_on_error;
2425
int linenr;
2526
int eof;
2627
struct strbuf value;
@@ -442,7 +443,10 @@ static int git_parse_source(config_fn_t fn, void *data)
442443
if (get_value(fn, data, var) < 0)
443444
break;
444445
}
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);
446450
}
447451

448452
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)
940944
}
941945

942946
/*
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
944948
* fgetc, ungetc, ftell of top need to be initialized before calling
945949
* this function.
946950
*/
@@ -977,6 +981,7 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
977981

978982
top.u.file = f;
979983
top.name = filename;
984+
top.die_on_error = 1;
980985
top.fgetc = config_file_fgetc;
981986
top.ungetc = config_file_ungetc;
982987
top.ftell = config_file_ftell;
@@ -997,6 +1002,7 @@ int git_config_from_buf(config_fn_t fn, const char *name, const char *buf,
9971002
top.u.buf.len = len;
9981003
top.u.buf.pos = 0;
9991004
top.name = name;
1005+
top.die_on_error = 0;
10001006
top.fgetc = config_buf_fgetc;
10011007
top.ungetc = config_buf_ungetc;
10021008
top.ftell = config_buf_ftell;

0 commit comments

Comments
 (0)