1. 09 4月, 2018 9 次提交
    • J
      git_config_set: reuse empty sections · c71d8bb3
      Johannes Schindelin 提交于
      It can happen quite easily that the last setting in a config section is
      removed, and to avoid confusion when there are comments in the config
      about that section, we keep a lone section header, i.e. an empty
      section.
      
      Now that we use the `event_fn` callback, it is easy to add support for
      re-using empty sections, so let's do that.
      
      Note: t5512-ls-remote requires that this change is applied *after* the
      patch "git config --unset: remove empty sections (in the common case)":
      without that patch, there would be empty `transfer` and `uploadpack`
      sections ready for reuse, but in the *wrong* order (and sconsequently,
      t5512's "overrides work between mixed transfer/upload-pack hideRefs"
      would fail).
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c71d8bb3
    • J
      git config --unset: remove empty sections (in the common case) · 22aedfcc
      Johannes Schindelin 提交于
      The original reasoning for not removing section headers upon removal of
      the last entry went like this: the user could have added comments about
      the section, or about the entries therein, and if there were other
      comments there, we would not know whether we should remove them.
      
      In particular, a concocted example was presented that looked like this
      (and was added to t1300):
      
      	# some generic comment on the configuration file itself
      	# a comment specific to this "section" section.
      	[section]
      	# some intervening lines
      	# that should also be dropped
      
      	key = value
      	# please be careful when you update the above variable
      
      The ideal thing for `git config --unset section.key` in this case would
      be to leave only the first line behind, because all the other comments
      are now obsolete.
      
      However, this is unfeasible, short of adding a complete Natural Language
      Processing module to Git, which seems not only a lot of work, but a
      totally unreasonable feature (for little benefit to most users).
      
      Now, the real kicker about this problem is: most users do not edit their
      config files at all! In their use case, the config looks like this
      instead:
      
      	[section]
      		key = value
      
      ... and it is totally obvious what should happen if the entry is
      removed: the entire section should vanish.
      
      Let's generalize this observation to this conservative strategy: if we
      are removing the last entry from a section, and there are no comments
      inside that section nor surrounding it, then remove the entire section.
      Otherwise behave as before: leave the now-empty section (including those
      comments, even ones about the now-deleted entry).
      
      We have to be extra careful to handle the case where more than one entry
      is removed: any subset of them might be the last entries of their
      respective sections (and if there are no comments in or around that
      section, the section should be removed, too).
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      22aedfcc
    • 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
    • J
      git_config_set: do not use a state machine · 5221c315
      Johannes Schindelin 提交于
      While a neat theoretical construct, state machines are hard to read. In
      this instance, it does not even make a whole lot of sense because we are
      more interested in flags, anyway: has the section been seen? Has the key
      been seen? Does the current section match the key we are looking for?
      
      Besides, the state `SECTION_SEEN` was named in a misleading way: it did
      not indicate that we saw the section matching the key we are looking
      for, but it instead indicated that we are *currently* in that section.
      
      Let's just replace the state machine logic by clear and obvious flags.
      
      This will also make it easier to review the upcoming patches to use the
      newly-introduced `event_fn` callback of the config parser.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5221c315
    • J
      config_set_store: rename some fields for consistency · 668b9ade
      Johannes Schindelin 提交于
      The `seen` field is the actual length of the `offset` array, and the
      `offset_alloc` field records what was allocated (to avoid resizing
      wherever `seen` has to be incremented).
      
      Elsewhere, we use the convention `name` for the array, where `name` is
      descriptive enough to guess its purpose, `name_nr` for the actual length
      and `name_alloc` to record the maximum length without needing to resize.
      
      Let's make the names of the fields in question consistent with that
      convention.
      
      This will also help with the next steps where we will let the
      git_config_set() machinery use the config event stream that we just
      introduced.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      668b9ade
    • J
      config: avoid using the global variable `store` · fee8572c
      Johannes Schindelin 提交于
      It is much easier to reason about, when the config code to set/unset
      variables or to remove/rename sections does not rely on a global (or
      file-local) variable.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fee8572c
    • J
      config: introduce an optional event stream while parsing · 8032cc44
      Johannes Schindelin 提交于
      This extends our config parser so that it can optionally produce an event
      stream via callback function, where it reports e.g. when a comment was
      parsed, or a section header, etc.
      
      This parser will be used subsequently to handle the scenarios better where
      removing config entries would make sections empty, or where a new entry
      could be added to an already-existing, empty section.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8032cc44
    • J
      t1300: `--unset-all` can leave an empty section behind (bug) · b73bdc34
      Johannes Schindelin 提交于
      We already have a test demonstrating that removing the last entry from a
      config section fails to remove the section header of the now-empty
      section.
      
      The same can happen, of course, if we remove the last entries in one fell
      swoop. This is *also* a bug, and should be fixed at the same time.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b73bdc34
    • J
      t1300: add a few more hairy examples of sections becoming empty · 422e8ef2
      Johannes Schindelin 提交于
      During the review of the first iteration of the patch series to remove
      sections that become empty upon --unset or --unset-all, Jeff King
      identified a couple of problematic cases with the backtracking approach
      that was still used then to "look backwards for the section header":
      https://public-inbox.org/git/20180329213229.GG2939@sigill.intra.peff.net/
      
      This patch adds a couple of concocted examples designed to fool a
      backtracking parser.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      422e8ef2
  2. 06 4月, 2018 6 次提交
  3. 23 3月, 2018 25 次提交