• J
    git_config_set: make use of the config parser's event stream · 6ae996f2
    Johannes Schindelin 提交于
    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: NJohannes Schindelin <johannes.schindelin@gmx.de>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    6ae996f2
config.c 74.5 KB