git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 00/11] config: remove global state from config iteration

From
Glen Choo via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 28, 2023, 19:26 UTC
Message-ID
<pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
In-Reply-To
<pull.1497.v4.git.git.1687803083.gitgitgadget@gmail.com>
As promised, this version addresses the comments on v3.
= Changes since v4
- Squash 6-7/12 since `test_must_fail` doesn't catch BUG()
- Move a hunk to later in the series where it belongs
- Replace a memcpy with `*a = *b`
= Changes since v3
- Rebase onto newer 'master'
- Move the 'remove UNUSED from tr2_cfg_cb' hunk from 9/12 -> 8/12. It should
  have been there all along; v3 8/12 didn't build at all.
Glen Choo (11):
  config: inline git_color_default_config
  urlmatch.h: use config_fn_t type
  config: add ctx arg to config_fn_t
  config.c: pass ctx in configsets
  config: pass ctx with config files
  config.c: pass ctx with CLI config
  trace2: plumb config kvi
  config: pass kvi to die_bad_number()
  config.c: remove config_reader from configsets
  config: add kvi.path, use it to evaluate includes
  config: pass source to config_parser_event_fn_t
 alias.c                                       |   3 +-
 archive-tar.c                                 |   5 +-
 archive-zip.c                                 |   1 +
 builtin/add.c                                 |   8 +-
 builtin/blame.c                               |   5 +-
 builtin/branch.c                              |   8 +-
 builtin/cat-file.c                            |   5 +-
 builtin/checkout.c                            |  12 +-
 builtin/clean.c                               |   9 +-
 builtin/clone.c                               |  11 +-
 builtin/column.c                              |   3 +-
 builtin/commit-graph.c                        |   3 +-
 builtin/commit.c                              |  20 +-
 builtin/config.c                              |  72 ++-
 builtin/difftool.c                            |   5 +-
 builtin/fetch.c                               |  13 +-
 builtin/fsmonitor--daemon.c                   |  11 +-
 builtin/grep.c                                |  12 +-
 builtin/help.c                                |   5 +-
 builtin/index-pack.c                          |   9 +-
 builtin/log.c                                 |  12 +-
 builtin/merge.c                               |   7 +-
 builtin/multi-pack-index.c                    |   1 +
 builtin/pack-objects.c                        |  19 +-
 builtin/patch-id.c                            |   5 +-
 builtin/pull.c                                |   5 +-
 builtin/push.c                                |   5 +-
 builtin/read-tree.c                           |   5 +-
 builtin/rebase.c                              |   5 +-
 builtin/receive-pack.c                        |  15 +-
 builtin/reflog.c                              |   7 +-
 builtin/remote.c                              |  15 +-
 builtin/repack.c                              |   5 +-
 builtin/reset.c                               |   5 +-
 builtin/send-pack.c                           |   5 +-
 builtin/show-branch.c                         |   8 +-
 builtin/stash.c                               |   5 +-
 builtin/submodule--helper.c                   |   3 +-
 builtin/tag.c                                 |   9 +-
 builtin/var.c                                 |   5 +-
 builtin/worktree.c                            |   5 +-
 bundle-uri.c                                  |   9 +-
 color.c                                       |   8 -
 color.h                                       |   6 +-
 compat/mingw.c                                |   3 +-
 compat/mingw.h                                |   4 +-
 config.c                                      | 552 +++++++-----------
 config.h                                      |  80 ++-
 connect.c                                     |   4 +-
 .../coccinelle/config_fn_ctx.pending.cocci    | 144 +++++
 contrib/coccinelle/git_config_number.cocci    |  27 +
 convert.c                                     |   4 +-
 credential.c                                  |   1 +
 delta-islands.c                               |   4 +-
 diff.c                                        |  19 +-
 diff.h                                        |   7 +-
 fetch-pack.c                                  |   5 +-
 fmt-merge-msg.c                               |   7 +-
 fmt-merge-msg.h                               |   3 +-
 fsck.c                                        |  12 +-
 fsck.h                                        |   4 +-
 git-compat-util.h                             |   2 +
 gpg-interface.c                               |   7 +-
 grep.c                                        |   7 +-
 grep.h                                        |   4 +-
 help.c                                        |   9 +-
 http.c                                        |  15 +-
 ident.c                                       |   4 +-
 ident.h                                       |   4 +-
 imap-send.c                                   |   7 +-
 ll-merge.c                                    |   1 +
 ls-refs.c                                     |   1 +
 mailinfo.c                                    |   5 +-
 notes-utils.c                                 |   4 +-
 notes.c                                       |   4 +-
 pager.c                                       |   5 +-
 pretty.c                                      |   1 +
 promisor-remote.c                             |   4 +-
 remote.c                                      |   8 +-
 revision.c                                    |   4 +-
 scalar.c                                      |   4 +-
 sequencer.c                                   |  29 +-
 setup.c                                       |  18 +-
 submodule-config.c                            |  31 +-
 submodule-config.h                            |   3 +-
 t/helper/test-config.c                        |  24 +-
 t/helper/test-userdiff.c                      |   4 +-
 t/t1300-config.sh                             |  27 +
 trace2.c                                      |   4 +-
 trace2.h                                      |   3 +-
 trace2/tr2_cfg.c                              |  16 +-
 trace2/tr2_sysenv.c                           |   3 +-
 trace2/tr2_tgt.h                              |   4 +-
 trace2/tr2_tgt_event.c                        |   4 +-
 trace2/tr2_tgt_normal.c                       |   4 +-
 trace2/tr2_tgt_perf.c                         |   4 +-
 trailer.c                                     |   2 +
 upload-pack.c                                 |  18 +-
 urlmatch.c                                    |   7 +-
 urlmatch.h                                    |   8 +-
 worktree.c                                    |   2 +-
 xdiff-interface.c                             |   5 +-
 xdiff-interface.h                             |   4 +-
 103 files changed, 960 insertions(+), 638 deletions(-)
 create mode 100644 contrib/coccinelle/config_fn_ctx.pending.cocci
 create mode 100644 contrib/coccinelle/git_config_number.cocci
base-commit: 6ff334181cfb6485d3ba50843038209a2a253907
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1497%2Fchooglen%2Fconfig%2Fno-global-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1497/chooglen/config/no-global-v5
Pull-Request: https://github.com/git/git/pull/1497
Range-diff vs v4:
  1:  7bfffb454c5 =  1:  7bfffb454c5 config: inline git_color_default_config
  2:  739c519ce62 =  2:  739c519ce62 urlmatch.h: use config_fn_t type
  3:  a9a0a50f32a =  3:  a9a0a50f32a config: add ctx arg to config_fn_t
  4:  39b2e291f86 =  4:  39b2e291f86 config.c: pass ctx in configsets
  5:  bfc6d2833c5 =  5:  bfc6d2833c5 config: pass ctx with config files
  6:  897bdc759b5 <  -:  ----------- builtin/config.c: test misuse of format_config()
  7:  33e4437737d !  6:  7b24eefbcf3 config.c: pass ctx with CLI config
     @@ Commit message
          * git_config_parse_parameter() hasn't been setting config source
            information, so plumb "kvi" there too.
      
     -    * "git config --get-urlmatch --show-scope" iterates config to collect
     -      values, but then attempts to display the scope after config iteration.
     -      Fix this by copying the "kvi" value in the collection phase so that it
     -      can be read back later. This means that we can now support "git config
     -      --get-urlmatch --show-origin" (we don't allow this combination of args
     -      because of this bug), but that is left unchanged for now.
     +    * Several sites in builtin/config.c have been calling current_config_*()
     +      functions outside of config callbacks (indirectly, via the
     +      format_config() helper), which means they're reading state that isn't
     +      set correctly:
      
     -    * "git config --default" doesn't have config source metadata when
     -      displaying the default value. Fix this by treating the default value
     -      as if it came from the command line (e.g. like we do with "git -c" or
     -      "git config --file"), using kvi_from_param().
     +      * "git config --get-urlmatch --show-scope" iterates config to collect
     +        values, but then attempts to display the scope after config
     +        iteration, causing the "unknown" scope to be shown instead of the
     +        config file's scope. It's clear that this wasn't intended: we knew
     +        that "--get-urlmatch" couldn't show config source metadata, which is
     +        why "--show-origin" was marked incompatible with "--get-urlmatch"
     +        when it was introduced [1]. It was most likely a mistake that we
     +        allowed "--show-scope" to sneak through.
     +
     +        Fix this by copying the "kvi" value in the collection phase so that
     +        it can be read back later. This means that we can now support "git
     +        config --get-urlmatch --show-origin", but that is left unchanged
     +        for now.
     +
     +      * "git config --default" doesn't have config source metadata when
     +        displaying the default value, so "--show-scope" also results in
     +        "unknown", and "--show-origin" results in a BUG(). Fix this by
     +        treating the default value as if it came from the command line (e.g.
     +        like we do with "git -c" or "git config --file"), using
     +        kvi_from_param().
     +
     +    [1] https://lore.kernel.org/git/20160205112001.GA13397@sigill.intra.peff.net/
      
          Signed-off-by: Glen Choo <chooglen@google.com>
      
     @@ config.c: static int configset_find_element(struct config_set *set, const char *
       			       const char *value)
       {
      @@ config.c: static int configset_add_value(struct config_reader *reader,
     - 	l_item->e = e;
     - 	l_item->value_index = e->value_list.nr - 1;
     - 
     --	if (!reader->source)
     --		BUG("configset_add_value has no source");
     + 	if (!reader->source)
     + 		BUG("configset_add_value has no source");
       	if (reader->source->name) {
      -		kvi_from_source(reader->source, current_config_scope(), kv_info);
      +		kvi_from_source(reader->source, kvi_p->scope, kv_info);
     @@ config.h: void git_global_config(char **user, char **xdg);
        * Match and parse a config key of the form:
      
       ## t/t1300-config.sh ##
     -@@ t/t1300-config.sh: test_expect_success 'urlmatch with --show-scope' '
     - 	EOF
     +@@ t/t1300-config.sh: test_expect_success 'urlmatch' '
     + 	test_cmp expect actual
     + '
       
     - 	cat >expect <<-EOF &&
     --	unknown	http.cookiefile /tmp/cookie.txt
     --	unknown	http.sslverify false
     ++test_expect_success 'urlmatch with --show-scope' '
     ++	cat >.git/config <<-\EOF &&
     ++	[http "https://weak.example.com"]
     ++		sslVerify = false
     ++		cookieFile = /tmp/cookie.txt
     ++	EOF
     ++
     ++	cat >expect <<-EOF &&
      +	local	http.cookiefile /tmp/cookie.txt
      +	local	http.sslverify false
     - 	EOF
     - 	git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
     - 	test_cmp expect actual
     ++	EOF
     ++	git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
     ++	test_cmp expect actual
     ++'
     ++
     + test_expect_success 'urlmatch favors more specific URLs' '
     + 	cat >.git/config <<-\EOF &&
     + 	[http "https://example.com/"]
      @@ t/t1300-config.sh: test_expect_success '--show-origin blob ref' '
     + 	test_cmp expect output
       '
       
     - test_expect_success '--show-origin with --default' '
     --	test_must_fail git config --show-origin --default foo some.key
     ++test_expect_success '--show-origin with --default' '
      +	git config --show-origin --default foo some.key >actual &&
      +	echo "command line:	foo" >expect &&
      +	test_cmp expect actual
     - '
     - 
     ++'
     ++
       test_expect_success '--show-scope with --list' '
     + 	cat >expect <<-EOF &&
     + 	global	user.global=true
      @@ t/t1300-config.sh: test_expect_success '--show-scope with --show-origin' '
     - 
     - test_expect_success '--show-scope with --default' '
     - 	git config --show-scope --default foo some.key >actual &&
     --	echo "unknown	foo" >expect &&
     -+	echo "command	foo" >expect &&
     - 	test_cmp expect actual
     + 	test_cmp expect output
       '
       
     ++test_expect_success '--show-scope with --default' '
     ++	git config --show-scope --default foo some.key >actual &&
     ++	echo "command	foo" >expect &&
     ++	test_cmp expect actual
     ++'
     ++
     + test_expect_success 'override global and system config' '
     + 	test_when_finished rm -f \"\$HOME\"/.gitconfig &&
     + 	cat >"$HOME"/.gitconfig <<-EOF &&
  8:  9bd5f60282c =  7:  7d64dcbdade trace2: plumb config kvi
  9:  114723ee4a7 =  8:  9e71c10ca0a config: pass kvi to die_bad_number()
 10:  807057b6d7f !  9:  4776600e790 config.c: remove config_reader from configsets
     @@ config.c: static int configset_add_value(const struct key_value_info *kvi_p,
       	l_item->e = e;
       	l_item->value_index = e->value_list.nr - 1;
       
     +-	if (!reader->source)
     +-		BUG("configset_add_value has no source");
      -	if (reader->source->name) {
      -		kvi_from_source(reader->source, kvi_p->scope, kv_info);
      -	} else {
      -		kvi_from_param(kv_info);
      -	}
     -+	memcpy(kv_info, kvi_p, sizeof(struct key_value_info));
     ++	*kv_info = *kvi_p;
       	si->util = kv_info;
       
       	return 0;
 11:  3f0f84df972 = 10:  2b33977aba6 config: add kvi.path, use it to evaluate includes
 12:  fe2f154fe8b = 11:  8347d3c9b80 config: pass source to config_parser_event_fn_t
-- 
gitgitgadget
Previous: Junio C HamanoNext: Glen Choo via GitGitGadget
Message 101 of 115 in “[RFC] config: remove global state from config iteration”
  1. 00/14 [RFC] config: remove global state from config iterationGlen Choo via GitGitGadget, Apr 21, 2023
  2. 01/14 config.c: introduce kvi_fn(), use it for configsetsGlen Choo via GitGitGadget, Apr 21, 2023
  3. 02/14 config.c: use kvi for CLI configGlen Choo via GitGitGadget, Apr 21, 2023
  4. Ævar Arnfjörð BjarmasonMay 1, 2023
  5. 06/14 config: inline git_color_default_configGlen Choo via GitGitGadget, Apr 21, 2023
  6. 03/14 config: use kvi for config filesGlen Choo via GitGitGadget, Apr 21, 2023
  7. 04/14 config: add kvi.path, use it to evaluate includesGlen Choo via GitGitGadget, Apr 21, 2023
  8. 05/14 config: pass source to config_parser_event_fn_tGlen Choo via GitGitGadget, Apr 21, 2023
  9. 07/14 urlmatch.h: use config_fn_t typeGlen Choo via GitGitGadget, Apr 21, 2023
  10. 08/14 (RFC-only) config: add kvi arg to config_fn_tGlen Choo via GitGitGadget, Apr 21, 2023
  11. 10/14 (RFC-only) config: finish config_fn_t refactorGlen Choo via GitGitGadget, Apr 21, 2023
  12. Ævar Arnfjörð BjarmasonMay 1, 2023
  13. Jonathan TanMay 5, 2023
  14. Glen ChooMay 9, 2023
  15. Jonathan TanMay 11, 2023
  16. Glen ChooMay 8, 2023
  17. 11/14 config: remove current_config_(line|name|origin_type)Glen Choo via GitGitGadget, Apr 21, 2023
  18. 14/14 config: remove config_reader from configset_add_valueGlen Choo via GitGitGadget, Apr 21, 2023
  19. 12/14 config: remove current_config_scope()Glen Choo via GitGitGadget, Apr 21, 2023
  20. 09/14 (RFC-only) config: apply cocci to config_fn_t implementationsGlen Choo via GitGitGadget, Apr 21, 2023
  21. 13/14 config: pass kvi to die_bad_number()Glen Choo via GitGitGadget, Apr 21, 2023
  22. 00/14 [RFC] config: remove global state from config iterationGlen Choo via GitGitGadget, May 30, 2023
  23. 01/14 config: inline git_color_default_configGlen Choo via GitGitGadget, May 30, 2023
  24. 02/14 urlmatch.h: use config_fn_t typeGlen Choo via GitGitGadget, May 30, 2023
  25. 03/14 (RFC-only) config: add kvi arg to config_fn_tGlen Choo via GitGitGadget, May 30, 2023
  26. Phillip WoodJun 1, 2023
  27. Glen ChooJun 1, 2023
  28. Phillip WoodJun 2, 2023
  29. Glen ChooJun 2, 2023
  30. Phillip WoodJun 5, 2023
  31. Glen ChooJun 9, 2023
  32. 08/14 builtin/config.c: test misuse of format_config()Glen Choo via GitGitGadget, May 30, 2023
  33. 06/14 config.c: pass kvi in configsetsGlen Choo via GitGitGadget, May 30, 2023
  34. Jonathan TanJun 1, 2023
  35. 05/14 (RFC-only) config: finish config_fn_t refactorGlen Choo via GitGitGadget, May 30, 2023
  36. Jonathan TanJun 1, 2023
  37. 07/14 config: provide kvi with config filesGlen Choo via GitGitGadget, May 30, 2023
  38. Jonathan TanJun 1, 2023
  39. Jonathan TanJun 1, 2023
  40. 04/14 (RFC-only) config: apply cocci to config_fn_t implementationsGlen Choo via GitGitGadget, May 30, 2023
  41. 09/14 config.c: provide kvi with CLI configGlen Choo via GitGitGadget, May 30, 2023
  42. Jonathan TanJun 1, 2023
  43. Glen ChooJun 2, 2023
  44. 10/14 trace2: plumb config kviGlen Choo via GitGitGadget, May 30, 2023
  45. Jonathan TanJun 1, 2023
  46. 12/14 config.c: remove config_reader from configsetsGlen Choo via GitGitGadget, May 30, 2023
  47. 13/14 config: add kvi.path, use it to evaluate includesGlen Choo via GitGitGadget, May 30, 2023
  48. Jonathan TanJun 2, 2023
  49. 14/14 config: pass source to config_parser_event_fn_tGlen Choo via GitGitGadget, May 30, 2023
  50. Jonathan TanJun 2, 2023
  51. Glen ChooJun 2, 2023
  52. 11/14 config: pass kvi to die_bad_number()Glen Choo via GitGitGadget, May 30, 2023
  53. Jonathan TanJun 1, 2023
  54. Glen ChooJun 2, 2023
  55. 00/12 config: remove global state from config iterationGlen Choo via GitGitGadget, Jun 20, 2023
  56. 02/12 urlmatch.h: use config_fn_t typeGlen Choo via GitGitGadget, Jun 20, 2023
  57. Junio C HamanoJun 20, 2023
  58. 01/12 config: inline git_color_default_configGlen Choo via GitGitGadget, Jun 20, 2023
  59. Junio C HamanoJun 20, 2023
  60. 04/12 config.c: pass ctx in configsetsGlen Choo via GitGitGadget, Jun 20, 2023
  61. Junio C HamanoJun 20, 2023
  62. 05/12 config: pass ctx with config filesGlen Choo via GitGitGadget, Jun 20, 2023
  63. 06/12 builtin/config.c: test misuse of format_config()Glen Choo via GitGitGadget, Jun 20, 2023
  64. Junio C HamanoJun 20, 2023
  65. Glen ChooJun 20, 2023
  66. Jonathan TanJun 23, 2023
  67. Jeff KingJun 24, 2023
  68. Glen ChooJun 28, 2023
  69. 07/12 config.c: pass ctx with CLI configGlen Choo via GitGitGadget, Jun 20, 2023
  70. Jonathan TanJun 23, 2023
  71. Glen ChooJun 23, 2023
  72. 08/12 trace2: plumb config kviGlen Choo via GitGitGadget, Jun 20, 2023
  73. Jonathan TanJun 23, 2023
  74. 10/12 config.c: remove config_reader from configsetsGlen Choo via GitGitGadget, Jun 20, 2023
  75. Jonathan TanJun 23, 2023
  76. Junio C HamanoJun 23, 2023
  77. 03/12 config: add ctx arg to config_fn_tGlen Choo via GitGitGadget, Jun 20, 2023
  78. 11/12 config: add kvi.path, use it to evaluate includesGlen Choo via GitGitGadget, Jun 20, 2023
  79. 12/12 config: pass source to config_parser_event_fn_tGlen Choo via GitGitGadget, Jun 20, 2023
  80. Junio C HamanoJun 20, 2023
  81. 09/12 config: pass kvi to die_bad_number()Glen Choo via GitGitGadget, Jun 20, 2023
  82. Junio C HamanoJun 21, 2023
  83. Glen ChooJun 21, 2023
  84. Jonathan TanJun 23, 2023
  85. Junio C HamanoJun 23, 2023
  86. Glen ChooJun 23, 2023
  87. 00/12 config: remove global state from config iterationGlen Choo via GitGitGadget, Jun 26, 2023
  88. 01/12 config: inline git_color_default_configGlen Choo via GitGitGadget, Jun 26, 2023
  89. 02/12 urlmatch.h: use config_fn_t typeGlen Choo via GitGitGadget, Jun 26, 2023
  90. 04/12 config.c: pass ctx in configsetsGlen Choo via GitGitGadget, Jun 26, 2023
  91. 06/12 builtin/config.c: test misuse of format_config()Glen Choo via GitGitGadget, Jun 26, 2023
  92. 05/12 config: pass ctx with config filesGlen Choo via GitGitGadget, Jun 26, 2023
  93. 07/12 config.c: pass ctx with CLI configGlen Choo via GitGitGadget, Jun 26, 2023
  94. 08/12 trace2: plumb config kviGlen Choo via GitGitGadget, Jun 26, 2023
  95. 03/12 config: add ctx arg to config_fn_tGlen Choo via GitGitGadget, Jun 26, 2023
  96. 11/12 config: add kvi.path, use it to evaluate includesGlen Choo via GitGitGadget, Jun 26, 2023
  97. 12/12 config: pass source to config_parser_event_fn_tGlen Choo via GitGitGadget, Jun 26, 2023
  98. 10/12 config.c: remove config_reader from configsetsGlen Choo via GitGitGadget, Jun 26, 2023
  99. 09/12 config: pass kvi to die_bad_number()Glen Choo via GitGitGadget, Jun 26, 2023
  100. Junio C HamanoJun 26, 2023
  101. 00/11 config: remove global state from config iterationGlen Choo via GitGitGadget, Jun 28, 2023
  102. 01/11 config: inline git_color_default_configGlen Choo via GitGitGadget, Jun 28, 2023
  103. 02/11 urlmatch.h: use config_fn_t typeGlen Choo via GitGitGadget, Jun 28, 2023
  104. 04/11 config.c: pass ctx in configsetsGlen Choo via GitGitGadget, Jun 28, 2023
  105. 05/11 config: pass ctx with config filesGlen Choo via GitGitGadget, Jun 28, 2023
  106. 06/11 config.c: pass ctx with CLI configGlen Choo via GitGitGadget, Jun 28, 2023
  107. 07/11 trace2: plumb config kviGlen Choo via GitGitGadget, Jun 28, 2023
  108. 03/11 config: add ctx arg to config_fn_tGlen Choo via GitGitGadget, Jun 28, 2023
  109. 09/11 config.c: remove config_reader from configsetsGlen Choo via GitGitGadget, Jun 28, 2023
  110. 10/11 config: add kvi.path, use it to evaluate includesGlen Choo via GitGitGadget, Jun 28, 2023
  111. 11/11 config: pass source to config_parser_event_fn_tGlen Choo via GitGitGadget, Jun 28, 2023
  112. 08/11 config: pass kvi to die_bad_number()Glen Choo via GitGitGadget, Jun 28, 2023
  113. Jonathan TanJun 28, 2023
  114. Junio C HamanoJun 28, 2023
  115. Phillip WoodJul 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.