]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/empty-config-section-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:18 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:18 +0000 (15:59 +0900)
"git config --unset a.b", when "a.b" is the last variable in an
otherwise empty section "a", left an empty section "a" behind, and
worse yet, a subsequent "git config a.c value" did not reuse that
empty shell and instead created a new one.  These have been
(partially) corrected.

* js/empty-config-section-fix:
  git_config_set: reuse empty sections
  git config --unset: remove empty sections (in the common case)
  git_config_set: make use of the config parser's event stream
  git_config_set: do not use a state machine
  config_set_store: rename some fields for consistency
  config: avoid using the global variable `store`
  config: introduce an optional event stream while parsing
  t1300: `--unset-all` can leave an empty section behind (bug)
  t1300: add a few more hairy examples of sections becoming empty
  t1300: remove unreasonable expectation from TODO
  t1300: avoid relying on a bug
  config --replace-all: avoid extra line breaks
  t1300: demonstrate that --replace-all can "invent" newlines
  t1300: rename it to reflect that `repo-config` was deprecated
  git_config_set: fix off-by-two

1  2 
config.c
t/t1300-config.sh

diff --cc config.c
index 62c56099bf82c44aefc7f4dcdba207a66ad76cd7,d4527beb44591983ce0131851bd596209d487b47..5687e2d23e5ae1e3f2110875ee71318d1cf345a6
+++ b/config.c
@@@ -1423,10 -1483,9 +1491,10 @@@ static int do_config_from(struct config
  static int do_config_from_file(config_fn_t fn,
                const enum config_origin_type origin_type,
                const char *name, const char *path, FILE *f,
-               void *data)
+               void *data, const struct config_options *opts)
  {
        struct config_source top;
 +      int ret;
  
        top.u.file = f;
        top.origin_type = origin_type;
        top.do_ungetc = config_file_ungetc;
        top.do_ftell = config_file_ftell;
  
 -      return do_config_from(&top, fn, data, opts);
 +      flockfile(f);
-       ret = do_config_from(&top, fn, data);
++      ret = do_config_from(&top, fn, data, opts);
 +      funlockfile(f);
 +      return ret;
  }
  
  static int git_config_from_stdin(config_fn_t fn, void *data)
@@@ -1455,7 -1514,10 +1526,8 @@@ int git_config_from_file_with_options(c
  
        f = fopen_or_warn(filename, "r");
        if (f) {
-               ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
 -              flockfile(f);
+               ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,
+                                         filename, f, data, opts);
 -              funlockfile(f);
                fclose(f);
        }
        return ret;
Simple merge