config.c: fix accuracy of line number in errors
If a callback returns a negative value to `git_config*()` family, they call `die()` while printing the line number and the file name. Currently the printed line number is off by one, thus printing the wrong line number. Make `linenr` point to the line we just parsed during the call to callback to get accurate line number in error messages. Commit-message-by: Tanay Abhra <tanayabh@gmail.com> Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
8262aaa283
commit
b3b3f60bb6
12
config.c
12
config.c
|
@ -244,6 +244,7 @@ static int get_next_char(void)
|
||||||
cf->linenr++;
|
cf->linenr++;
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
cf->eof = 1;
|
cf->eof = 1;
|
||||||
|
cf->linenr++;
|
||||||
c = '\n';
|
c = '\n';
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
|
@ -319,6 +320,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
char *value;
|
char *value;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Get the full name */
|
/* Get the full name */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -341,7 +343,15 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
|
||||||
if (!value)
|
if (!value)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return fn(name->buf, value, data);
|
/*
|
||||||
|
* We already consumed the \n, but we need linenr to point to
|
||||||
|
* the line we just parsed during the call to fn to get
|
||||||
|
* accurate line number in error messages.
|
||||||
|
*/
|
||||||
|
cf->linenr--;
|
||||||
|
ret = fn(name->buf, value, data);
|
||||||
|
cf->linenr++;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_extended_base_var(struct strbuf *name, int c)
|
static int get_extended_base_var(struct strbuf *name, int c)
|
||||||
|
|
Loading…
Reference in New Issue