git_config_set: make use of the config parser's event stream
commit6ae996f2acf3ad780b8d338c81e24143f0b0d304
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 9 Apr 2018 08:32:20 +0000 (9 10:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Apr 2018 12:32:59 +0000 (9 21:32 +0900)
tree64b0f793e04da372748d20c6b8d151da2c67b39b
parent5221c3159f670281ff36b6adbdf568661e930b50
git_config_set: make use of the config parser's event stream

In the recent commit with the title "config: introduce an optional event
stream while parsing", we introduced an optional callback to keep track
of the config parser's events "comment", "white-space", "section header"
and "entry".

One motivation for this feature was to make use of it in the code that
edits the config. And this commit makes it so.

Note: this patch changes the meaning of the `seen` array that records
whether we saw the config entry that is to be edited: previously, it
contained the end offset of the found entry. Now, we introduce a new
array `parsed` that keeps a record of *all* config parser events (with
begin/end offsets), and the items in the `seen` array now point into the
`parsed` array.

There are two reasons why we do it this way:

1. To keep the implementation simple, the config parser's event stream
   reports the event only after the config callback was called, so we
   would not receive the begin offset otherwise.

2. In the following patches, we will re-use the `parsed` array to fix two
   long-standing bugs related to empty sections.

Note that this also makes the code more robust with respect to finding the
begin offset of the part(s) of the config file to be edited, as we no
longer back-track to find the beginning of the line.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c