git/builtin
Glen Choo 26b669324b config.c: pass ctx with CLI config
Pass config_context when parsing CLI config. To provide the .kvi member,
refactor out kvi_from_param() from the logic that caches CLI config in
configsets. Now that config_context and config_context.kvi is always
present when config machinery calls config callbacks, plumb "kvi" so
that we can remove all calls of current_config_scope() except for
trace2/*.c (which will be handled in a later commit), and remove all
other current_config_*() (the functions themselves and their calls).
Note that this results in .kvi containing a different, more complete
set of information than the mocked up "struct config_source" in
git_config_from_parameters().

Plumbing "kvi" reveals a few places where we've been doing the wrong
thing:

* git_config_parse_parameter() hasn't been setting config source
  information, so plumb "kvi" there too.

* 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 --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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-06-28 14:06:39 -07:00
..
add.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
am.c pager.h: move declarations for pager.c functions from cache.h 2023-04-11 08:52:10 -07:00
annotate.c strvec: rename struct fields 2020-07-30 19:18:06 -07:00
apply.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
archive.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
bisect.c copy.h: move declarations for copy.c functions from cache.h 2023-04-24 12:47:31 -07:00
blame.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
branch.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
bugreport.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
bundle.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
cat-file.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
check-attr.c Merge branch 'jc/attr-source-tree' 2023-05-17 10:11:41 -07:00
check-ignore.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
check-mailmap.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
check-ref-format.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
checkout--worker.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
checkout-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
checkout.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
clean.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
clone.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
column.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
commit-graph.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
commit-tree.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
commit.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
config.c config.c: pass ctx with CLI config 2023-06-28 14:06:39 -07:00
count-objects.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
credential-cache--daemon.c credential: erase all matching credentials 2023-06-15 13:26:41 -07:00
credential-cache.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
credential-store.c credential: avoid erasing distinct password 2023-06-15 13:26:39 -07:00
credential.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
describe.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
diagnose.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
diff-files.c diff-files: integrate with sparse index 2023-05-09 14:26:36 -07:00
diff-index.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
diff-tree.c diff-tree: integrate with sparse index 2023-05-18 10:40:33 -07:00
diff.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
difftool.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
fast-export.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fast-import.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fetch-pack.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
fetch.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
fmt-merge-msg.c wrapper.h: move declarations for wrapper.c functions from cache.h 2023-03-21 10:56:53 -07:00
for-each-ref.c Merge branch 'ow/ref-filter-omit-empty' 2023-04-21 15:35:05 -07:00
for-each-repo.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
fsck.c Merge branch 'ds/disable-replace-refs' 2023-06-22 16:29:06 -07:00
fsmonitor--daemon.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
gc.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
get-tar-commit-id.c Merge branch 'rs/get-tar-commit-id-use-defined-const' 2023-04-20 14:33:36 -07:00
grep.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
hash-object.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
help.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
hook.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
index-pack.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
init-db.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
interpret-trailers.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
log.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
ls-files.c ls-files: align format atoms with ls-tree 2023-05-23 20:12:57 +09:00
ls-remote.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
ls-tree.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
mailinfo.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
mailsplit.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge-base.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
merge-file.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
merge-index.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
merge-ours.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
merge-recursive.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
merge-tree.c surround %s with quotes when failed to lookup commit 2023-06-03 09:01:10 +09:00
merge.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
mktag.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
mktree.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
multi-pack-index.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
mv.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
name-rev.c name-rev: make --stdin hidden 2023-05-06 14:32:20 -07:00
notes.c editor: move editor-related functions and declarations into common file 2023-04-11 08:52:10 -07:00
pack-objects.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
pack-redundant.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pack-refs.c pack-refs: teach pack-refs --include option 2023-05-12 14:54:14 -07:00
patch-id.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
prune-packed.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
prune.c repository: create disable_replace_refs() 2023-06-12 13:34:55 -07:00
pull.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
push.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
range-diff.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
read-tree.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
rebase.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
receive-pack.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
reflog.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
remote-ext.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote-fd.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote.c config.c: pass ctx in configsets 2023-06-28 14:06:39 -07:00
repack.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
replace.c repository: create disable_replace_refs() 2023-06-12 13:34:55 -07:00
rerere.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
reset.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
rev-list.c object-file.h: move declarations for object-file.c functions from cache.h 2023-04-11 08:52:10 -07:00
rev-parse.c rev-parse: fix a leak with --abbrev-ref 2023-06-17 09:02:47 -07:00
revert.c Merge branch 'pw/rebase-cleanup-merge-strategy-option-handling' 2023-04-17 18:05:13 -07:00
rm.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
send-pack.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
shortlog.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
show-branch.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
show-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
show-ref.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
sparse-checkout.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
stash.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
stripspace.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
submodule--helper.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
symbolic-ref.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
tag.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
unpack-file.c Merge branch 'en/header-split-cache-h' 2023-04-25 13:56:20 -07:00
unpack-objects.c repository: create disable_replace_refs() 2023-06-12 13:34:55 -07:00
update-index.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
update-ref.c hash-ll.h: split out of hash.h to remove dependency on repository.h 2023-04-24 12:47:32 -07:00
update-server-info.c server-info.h: move declarations for server-info.c functions from cache.h 2023-04-24 12:47:31 -07:00
upload-archive.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00
upload-pack.c repository: create disable_replace_refs() 2023-06-12 13:34:55 -07:00
var.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
verify-commit.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
verify-pack.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
verify-tag.c object-name.h: move declarations for object-name.c functions from cache.h 2023-04-11 08:52:09 -07:00
worktree.c config: add ctx arg to config_fn_t 2023-06-28 14:06:39 -07:00
write-tree.c Merge branch 'en/header-split-cache-h-part-2' 2023-05-09 16:45:46 -07:00