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>

Matthieu Moy committed Aug 7, 2014 at 04:59 UTC b3b3f60bb672d23b9db1582395a1d29561cb79ef
1 file changed +11 -1
config.c
+11 -1
@@ -244,6 +244,7 @@ static int get_next_char(void)
244 cf->linenr++;
245 if (c == EOF) {
246 cf->eof = 1;
247 + cf->linenr++;
248 c = '\n';
249 }
250 return c;
@@ -319,6 +320,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
320 {
321 int c;
322 char *value;
323 + int ret;
324
325 /* Get the full name */
326 for (;;) {
@@ -341,7 +343,15 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
343 if (!value)
344 return -1;
345 }
344 - return fn(name->buf, value, data);
346 + /*
347 + * We already consumed the \n, but we need linenr to point to
348 + * the line we just parsed during the call to fn to get
349 + * accurate line number in error messages.
350 + */
351 + cf->linenr--;
352 + ret = fn(name->buf, value, data);
353 + cf->linenr++;
354 + return ret;
355 }
356
357 static int get_extended_base_var(struct strbuf *name, int c)