* git-switch history and checkout compatibility
From: Namikaze Minato @ 2023-06-28 13:03 UTC (permalink / raw)
To: git
In-Reply-To: <CACmJb3yoHagaU1wb4qRT-nZV4Wptao8boaUXCAYrFxfrxcmUYg@mail.gmail.com>
Hello,
I have been waiting for people to report this but it never came so I'm doing it:
I have trouble with getting used to git-switch instead of
git-checkout, but have even more trouble to get people to adopt it.
Please consider the two following git-switch statements:
git switch remote/branch # fatal: a branch is expected, got remote
branch 'remote/branch'
#and
git switch -d remote/branch
git switch master
git switch - # fatal: a branch is expected, got commit 'commit_id_here'
Both as retro-compatibility with checkout and for user-friendliness, I
would expect both to work.
Maybe a setting checkout.autoDetach could control such behavior if the
current implementation should be kept?
What do you think?
Kind regards,
Minato
^ permalink raw reply
* Re: [PATCH 2/2] for-each-ref: add --count-matches option
From: Phillip Wood @ 2023-06-28 13:12 UTC (permalink / raw)
To: Jeff King, Derrick Stolee via GitGitGadget
Cc: Junio C Hamano, git, vdye, me, mjcheetham, Derrick Stolee
In-Reply-To: <f6fd39bc-65d4-76e3-94b4-9163194c89dd@gmail.com>
On 27/06/2023 11:05, Phillip Wood wrote:
> On 27/06/2023 08:30, Jeff King wrote:
>> I don't think this is a very realistic perf test, because for-each-ref
>> is doing a bunch of work to generate its default format, only to have
>> "wc" throw most of it away. Doing:
>>
>> git for-each-ref --format='%(refname)' | wc -l
>
> That's a good point. I wondered if using a short fixed format string was
> even better so I tried
>
> git init test
> cd test
> git commit --allow-empty -m initial
> seq 0 100000 | sed "s:\(.*\):create refs/heads/some-prefix/\1 $(git
> rev-parse HEAD):" | git update-ref --stdin
> git pack-refs --all
> hyperfine -L fmt "","--format=%\(refname\)","--format=x" 'git
> for-each-ref {fmt} refs/heads/ | wc -l'
>
> Which gives
> [...]
> Summary
> git for-each-ref --format=x refs/heads/ | wc -l ran
> 1.05 ± 0.01 times faster than git for-each-ref
> --format=%\(refname\) refs/heads/ | wc -l
> 18.25 ± 0.20 times faster than git for-each-ref refs/heads/ | wc -l
> [...]
> I'm a bit suspicious of the massive speed up I'm seeing by avoiding the
> default format but it appears to be repeatable.
Having seen Peff's mail [1] I realized that my test repo above is
looking up the commit from a loose object. If I repack the repository
then the default format is still slower than using "--format=%(refname)"
but is much more competitive.
$ git repack -a
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Writing objects: 100% (2/2), done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
$ hyperfine -L fmt "","--format=%\(refname\)","--format=x" 'git
for-each-ref {fmt} refs/heads/ | wc'
Benchmark 1: git for-each-ref refs/heads/ | wc -l
Time (mean ± σ): 111.4 ms ± 1.4 ms [User: 96.9 ms, System:
19.6 ms]
Range (min … max): 109.6 ms … 115.1 ms 25 runs
Benchmark 2: git for-each-ref --format=%\(refname\) refs/heads/ | wc -l
Time (mean ± σ): 66.7 ms ± 0.7 ms [User: 59.5 ms, System:
9.5 ms]
Range (min … max): 65.6 ms … 68.2 ms 42 runs
Benchmark 3: git for-each-ref --format=x refs/heads/ | wc -l
Time (mean ± σ): 63.4 ms ± 0.7 ms [User: 56.3 ms, System:
8.0 ms]
Range (min … max): 61.9 ms … 65.1 ms 44 runs
Summary
git for-each-ref --format=x refs/heads/ | wc -l ran
1.05 ± 0.02 times faster than git for-each-ref
--format=%\(refname\) refs/heads/ | wc -l
1.76 ± 0.03 times faster than git for-each-ref refs/heads/ | wc -l
So it seems most of the slowdown I was seeing yesterday was due it
looking up a loose object. I'm surprised repacking makes such a
difference in a repository that only contains two objects.
Best Wishes
Phillip
[1]
https://lore.kernel.org/git/20230627195900.GC1280909@coredump.intra.peff.net
^ permalink raw reply
* Re: [RFC PATCH 2/8] hex-ll: split out functionality from hex
From: Phillip Wood @ 2023-06-28 13:15 UTC (permalink / raw)
To: Calvin Wan, git; +Cc: nasamuffin, chooglen, johnathantanmy
In-Reply-To: <20230627195251.1973421-3-calvinwan@google.com>
Hi Calvin
On 27/06/2023 20:52, Calvin Wan wrote:
> Separate out hex functionality that doesn't require a hash algo into
> hex-ll.[ch]. Since the hash algo is currently a global that sits in
> repository, this separation removes that dependency for files that only
> need basic hex manipulation functions.
>
> diff --git a/hex.h b/hex.h
> index 7df4b3c460..c07c8b34c2 100644
> --- a/hex.h
> +++ b/hex.h
> @@ -2,22 +2,7 @@
> #define HEX_H
>
> #include "hash-ll.h"
> -
> -extern const signed char hexval_table[256];
> -static inline unsigned int hexval(unsigned char c)
> -{
> - return hexval_table[c];
> -}
> -
> -/*
> - * Convert two consecutive hexadecimal digits into a char. Return a
> - * negative value on error. Don't run over the end of short strings.
> - */
> -static inline int hex2chr(const char *s)
> -{
> - unsigned int val = hexval(s[0]);
> - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]);
> -}
> +#include "hex-ll.h"
I don't think any of the remaining declarations in hex.h depend on the
ones that are moved to "hex-ll.h" so this include should probably be in
"hex.c" rather than "hex.h"
Best Wishes
Phillip
^ permalink raw reply
* Re: [RFC PATCH 7/8] git-std-lib: introduce git standard library
From: Phillip Wood @ 2023-06-28 13:27 UTC (permalink / raw)
To: Calvin Wan, git; +Cc: nasamuffin, chooglen, johnathantanmy
In-Reply-To: <20230627195251.1973421-8-calvinwan@google.com>
Hi Calvin
On 27/06/2023 20:52, Calvin Wan wrote:
> The Git Standard Library intends to serve as the foundational library
> and root dependency that other libraries in Git will be built off of.
> That is to say, suppose we have libraries X and Y; a user that wants to
> use X and Y would need to include X, Y, and this Git Standard Library.
I think having a library of commonly used functions and structures is a
good idea. While I appreciate that we don't want to include everything
I'm surprised to see it does not include things like "hashmap.c" and
"string-list.c" that will be required by the config library as well as
other code in "libgit.a". I don't think we want "libgitconfig.a" and
"libgit.a" to both contain a copy of "hashmap.o" and "string-list.o"
> diff --git a/Makefile b/Makefile
> index e9ad9f9ef1..255bd10b82 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2162,6 +2162,11 @@ ifdef FSMONITOR_OS_SETTINGS
> COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_OS_SETTINGS).o
> endif
>
> +ifdef GIT_STD_LIB
> + BASIC_CFLAGS += -DGIT_STD_LIB
> + BASIC_CFLAGS += -DNO_GETTEXT
I can see other projects may want to build git-std-lib without gettext
support but if we're going to use git-std-lib within git it needs to be
able to be built with that support. The same goes for the trace
functions that you are redefining in usage.h
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 481dac22b0..75aa9b263e 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -396,8 +396,8 @@ static inline int noop_core_config(const char *var UNUSED,
> #define platform_core_config noop_core_config
> #endif
>
> +#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(GIT_STD_LIB)
> int lstat_cache_aware_rmdir(const char *path);
> -#if !defined(__MINGW32__) && !defined(_MSC_VER)
> #define rmdir lstat_cache_aware_rmdir
> #endif
I'm not sure why the existing condition is being moved here
Thanks for posting this RFC. I've only really given it a quick glance
but on the whole it seems to make sense.
Best Wishes
Phillip
^ permalink raw reply
* Re: What's cooking in git.git (Jun 2023, #07; Tue, 27)
From: Junio C Hamano @ 2023-06-28 16:24 UTC (permalink / raw)
To: Teng Long; +Cc: git
In-Reply-To: <20230628095421.7249-1-tenglong.tl@alibaba-inc.com>
Teng Long <dyroneteng@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> * tl/notes-separator (2023-06-21) 7 commits
>> - notes: introduce "--no-separator" option
>> - notes.c: introduce "--[no-]stripspace" option
>> - notes.c: append separator instead of insert by pos
>> - notes.c: introduce '--separator=<paragraph-break>' option
>> - t3321: add test cases about the notes stripspace behavior
>> - notes.c: use designated initializers for clarity
>> - notes.c: cleanup 'strbuf_grow' call in 'append_edit'
>>
>> 'git notes append' was taught '--separator' to specify string to insert
>> between paragraphs.
>> source: <cover.1685174011.git.dyroneteng@gmail.com>
>
> There are no pending issues I think ;-)
>
> Please let me know if there are some obstables to merge.
Yes, please do (this is not a message to Teng, but to others) ;-)
Thanks.
^ permalink raw reply
* Re: [PATCH v2] fix cherry-pick/revert status when doing multiple commits
From: Junio C Hamano @ 2023-06-28 16:26 UTC (permalink / raw)
To: Phillip Wood; +Cc: Jacob Keller, git, Phillip Wood, Jacob Keller
In-Reply-To: <743b17ee-2c5b-be7e-70f3-76d0f9d0ff5e@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
> Hi Jacob
>
> This version looks good to me
>
> Thanks for re-rolling
>
> Phillip
Thanks Jacob for writing and Phillip for reviewing. Queued.
^ permalink raw reply
* SHA256 support not experimental, or?
From: Adam Majer @ 2023-06-28 16:28 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 685 bytes --]
Hi all,
Is sha256 still considered experimental or can it be assumed to be stable?
The usecase here is we are planning on moving to sha256 repositories
mostly due to integrity guarantees, hypothetical or otherwise. What is
important is not the initial interop challenges with sha1 repos, but
whether the on-disk format will remain compatible with future versions
of git. At minimum, the on-disk format would be converted by some future
version(s) of git into another one and not be an end-of-the-road because
it was "experimental" where dataloss is an implied risk.
Attached is a patch that removes the scary text, if indeed sha256 should
be viewed as stable.
Cheers,
- Adam
[-- Attachment #2: 0001-doc-sha256-is-no-longer-experimantal.patch --]
[-- Type: text/x-patch, Size: 1580 bytes --]
---
Documentation/git.txt | 4 ++--
Documentation/object-format-disclaimer.txt | 8 ++------
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index f0cafa2290..7c150a473c 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -553,8 +553,8 @@ double-quotes and respecting backslash escapes. E.g., the value
If this variable is set, the default hash algorithm for new
repositories will be set to this value. This value is
ignored when cloning and the setting of the remote repository
- is always used. The default is "sha1". THIS VARIABLE IS
- EXPERIMENTAL! See `--object-format` in linkgit:git-init[1].
+ is always used. The default is "sha1".
+ See `--object-format` in linkgit:git-init[1].
Git Commits
~~~~~~~~~~~
diff --git a/Documentation/object-format-disclaimer.txt b/Documentation/object-format-disclaimer.txt
index 4cb106f0d1..dccee9c400 100644
--- a/Documentation/object-format-disclaimer.txt
+++ b/Documentation/object-format-disclaimer.txt
@@ -1,6 +1,2 @@
-THIS OPTION IS EXPERIMENTAL! SHA-256 support is experimental and still
-in an early stage. A SHA-256 repository will in general not be able to
-share work with "regular" SHA-1 repositories. It should be assumed
-that, e.g., Git internal file formats in relation to SHA-256
-repositories may change in backwards-incompatible ways. Only use
-`--object-format=sha256` for testing purposes.
+Note: SHA-256 repository will in general not be able to
+share work with "regular" SHA-1 repositories.
--
2.41.0
^ permalink raw reply related
* Re: [RFC PATCH 0/8] Introduce Git Standard Library
From: Calvin Wan @ 2023-06-28 16:30 UTC (permalink / raw)
To: Glen Choo; +Cc: git, nasamuffin, Jonathan Tan
In-Reply-To: <kl6lzg4kqw7v.fsf@chooglen-macbookpro.roam.corp.google.com>
Ah I failed to mention that this is built on top of 2.41. You can also
get this series with the correctly applied patches from:
https://github.com/calvin-wan-google/git/tree/git-std-lib-rfc
^ permalink raw reply
* Re: [RFC PATCH 6/8] pager: remove pager_in_use()
From: Glen Choo @ 2023-06-28 16:37 UTC (permalink / raw)
To: Junio C Hamano, Calvin Wan; +Cc: git, nasamuffin, johnathantanmy
In-Reply-To: <kl6lv8f8qvhd.fsf@chooglen-macbookpro.roam.corp.google.com>
Glen Choo <chooglen@google.com> writes:
> Could we add a is_pager/pager_in_use to that
> function and push the pager.h dependency upwards?
Bleh, I meant "Could we add a new is_pager/pager_in_use parameter to
that function?"
^ permalink raw reply
* Re: git-switch history and checkout compatibility
From: Junio C Hamano @ 2023-06-28 16:39 UTC (permalink / raw)
To: Namikaze Minato; +Cc: git
In-Reply-To: <CACmJb3xWh+0BR_V6sxfMK7iMSdWfvY9d2rjt1hnZhFw70zWweA@mail.gmail.com>
Namikaze Minato <LLoydsensei+git@gmail.com> writes:
> I have trouble with getting used to git-switch instead of
> git-checkout, but have even more trouble to get people to adopt
> it.
>
> Please consider the two following git-switch statements:
>
> git switch remote/branch # fatal: a branch is expected, got remote
> branch 'remote/branch'
> #and
> git switch -d remote/branch
> git switch master
> git switch - # fatal: a branch is expected, got commit 'commit_id_here'
>
> Both as retro-compatibility with checkout and for user-friendliness, I
> would expect both to work.
I wasn't among the primary advocates to add "switch/restore" pair
for those people who felt "checkout" was overloaded, and I may be
misremembering why they decided to deviate from what "checkout"
(one that checks out a branch, not the one that checks out paths)
did in these two cases. Having said that ...
* I suspect that requiring an explicit "--detach" is deliberate, as
they were trying to make "newbie friendlier" version of checkout.
* I am on the fence about the latter one. While I think it is a
bug if "switch -" and "switch @{-1}" did not work exactly like
"checkout @{-1}", combined with the previous point of requiring
to be explicit when detaching HEAD, "switch -" that tries to go
back to a detached state may be justifiable---it stops you in
order to avoid accidental detaching of HEAD.
> Maybe a setting checkout.autoDetach could control such behavior if the
> current implementation should be kept?
>
> What do you think?
Personally, I think those who are familiar with and expert enough on
Git and do not feel uneasy working on detached HEAD can and should
just use "checkout" not "switch/restore", but that may be just me.
Thanks.
^ permalink raw reply
* Re: [RFC PATCH 6/8] pager: remove pager_in_use()
From: Calvin Wan @ 2023-06-28 16:44 UTC (permalink / raw)
To: Glen Choo; +Cc: Junio C Hamano, git, nasamuffin, johnathantanmy
In-Reply-To: <kl6lpm5fr19f.fsf@chooglen-macbookpro.roam.corp.google.com>
> Glen Choo <chooglen@google.com> writes:
>
> > Could we add a is_pager/pager_in_use to that
> > function and push the pager.h dependency upwards?
>
> Bleh, I meant "Could we add a new is_pager/pager_in_use parameter to
> that function?"
Refactoring the function signature to:
parse_date_format(const char *format, struct date_mode *mode, int pager_in_use)
as you suggested is a much better solution, thanks! I'll make that
change in the next reroll.
^ permalink raw reply
* Re: [RFC PATCH 2/8] hex-ll: split out functionality from hex
From: Calvin Wan @ 2023-06-28 16:55 UTC (permalink / raw)
To: phillip.wood; +Cc: git, nasamuffin, chooglen, Jonathan Tan
In-Reply-To: <e08d9319-9a4f-bf16-242f-d976aeae32bc@gmail.com>
> I don't think any of the remaining declarations in hex.h depend on the
> ones that are moved to "hex-ll.h" so this include should probably be in
> "hex.c" rather than "hex.h"
The reason why hex-ll.h is included in hex.h isn't because there might
be other declarations in hex.h that depend on it. It is for files that
include hex.h to also inherit the inclusion of hex-ll.h. If we moved
the inclusion of hex-ll.h to hex.c rather than hex.h, then those files
would have to include both hex.h and hex-ll.h. It clarifies whether a
file needs all of hex or just the low level functionality of hex.
^ permalink raw reply
* Re: [PATCH 2/2] for-each-ref: add --count-matches option
From: Junio C Hamano @ 2023-06-28 17:08 UTC (permalink / raw)
To: Phillip Wood
Cc: Jeff King, Derrick Stolee via GitGitGadget, git, vdye, me,
mjcheetham, Derrick Stolee
In-Reply-To: <776c3682-d2eb-d2d7-3ea8-4a7db8cd7842@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
> So it seems most of the slowdown I was seeing yesterday was due it
> looking up a loose object. I'm surprised repacking makes such a
> difference in a repository that only contains two objects.
If we compare what is done in packfile.c:packed_object_info() and
object-file.c:loose_object_info() when we are only interested in
finding out the object type, there aren't that many differences
in the set of system calls each codepath needs to make.
* The packfile codepath needs to open and mmap *.pack and *.idx,
binary search in the .idx for the object location, then read a
few bytes from .pack, before being able to decode the header to
find out the type.
* The loose object codepath needs to open and mmap the loose object
file, read a few bytes from there, before being abole to decode
the header to find out the type. After that, it needs to munmap.
The cost of open/mmap for packfile codepath amortises over number of
objects (hence number of refs) very well. If there are many refs
that point at the same object, cache object layer will kick in to
avoid disk access for second and subsequent accesses to the same
object, but it helps both codepaths equally, so there should not be
much difference either way.
Thanks for a interesting piece of food for thought.
^ permalink raw reply
* Re: [PATCH v3 06/12] builtin/config.c: test misuse of format_config()
From: Glen Choo @ 2023-06-28 17:28 UTC (permalink / raw)
To: Jonathan Tan, Glen Choo via GitGitGadget
Cc: Jonathan Tan, git, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood
In-Reply-To: <20230623203219.3255267-1-jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
> "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com> writes:
>> +test_expect_success '--show-origin with --default' '
>> + test_must_fail git config --show-origin --default foo some.key
>> +'
>
> On my machine, this fails with
>
> BUG: config.c:4035: current_config_origin_type called outside config callback
> /usr/local/google/home/jonathantanmy/git/t/test-lib-functions.sh: line 1067: 3255109 Aborted "$@" 2>&7
> test_must_fail: died by signal 6: git config --show-origin --default foo some.key
>
> (So it indeed fails, as expected, but test_must_fail seems to not like
> the exit code.)
Ah you're right. I was under the impression that this was doing the
right thing on MacOS, but it doesn't work there either.
I think a good way to assert that we run into BUG() (Maybe
test_match_signal on the numeric value of SIGABRT? But that sounds error
prone), so I'll either use test_expect_failure or squash this patch.
^ permalink raw reply
* Re: [RFC PATCH 6/8] pager: remove pager_in_use()
From: Junio C Hamano @ 2023-06-28 17:30 UTC (permalink / raw)
To: Calvin Wan; +Cc: Glen Choo, git, nasamuffin, johnathantanmy
In-Reply-To: <CAFySSZBBAatvBmfwn9vc=v2hdWX_0Q4g4txqLOwtqiFZFW7uiA@mail.gmail.com>
Calvin Wan <calvinwan@google.com> writes:
>> Glen Choo <chooglen@google.com> writes:
>>
>> > Could we add a is_pager/pager_in_use to that
>> > function and push the pager.h dependency upwards?
>>
>> Bleh, I meant "Could we add a new is_pager/pager_in_use parameter to
>> that function?"
>
> Refactoring the function signature to:
>
> parse_date_format(const char *format, struct date_mode *mode, int pager_in_use)
>
> as you suggested is a much better solution, thanks! I'll make that
> change in the next reroll.
Yeah, the date format "auto:" that changes behaviour between the
output medium feels a serious layering violation, but given the
constraints, it looks like the best thing to do.
Thanks.
^ permalink raw reply
* Re: [PATCH 0/9] gitk: improve keyboard support
From: Jens Lideström @ 2023-06-28 17:32 UTC (permalink / raw)
To: Johannes Sixt, Jens Lidestrom via GitGitGadget; +Cc: Paul Mackerras [ ], git
In-Reply-To: <0cb94aa5-726f-a57f-858c-b29764c63ce7@kdbg.org>
@Hannes: I choose key combinations with Ctrl+<another-key>.
Another possibility is to use Ctrl+Shift+<another-key>. That is more complicated to press, but it creates a nice distinction between two categories of commands:
Searching and navigation command (existing): Ctrl+<another-key>
Branch modification commands (new): Ctrl+Shift+<another-key>
Do you have any opinion on this? Only Ctrl, or Ctrl+Shift for the new commands?
/Jens
On 2023-06-28 08:09, Johannes Sixt wrote:
> Am 27.06.23 um 16:41 schrieb Jens Lidestrom via GitGitGadget:
>> It is often convenient to use the keyboard to navigate the gitk GUI and
>> there are keyboard shortcut bindings for many operations such as searching
>> and scrolling. There is however no keyboard binding for the most common
>> operations on branches and commits: Check out, reset, cherry-pick, create
>> and delete branches.
>>
>> This PR adds keyboard bindings for these 5 commands. It also adjusts some
>> GUI focus defaults to simplify keyboard navigation.
>>
>> Some refactoring of the command implementation has been necessary.
>> Originally the commands was using the mouse context menu to get info about
>> the head and commit to act on. When using keyboard binds this information
>> isn't available so instead the row that is selected in the GUI is used. By
>> adding procedures for doing this the PR lays the groundwork for more similar
>> keyboard binds in the future.
> I like it when an application can be navigated with the keyboard. These
> changes are very much appreciated.
>
> I've left some comments on individual commits. The important one is that
> I think it makes the Reset dialog way too easy to destroy uncommitted work.
>
> Please note that gitk-git directory is in its own repository that is
> only subtree-merged into the Git repository. You should generate patches
> against git://git.ozlabs.org/~paulus/gitk (I don't know how difficult it
> would be for Paul to integrate patches that were generated by gitgitgadget).
>
> -- Hannes
>
>> I'm including Paul Mackerras because he seems to be the maintainer of gitk.
>> Can you review, Paul?
>>
>> Jens Lidestrom (9):
>> gitk: add procedures to get commit info from selected row
>> gitk: use term "current branch" in gui
>> gitk: add keyboard bind for reset
>> gitk: show branch name in reset dialog
>> gitk: add keyboard bind for checkout
>> gitk: add keyboard bind for create and remove branch
>> gitk: add keyboard bind to cherry-pick
>> gitk: focus ok button in reset dialog
>> gitk: default select reset hard in dialog
>>
>> gitk-git/gitk | 132 ++++++++++++++++++++++++++++++++++++--------------
>> 1 file changed, 96 insertions(+), 36 deletions(-)
>>
>>
>> base-commit: 94486b6763c29144c60932829a65fec0597e17b3
>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1551%2Fjensli%2Fkeyboard-for-gitk-v1
>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1551/jensli/keyboard-for-gitk-v1
>> Pull-Request: https://github.com/gitgitgadget/git/pull/1551
^ permalink raw reply
* [PATCH] t4205: correctly test %(describe:abbrev=...)
From: Kousik Sanagavarapu @ 2023-06-28 18:16 UTC (permalink / raw)
To: git; +Cc: Eli Schwartz, Kousik Sanagavarapu, Christian Couder, Hariom Verma
The pretty format %(describe:abbrev=<number>) tells describe to use only
<number> characters of the oid to generate the human-readable format of
the commit-ish.
This is not apparent in the test for %(describe:abbrev=...) because we
directly tag HEAD and use that, in which case the human-readable format
is just the tag name. So, create a new commit and use that instead.
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com>
---
t/t4205-log-pretty-formats.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 4cf8a77667..b631b5a142 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -1011,8 +1011,7 @@ test_expect_success '%(describe:tags) vs git describe --tags' '
'
test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' '
- test_when_finished "git tag -d tagname" &&
- git tag -a -m tagged tagname &&
+ test_commit --no-tag file &&
git describe --abbrev=15 >expect &&
git log -1 --format="%(describe:abbrev=15)" >actual &&
test_cmp expect actual
--
2.41.0.29.g8148156d44.dirty
^ permalink raw reply related
* [PATCH v5 01/11] config: inline git_color_default_config
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
git_color_default_config() is a shorthand for calling two other config
callbacks. There are no other non-static functions that do this and it
will complicate our refactoring of config_fn_t so inline it instead.
Signed-off-by: Glen Choo <chooglen@google.com>
---
builtin/add.c | 5 ++++-
builtin/branch.c | 5 ++++-
builtin/clean.c | 6 ++++--
builtin/grep.c | 5 ++++-
builtin/show-branch.c | 5 ++++-
builtin/tag.c | 6 +++++-
color.c | 8 --------
color.h | 6 +-----
8 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index 6137e7b4ad7..e01efdfc50d 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -365,7 +365,10 @@ static int add_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
}
static const char embedded_advice[] = N_(
diff --git a/builtin/branch.c b/builtin/branch.c
index 075e580d224..8337b9e71bb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -117,7 +117,10 @@ static int git_branch_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
}
static const char *branch_get_color(enum color_branch ix)
diff --git a/builtin/clean.c b/builtin/clean.c
index 78852d28cec..57e7f7cac64 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -130,8 +130,10 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
}
- /* inspect the color.ui config variable and others */
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
}
static const char *clean_get_color(enum color_clean ix)
diff --git a/builtin/grep.c b/builtin/grep.c
index b86c754defb..76cf999d310 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -293,7 +293,10 @@ static int wait_all(void)
static int grep_cmd_config(const char *var, const char *value, void *cb)
{
int st = grep_config(var, value, cb);
- if (git_color_default_config(var, value, NULL) < 0)
+
+ if (git_color_config(var, value, cb) < 0)
+ st = -1;
+ else if (git_default_config(var, value, cb) < 0)
st = -1;
if (!strcmp(var, "grep.threads")) {
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 7ef4a642c17..a2461270d4b 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -579,7 +579,10 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
}
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
diff --git a/builtin/tag.c b/builtin/tag.c
index 49b64c7a288..1acf5f7a59f 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -209,7 +209,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
if (starts_with(var, "column."))
return git_column_config(var, value, "tag", &colopts);
- return git_color_default_config(var, value, cb);
+
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
}
static void write_tag_body(int fd, const struct object_id *oid)
diff --git a/color.c b/color.c
index 83abb11eda0..b24b19566b9 100644
--- a/color.c
+++ b/color.c
@@ -430,14 +430,6 @@ int git_color_config(const char *var, const char *value, void *cb UNUSED)
return 0;
}
-int git_color_default_config(const char *var, const char *value, void *cb)
-{
- if (git_color_config(var, value, cb) < 0)
- return -1;
-
- return git_default_config(var, value, cb);
-}
-
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
{
if (*color)
diff --git a/color.h b/color.h
index cfc8f841b23..bb28343be21 100644
--- a/color.h
+++ b/color.h
@@ -88,12 +88,8 @@ extern const int column_colors_ansi_max;
*/
extern int color_stdout_is_tty;
-/*
- * Use the first one if you need only color config; the second is a convenience
- * if you are just going to change to git_default_config, too.
- */
+/* Parse color config. */
int git_color_config(const char *var, const char *value, void *cb);
-int git_color_default_config(const char *var, const char *value, void *cb);
/*
* Parse a config option, which can be a boolean or one of
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 02/11] urlmatch.h: use config_fn_t type
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
These are actually used as config callbacks, so use the typedef-ed type
and make future refactors easier.
Signed-off-by: Glen Choo <chooglen@google.com>
---
urlmatch.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/urlmatch.h b/urlmatch.h
index 9f40b00bfb8..bee374a642c 100644
--- a/urlmatch.h
+++ b/urlmatch.h
@@ -2,6 +2,7 @@
#define URL_MATCH_H
#include "string-list.h"
+#include "config.h"
struct url_info {
/* normalized url on success, must be freed, otherwise NULL */
@@ -48,8 +49,8 @@ struct urlmatch_config {
const char *key;
void *cb;
- int (*collect_fn)(const char *var, const char *value, void *cb);
- int (*cascade_fn)(const char *var, const char *value, void *cb);
+ config_fn_t collect_fn;
+ config_fn_t cascade_fn;
/*
* Compare the two matches, the one just discovered and the existing
* best match and return a negative value if the found item is to be
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 00/11] config: remove global state from config iteration
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo
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
^ permalink raw reply
* [PATCH v5 04/11] config.c: pass ctx in configsets
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
Pass config_context to config callbacks in configset_iter(), trivially
setting the .kvi member to the cached key_value_info. Then, in config
callbacks that are only used with configsets, use the .kvi member to
replace calls to current_config_*(), and delete current_config_line()
because it has no remaining callers.
This leaves builtin/config.c and config.c as the only remaining users of
current_config_*().
Signed-off-by: Glen Choo <chooglen@google.com>
---
builtin/remote.c | 10 ++++++----
config.c | 35 ++++++++++++++++-------------------
config.h | 2 +-
remote.c | 7 ++++---
t/helper/test-config.c | 11 ++++++-----
5 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 87de81105e2..d47f9ee21cf 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -646,17 +646,19 @@ struct push_default_info
};
static int config_read_push_default(const char *key, const char *value,
- const struct config_context *ctx UNUSED, void *cb)
+ const struct config_context *ctx, void *cb)
{
+ const struct key_value_info *kvi = ctx->kvi;
+
struct push_default_info* info = cb;
if (strcmp(key, "remote.pushdefault") ||
!value || strcmp(value, info->old_name))
return 0;
- info->scope = current_config_scope();
+ info->scope = kvi->scope;
strbuf_reset(&info->origin);
- strbuf_addstr(&info->origin, current_config_name());
- info->linenr = current_config_line();
+ strbuf_addstr(&info->origin, config_origin_type_name(kvi->origin_type));
+ info->linenr = kvi->linenr;
return 0;
}
diff --git a/config.c b/config.c
index 850e432e301..662d406ac1e 100644
--- a/config.c
+++ b/config.c
@@ -2317,6 +2317,7 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
struct string_list *values;
struct config_set_element *entry;
struct configset_list *list = &set->list;
+ struct config_context ctx = CONFIG_CONTEXT_INIT;
for (i = 0; i < list->nr; i++) {
entry = list->items[i].e;
@@ -2324,12 +2325,11 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
values = &entry->value_list;
config_reader_set_kvi(reader, values->items[value_index].util);
-
- if (fn(entry->key, values->items[value_index].string, NULL, data) < 0)
+ ctx.kvi = values->items[value_index].util;
+ if (fn(entry->key, values->items[value_index].string, &ctx, data) < 0)
git_die_config_linenr(entry->key,
- reader->config_kvi->filename,
- reader->config_kvi->linenr);
-
+ ctx.kvi->filename,
+ ctx.kvi->linenr);
config_reader_set_kvi(reader, NULL);
}
}
@@ -3984,13 +3984,8 @@ static int reader_origin_type(struct config_reader *reader,
return 0;
}
-const char *current_config_origin_type(void)
+const char *config_origin_type_name(enum config_origin_type type)
{
- enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
-
- if (reader_origin_type(&the_reader, &type))
- BUG("current_config_origin_type called outside config callback");
-
switch (type) {
case CONFIG_ORIGIN_BLOB:
return "blob";
@@ -4007,6 +4002,16 @@ const char *current_config_origin_type(void)
}
}
+const char *current_config_origin_type(void)
+{
+ enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
+
+ if (reader_origin_type(&the_reader, &type))
+ BUG("current_config_origin_type called outside config callback");
+
+ return config_origin_type_name(type);
+}
+
const char *config_scope_name(enum config_scope scope)
{
switch (scope) {
@@ -4054,14 +4059,6 @@ enum config_scope current_config_scope(void)
return the_reader.parsing_scope;
}
-int current_config_line(void)
-{
- if (the_reader.config_kvi)
- return the_reader.config_kvi->linenr;
- else
- return the_reader.source->linenr;
-}
-
int lookup_config(const char **mapping, int nr_mapping, const char *var)
{
int i;
diff --git a/config.h b/config.h
index cd30125a8a4..ddf147bb2d1 100644
--- a/config.h
+++ b/config.h
@@ -387,7 +387,7 @@ int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
enum config_scope current_config_scope(void);
const char *current_config_origin_type(void);
const char *current_config_name(void);
-int current_config_line(void);
+const char *config_origin_type_name(enum config_origin_type type);
/*
* Match and parse a config key of the form:
diff --git a/remote.c b/remote.c
index 241999c2842..1dab860141b 100644
--- a/remote.c
+++ b/remote.c
@@ -350,7 +350,7 @@ static void read_branches_file(struct remote_state *remote_state,
}
static int handle_config(const char *key, const char *value,
- const struct config_context *ctx UNUSED, void *cb)
+ const struct config_context *ctx, void *cb)
{
const char *name;
size_t namelen;
@@ -358,6 +358,7 @@ static int handle_config(const char *key, const char *value,
struct remote *remote;
struct branch *branch;
struct remote_state *remote_state = cb;
+ const struct key_value_info *kvi = ctx->kvi;
if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
/* There is no subsection. */
@@ -415,8 +416,8 @@ static int handle_config(const char *key, const char *value,
}
remote = make_remote(remote_state, name, namelen);
remote->origin = REMOTE_CONFIG;
- if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
- current_config_scope() == CONFIG_SCOPE_WORKTREE)
+ if (kvi->scope == CONFIG_SCOPE_LOCAL ||
+ kvi->scope == CONFIG_SCOPE_WORKTREE)
remote->configured_in_repo = 1;
if (!strcmp(subkey, "mirror"))
remote->mirror = git_config_bool(key, value);
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 85ad815358e..3f4c3678318 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -43,9 +43,10 @@
*/
static int iterate_cb(const char *var, const char *value,
- const struct config_context *ctx UNUSED,
+ const struct config_context *ctx,
void *data UNUSED)
{
+ const struct key_value_info *kvi = ctx->kvi;
static int nr;
if (nr++)
@@ -53,10 +54,10 @@ static int iterate_cb(const char *var, const char *value,
printf("key=%s\n", var);
printf("value=%s\n", value ? value : "(null)");
- printf("origin=%s\n", current_config_origin_type());
- printf("name=%s\n", current_config_name());
- printf("lno=%d\n", current_config_line());
- printf("scope=%s\n", config_scope_name(current_config_scope()));
+ printf("origin=%s\n", config_origin_type_name(kvi->origin_type));
+ printf("name=%s\n", kvi->filename ? kvi->filename : "");
+ printf("lno=%d\n", kvi->linenr);
+ printf("scope=%s\n", config_scope_name(kvi->scope));
return 0;
}
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 05/11] config: pass ctx with config files
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
Pass config_context to config_callbacks when parsing config files. To
provide the .kvi member, refactor out the configset logic that caches
"struct config_source" and "enum config_scope" as a "struct
key_value_info". Make the "enum config_scope" available to the config
file machinery by plumbing an additional arg through
git_config_from_file_with_options().
We do not exercise ctx yet because the remaining current_config_*()
callers may be used with config_with_options(), which may read config
from parameters, but parameters don't pass ctx yet.
Signed-off-by: Glen Choo <chooglen@google.com>
---
bundle-uri.c | 1 +
config.c | 105 ++++++++++++++++++++++++++++++---------------
config.h | 8 ++--
fsck.c | 3 +-
submodule-config.c | 5 ++-
5 files changed, 81 insertions(+), 41 deletions(-)
diff --git a/bundle-uri.c b/bundle-uri.c
index 0d5acc3dc51..64f32387745 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -255,6 +255,7 @@ int bundle_uri_parse_config_format(const char *uri,
}
result = git_config_from_file_with_options(config_to_bundle_list,
filename, list,
+ CONFIG_SCOPE_UNKNOWN,
&opts);
if (!result && list->mode == BUNDLE_MODE_NONE) {
diff --git a/config.c b/config.c
index 662d406ac1e..31718711827 100644
--- a/config.c
+++ b/config.c
@@ -259,7 +259,9 @@ static int handle_path_include(struct config_source *cs, const char *path,
!cs ? "<unknown>" :
cs->name ? cs->name :
"the command line");
- ret = git_config_from_file(git_config_include, path, inc);
+ ret = git_config_from_file_with_options(git_config_include, path, inc,
+ current_config_scope(),
+ NULL);
inc->depth--;
}
cleanup:
@@ -503,7 +505,7 @@ static int git_config_include(const char *var, const char *value,
* Pass along all values, including "include" directives; this makes it
* possible to query information on the includes themselves.
*/
- ret = inc->fn(var, value, NULL, inc->data);
+ ret = inc->fn(var, value, ctx, inc->data);
if (ret < 0)
return ret;
@@ -939,12 +941,15 @@ static char *parse_value(struct config_source *cs)
}
}
-static int get_value(struct config_source *cs, config_fn_t fn, void *data,
- struct strbuf *name)
+static int get_value(struct config_source *cs, struct key_value_info *kvi,
+ config_fn_t fn, void *data, struct strbuf *name)
{
int c;
char *value;
int ret;
+ struct config_context ctx = {
+ .kvi = kvi,
+ };
/* Get the full name */
for (;;) {
@@ -973,7 +978,8 @@ static int get_value(struct config_source *cs, config_fn_t fn, void *data,
* accurate line number in error messages.
*/
cs->linenr--;
- ret = fn(name->buf, value, NULL, data);
+ kvi->linenr = cs->linenr;
+ ret = fn(name->buf, value, &ctx, data);
if (ret >= 0)
cs->linenr++;
return ret;
@@ -1072,8 +1078,19 @@ static int do_event(struct config_source *cs, enum config_event_t type,
return 0;
}
+static void kvi_from_source(struct config_source *cs,
+ enum config_scope scope,
+ struct key_value_info *out)
+{
+ out->filename = strintern(cs->name);
+ out->origin_type = cs->origin_type;
+ out->linenr = cs->linenr;
+ out->scope = scope;
+}
+
static int git_parse_source(struct config_source *cs, config_fn_t fn,
- void *data, const struct config_options *opts)
+ struct key_value_info *kvi, void *data,
+ const struct config_options *opts)
{
int comment = 0;
size_t baselen = 0;
@@ -1157,7 +1174,7 @@ static int git_parse_source(struct config_source *cs, config_fn_t fn,
*/
strbuf_setlen(var, baselen);
strbuf_addch(var, tolower(c));
- if (get_value(cs, fn, data, var) < 0)
+ if (get_value(cs, kvi, fn, data, var) < 0)
break;
}
@@ -2010,9 +2027,11 @@ int git_default_config(const char *var, const char *value,
* this function.
*/
static int do_config_from(struct config_reader *reader,
- struct config_source *top, config_fn_t fn, void *data,
+ struct config_source *top, config_fn_t fn,
+ void *data, enum config_scope scope,
const struct config_options *opts)
{
+ struct key_value_info kvi = KVI_INIT;
int ret;
/* push config-file parsing state stack */
@@ -2022,8 +2041,9 @@ static int do_config_from(struct config_reader *reader,
strbuf_init(&top->value, 1024);
strbuf_init(&top->var, 1024);
config_reader_push_source(reader, top);
+ kvi_from_source(top, scope, &kvi);
- ret = git_parse_source(top, fn, data, opts);
+ ret = git_parse_source(top, fn, &kvi, data, opts);
/* pop config-file parsing state stack */
strbuf_release(&top->value);
@@ -2037,7 +2057,8 @@ static int do_config_from_file(struct config_reader *reader,
config_fn_t fn,
const enum config_origin_type origin_type,
const char *name, const char *path, FILE *f,
- void *data, const struct config_options *opts)
+ void *data, enum config_scope scope,
+ const struct config_options *opts)
{
struct config_source top = CONFIG_SOURCE_INIT;
int ret;
@@ -2052,19 +2073,20 @@ static int do_config_from_file(struct config_reader *reader,
top.do_ftell = config_file_ftell;
flockfile(f);
- ret = do_config_from(reader, &top, fn, data, opts);
+ ret = do_config_from(reader, &top, fn, data, scope, opts);
funlockfile(f);
return ret;
}
-static int git_config_from_stdin(config_fn_t fn, void *data)
+static int git_config_from_stdin(config_fn_t fn, void *data,
+ enum config_scope scope)
{
return do_config_from_file(&the_reader, fn, CONFIG_ORIGIN_STDIN, "",
- NULL, stdin, data, NULL);
+ NULL, stdin, data, scope, NULL);
}
int git_config_from_file_with_options(config_fn_t fn, const char *filename,
- void *data,
+ void *data, enum config_scope scope,
const struct config_options *opts)
{
int ret = -1;
@@ -2075,7 +2097,8 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
f = fopen_or_warn(filename, "r");
if (f) {
ret = do_config_from_file(&the_reader, fn, CONFIG_ORIGIN_FILE,
- filename, filename, f, data, opts);
+ filename, filename, f, data, scope,
+ opts);
fclose(f);
}
return ret;
@@ -2083,13 +2106,15 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
{
- return git_config_from_file_with_options(fn, filename, data, NULL);
+ return git_config_from_file_with_options(fn, filename, data,
+ CONFIG_SCOPE_UNKNOWN, NULL);
}
int git_config_from_mem(config_fn_t fn,
const enum config_origin_type origin_type,
const char *name, const char *buf, size_t len,
- void *data, const struct config_options *opts)
+ void *data, enum config_scope scope,
+ const struct config_options *opts)
{
struct config_source top = CONFIG_SOURCE_INIT;
@@ -2104,14 +2129,15 @@ int git_config_from_mem(config_fn_t fn,
top.do_ungetc = config_buf_ungetc;
top.do_ftell = config_buf_ftell;
- return do_config_from(&the_reader, &top, fn, data, opts);
+ return do_config_from(&the_reader, &top, fn, data, scope, opts);
}
int git_config_from_blob_oid(config_fn_t fn,
const char *name,
struct repository *repo,
const struct object_id *oid,
- void *data)
+ void *data,
+ enum config_scope scope)
{
enum object_type type;
char *buf;
@@ -2127,7 +2153,7 @@ int git_config_from_blob_oid(config_fn_t fn,
}
ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size,
- data, NULL);
+ data, scope, NULL);
free(buf);
return ret;
@@ -2136,13 +2162,14 @@ int git_config_from_blob_oid(config_fn_t fn,
static int git_config_from_blob_ref(config_fn_t fn,
struct repository *repo,
const char *name,
- void *data)
+ void *data,
+ enum config_scope scope)
{
struct object_id oid;
if (repo_get_oid(repo, name, &oid) < 0)
return error(_("unable to resolve config blob '%s'"), name);
- return git_config_from_blob_oid(fn, name, repo, &oid, data);
+ return git_config_from_blob_oid(fn, name, repo, &oid, data, scope);
}
char *git_system_config(void)
@@ -2228,27 +2255,34 @@ static int do_git_config_sequence(struct config_reader *reader,
if (git_config_system() && system_config &&
!access_or_die(system_config, R_OK,
opts->system_gently ? ACCESS_EACCES_OK : 0))
- ret += git_config_from_file(fn, system_config, data);
+ ret += git_config_from_file_with_options(fn, system_config,
+ data, CONFIG_SCOPE_SYSTEM,
+ NULL);
config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL);
git_global_config(&user_config, &xdg_config);
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
- ret += git_config_from_file(fn, xdg_config, data);
+ ret += git_config_from_file_with_options(fn, xdg_config, data,
+ CONFIG_SCOPE_GLOBAL, NULL);
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
- ret += git_config_from_file(fn, user_config, data);
+ ret += git_config_from_file_with_options(fn, user_config, data,
+ CONFIG_SCOPE_GLOBAL, NULL);
config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL);
if (!opts->ignore_repo && repo_config &&
!access_or_die(repo_config, R_OK, 0))
- ret += git_config_from_file(fn, repo_config, data);
+ ret += git_config_from_file_with_options(fn, repo_config, data,
+ CONFIG_SCOPE_LOCAL, NULL);
config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE);
if (!opts->ignore_worktree && worktree_config &&
repo && repo->repository_format_worktree_config &&
!access_or_die(worktree_config, R_OK, 0)) {
- ret += git_config_from_file(fn, worktree_config, data);
+ ret += git_config_from_file_with_options(fn, worktree_config, data,
+ CONFIG_SCOPE_WORKTREE,
+ NULL);
}
config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND);
@@ -2292,12 +2326,14 @@ int config_with_options(config_fn_t fn, void *data,
* regular lookup sequence.
*/
if (config_source && config_source->use_stdin) {
- ret = git_config_from_stdin(fn, data);
+ ret = git_config_from_stdin(fn, data, config_source->scope);
} else if (config_source && config_source->file) {
- ret = git_config_from_file(fn, config_source->file, data);
+ ret = git_config_from_file_with_options(fn, config_source->file,
+ data, config_source->scope,
+ NULL);
} else if (config_source && config_source->blob) {
ret = git_config_from_blob_ref(fn, repo, config_source->blob,
- data);
+ data, config_source->scope);
} else {
ret = do_git_config_sequence(&the_reader, opts, repo, fn, data);
}
@@ -2440,16 +2476,14 @@ static int configset_add_value(struct config_reader *reader,
if (!reader->source)
BUG("configset_add_value has no source");
if (reader->source->name) {
- kv_info->filename = strintern(reader->source->name);
- kv_info->linenr = reader->source->linenr;
- kv_info->origin_type = reader->source->origin_type;
+ kvi_from_source(reader->source, current_config_scope(), kv_info);
} else {
/* for values read from `git_config_from_parameters()` */
kv_info->filename = NULL;
kv_info->linenr = -1;
kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
+ kv_info->scope = reader->parsing_scope;
}
- kv_info->scope = reader->parsing_scope;
si->util = kv_info;
return 0;
@@ -3490,7 +3524,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
*/
if (git_config_from_file_with_options(store_aux,
config_filename,
- &store, &opts)) {
+ &store, CONFIG_SCOPE_UNKNOWN,
+ &opts)) {
error(_("invalid config file %s"), config_filename);
ret = CONFIG_INVALID_FILE;
goto out_free;
diff --git a/config.h b/config.h
index ddf147bb2d1..206bf1f175a 100644
--- a/config.h
+++ b/config.h
@@ -169,16 +169,18 @@ int git_default_config(const char *, const char *,
int git_config_from_file(config_fn_t fn, const char *, void *);
int git_config_from_file_with_options(config_fn_t fn, const char *,
- void *,
+ void *, enum config_scope,
const struct config_options *);
int git_config_from_mem(config_fn_t fn,
const enum config_origin_type,
const char *name,
const char *buf, size_t len,
- void *data, const struct config_options *opts);
+ void *data, enum config_scope scope,
+ const struct config_options *opts);
int git_config_from_blob_oid(config_fn_t fn, const char *name,
struct repository *repo,
- const struct object_id *oid, void *data);
+ const struct object_id *oid, void *data,
+ enum config_scope scope);
void git_config_push_parameter(const char *text);
void git_config_push_env(const char *spec);
int git_config_from_parameters(config_fn_t fn, void *data);
diff --git a/fsck.c b/fsck.c
index 55b6a694853..f92c216fb5c 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1238,7 +1238,8 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
data.ret = 0;
config_opts.error_action = CONFIG_ERROR_SILENT;
if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
- ".gitmodules", buf, size, &data, &config_opts))
+ ".gitmodules", buf, size, &data,
+ CONFIG_SCOPE_UNKNOWN, &config_opts))
data.ret |= report(options, oid, OBJ_BLOB,
FSCK_MSG_GITMODULES_PARSE,
"could not parse gitmodules blob");
diff --git a/submodule-config.c b/submodule-config.c
index a38d4d49731..3f25bd13674 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -606,7 +606,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
parameter.gitmodules_oid = &oid;
parameter.overwrite = 0;
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
- config, config_size, ¶meter, NULL);
+ config, config_size, ¶meter, CONFIG_SCOPE_UNKNOWN, NULL);
strbuf_release(&rev);
free(config);
@@ -714,7 +714,8 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
git_config_from_blob_oid(gitmodules_cb, rev.buf,
- the_repository, &oid, the_repository);
+ the_repository, &oid, the_repository,
+ CONFIG_SCOPE_UNKNOWN);
}
strbuf_release(&rev);
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 06/11] config.c: pass ctx with CLI config
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
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>
---
builtin/config.c | 47 ++++++++++++++++++----------
config.c | 80 ++++++++++++++++++++++++-----------------------
config.h | 3 +-
t/t1300-config.sh | 27 ++++++++++++++++
4 files changed, 99 insertions(+), 58 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index f4fccf99cb8..9b9f5527311 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -194,38 +194,42 @@ static void check_argc(int argc, int min, int max)
usage_builtin_config();
}
-static void show_config_origin(struct strbuf *buf)
+static void show_config_origin(const struct key_value_info *kvi,
+ struct strbuf *buf)
{
const char term = end_nul ? '\0' : '\t';
- strbuf_addstr(buf, current_config_origin_type());
+ strbuf_addstr(buf, config_origin_type_name(kvi->origin_type));
strbuf_addch(buf, ':');
if (end_nul)
- strbuf_addstr(buf, current_config_name());
+ strbuf_addstr(buf, kvi->filename ? kvi->filename : "");
else
- quote_c_style(current_config_name(), buf, NULL, 0);
+ quote_c_style(kvi->filename ? kvi->filename : "", buf, NULL, 0);
strbuf_addch(buf, term);
}
-static void show_config_scope(struct strbuf *buf)
+static void show_config_scope(const struct key_value_info *kvi,
+ struct strbuf *buf)
{
const char term = end_nul ? '\0' : '\t';
- const char *scope = config_scope_name(current_config_scope());
+ const char *scope = config_scope_name(kvi->scope);
strbuf_addstr(buf, N_(scope));
strbuf_addch(buf, term);
}
static int show_all_config(const char *key_, const char *value_,
- const struct config_context *ctx UNUSED,
+ const struct config_context *ctx,
void *cb UNUSED)
{
+ const struct key_value_info *kvi = ctx->kvi;
+
if (show_origin || show_scope) {
struct strbuf buf = STRBUF_INIT;
if (show_scope)
- show_config_scope(&buf);
+ show_config_scope(kvi, &buf);
if (show_origin)
- show_config_origin(&buf);
+ show_config_origin(kvi, &buf);
/* Use fwrite as "buf" can contain \0's if "end_null" is set. */
fwrite(buf.buf, 1, buf.len, stdout);
strbuf_release(&buf);
@@ -243,12 +247,13 @@ struct strbuf_list {
int alloc;
};
-static int format_config(struct strbuf *buf, const char *key_, const char *value_)
+static int format_config(struct strbuf *buf, const char *key_,
+ const char *value_, const struct key_value_info *kvi)
{
if (show_scope)
- show_config_scope(buf);
+ show_config_scope(kvi, buf);
if (show_origin)
- show_config_origin(buf);
+ show_config_origin(kvi, buf);
if (show_keys)
strbuf_addstr(buf, key_);
if (!omit_values) {
@@ -303,9 +308,10 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
}
static int collect_config(const char *key_, const char *value_,
- const struct config_context *ctx UNUSED, void *cb)
+ const struct config_context *ctx, void *cb)
{
struct strbuf_list *values = cb;
+ const struct key_value_info *kvi = ctx->kvi;
if (!use_key_regexp && strcmp(key_, key))
return 0;
@@ -320,7 +326,7 @@ static int collect_config(const char *key_, const char *value_,
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
strbuf_init(&values->items[values->nr], 0);
- return format_config(&values->items[values->nr++], key_, value_);
+ return format_config(&values->items[values->nr++], key_, value_, kvi);
}
static int get_value(const char *key_, const char *regex_, unsigned flags)
@@ -382,11 +388,14 @@ static int get_value(const char *key_, const char *regex_, unsigned flags)
&config_options);
if (!values.nr && default_value) {
+ struct key_value_info kvi = KVI_INIT;
struct strbuf *item;
+
+ kvi_from_param(&kvi);
ALLOC_GROW(values.items, values.nr + 1, values.alloc);
item = &values.items[values.nr++];
strbuf_init(item, 0);
- if (format_config(item, key_, default_value) < 0)
+ if (format_config(item, key_, default_value, &kvi) < 0)
die(_("failed to format default config value: %s"),
default_value);
}
@@ -563,15 +572,17 @@ static void check_write(void)
struct urlmatch_current_candidate_value {
char value_is_null;
struct strbuf value;
+ struct key_value_info kvi;
};
static int urlmatch_collect_fn(const char *var, const char *value,
- const struct config_context *ctx UNUSED,
+ const struct config_context *ctx,
void *cb)
{
struct string_list *values = cb;
struct string_list_item *item = string_list_insert(values, var);
struct urlmatch_current_candidate_value *matched = item->util;
+ const struct key_value_info *kvi = ctx->kvi;
if (!matched) {
matched = xmalloc(sizeof(*matched));
@@ -580,6 +591,7 @@ static int urlmatch_collect_fn(const char *var, const char *value,
} else {
strbuf_reset(&matched->value);
}
+ matched->kvi = *kvi;
if (value) {
strbuf_addstr(&matched->value, value);
@@ -627,7 +639,8 @@ static int get_urlmatch(const char *var, const char *url)
struct strbuf buf = STRBUF_INIT;
format_config(&buf, item->string,
- matched->value_is_null ? NULL : matched->value.buf);
+ matched->value_is_null ? NULL : matched->value.buf,
+ &matched->kvi);
fwrite(buf.buf, 1, buf.len, stdout);
strbuf_release(&buf);
diff --git a/config.c b/config.c
index 31718711827..4986942b091 100644
--- a/config.c
+++ b/config.c
@@ -219,7 +219,9 @@ static const char include_depth_advice[] = N_(
"from\n"
" %s\n"
"This might be due to circular includes.");
-static int handle_path_include(struct config_source *cs, const char *path,
+static int handle_path_include(struct config_source *cs,
+ const struct key_value_info *kvi,
+ const char *path,
struct config_include_data *inc)
{
int ret = 0;
@@ -260,8 +262,7 @@ static int handle_path_include(struct config_source *cs, const char *path,
cs->name ? cs->name :
"the command line");
ret = git_config_from_file_with_options(git_config_include, path, inc,
- current_config_scope(),
- NULL);
+ kvi->scope, NULL);
inc->depth--;
}
cleanup:
@@ -510,7 +511,7 @@ static int git_config_include(const char *var, const char *value,
return ret;
if (!strcmp(var, "include.path"))
- ret = handle_path_include(cs, value, inc);
+ ret = handle_path_include(cs, ctx->kvi, value, inc);
if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
cond && include_condition_is_true(cs, inc, cond, cond_len) &&
@@ -519,7 +520,7 @@ static int git_config_include(const char *var, const char *value,
if (inc->opts->unconditional_remote_url)
inc->fn = forbid_remote_url;
- ret = handle_path_include(cs, value, inc);
+ ret = handle_path_include(cs, ctx->kvi, value, inc);
inc->fn = old_fn;
}
@@ -677,27 +678,44 @@ out_free_ret_1:
}
static int config_parse_pair(const char *key, const char *value,
- config_fn_t fn, void *data)
+ struct key_value_info *kvi,
+ config_fn_t fn, void *data)
{
char *canonical_name;
int ret;
+ struct config_context ctx = {
+ .kvi = kvi,
+ };
if (!strlen(key))
return error(_("empty config key"));
if (git_config_parse_key(key, &canonical_name, NULL))
return -1;
- ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0;
+ ret = (fn(canonical_name, value, &ctx, data) < 0) ? -1 : 0;
free(canonical_name);
return ret;
}
+
+/* for values read from `git_config_from_parameters()` */
+void kvi_from_param(struct key_value_info *out)
+{
+ out->filename = NULL;
+ out->linenr = -1;
+ out->origin_type = CONFIG_ORIGIN_CMDLINE;
+ out->scope = CONFIG_SCOPE_COMMAND;
+}
+
int git_config_parse_parameter(const char *text,
config_fn_t fn, void *data)
{
const char *value;
struct strbuf **pair;
int ret;
+ struct key_value_info kvi = KVI_INIT;
+
+ kvi_from_param(&kvi);
pair = strbuf_split_str(text, '=', 2);
if (!pair[0])
@@ -716,12 +734,13 @@ int git_config_parse_parameter(const char *text,
return error(_("bogus config parameter: %s"), text);
}
- ret = config_parse_pair(pair[0]->buf, value, fn, data);
+ ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data);
strbuf_list_free(pair);
return ret;
}
-static int parse_config_env_list(char *env, config_fn_t fn, void *data)
+static int parse_config_env_list(char *env, struct key_value_info *kvi,
+ config_fn_t fn, void *data)
{
char *cur = env;
while (cur && *cur) {
@@ -755,7 +774,7 @@ static int parse_config_env_list(char *env, config_fn_t fn, void *data)
CONFIG_DATA_ENVIRONMENT);
}
- if (config_parse_pair(key, value, fn, data) < 0)
+ if (config_parse_pair(key, value, kvi, fn, data) < 0)
return -1;
}
else {
@@ -780,10 +799,13 @@ int git_config_from_parameters(config_fn_t fn, void *data)
int ret = 0;
char *envw = NULL;
struct config_source source = CONFIG_SOURCE_INIT;
+ struct key_value_info kvi = KVI_INIT;
source.origin_type = CONFIG_ORIGIN_CMDLINE;
config_reader_push_source(&the_reader, &source);
+ kvi_from_param(&kvi);
+
env = getenv(CONFIG_COUNT_ENVIRONMENT);
if (env) {
unsigned long count;
@@ -819,7 +841,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
}
strbuf_reset(&envvar);
- if (config_parse_pair(key, value, fn, data) < 0) {
+ if (config_parse_pair(key, value, &kvi, fn, data) < 0) {
ret = -1;
goto out;
}
@@ -830,7 +852,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
if (env) {
/* sq_dequote will write over it */
envw = xstrdup(env);
- if (parse_config_env_list(envw, fn, data) < 0) {
+ if (parse_config_env_list(envw, &kvi, fn, data) < 0) {
ret = -1;
goto out;
}
@@ -2442,7 +2464,8 @@ static int configset_find_element(struct config_set *set, const char *key,
return 0;
}
-static int configset_add_value(struct config_reader *reader,
+static int configset_add_value(const struct key_value_info *kvi_p,
+ struct config_reader *reader,
struct config_set *set, const char *key,
const char *value)
{
@@ -2476,13 +2499,9 @@ static int configset_add_value(struct config_reader *reader,
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);
} else {
- /* for values read from `git_config_from_parameters()` */
- kv_info->filename = NULL;
- kv_info->linenr = -1;
- kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
- kv_info->scope = reader->parsing_scope;
+ kvi_from_param(kv_info);
}
si->util = kv_info;
@@ -2538,11 +2557,12 @@ struct configset_add_data {
#define CONFIGSET_ADD_INIT { 0 }
static int config_set_callback(const char *key, const char *value,
- const struct config_context *ctx UNUSED,
+ const struct config_context *ctx,
void *cb)
{
struct configset_add_data *data = cb;
- configset_add_value(data->config_reader, data->config_set, key, value);
+ configset_add_value(ctx->kvi, data->config_reader, data->config_set,
+ key, value);
return 0;
}
@@ -4037,16 +4057,6 @@ const char *config_origin_type_name(enum config_origin_type type)
}
}
-const char *current_config_origin_type(void)
-{
- enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
-
- if (reader_origin_type(&the_reader, &type))
- BUG("current_config_origin_type called outside config callback");
-
- return config_origin_type_name(type);
-}
-
const char *config_scope_name(enum config_scope scope)
{
switch (scope) {
@@ -4078,14 +4088,6 @@ static int reader_config_name(struct config_reader *reader, const char **out)
return 0;
}
-const char *current_config_name(void)
-{
- const char *name;
- if (reader_config_name(&the_reader, &name))
- BUG("current_config_name called outside config callback");
- return name ? name : "";
-}
-
enum config_scope current_config_scope(void)
{
if (the_reader.config_kvi)
diff --git a/config.h b/config.h
index 206bf1f175a..ea92392400e 100644
--- a/config.h
+++ b/config.h
@@ -387,9 +387,8 @@ void git_global_config(char **user, char **xdg);
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
enum config_scope current_config_scope(void);
-const char *current_config_origin_type(void);
-const char *current_config_name(void);
const char *config_origin_type_name(enum config_origin_type type);
+void kvi_from_param(struct key_value_info *out);
/*
* Match and parse a config key of the form:
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 86bfbc2b364..387d336c91f 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -1668,6 +1668,21 @@ test_expect_success 'urlmatch' '
test_cmp expect actual
'
+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
+'
+
test_expect_success 'urlmatch favors more specific URLs' '
cat >.git/config <<-\EOF &&
[http "https://example.com/"]
@@ -2055,6 +2070,12 @@ test_expect_success '--show-origin blob ref' '
test_cmp expect output
'
+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
@@ -2123,6 +2144,12 @@ test_expect_success '--show-scope with --show-origin' '
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 &&
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 07/11] trace2: plumb config kvi
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
There is a code path starting from trace2_def_param_fl() that eventually
calls current_config_scope(), and thus it needs to have "kvi" plumbed
through it. Additional plumbing is also needed to get "kvi" to
trace2_def_param_fl(), which gets called by two code paths:
- Through tr2_cfg_cb(), which is a config callback, so it trivially
receives "kvi" via the "struct config_context ctx" parameter.
- Through tr2_list_env_vars_fl(), which is a high level function that
lists environment variables for tracing. This has been secretly
behaving like git_config_from_parameters() (in that it parses config
from environment variables/the CLI), but does not set config source
information.
Teach tr2_list_env_vars_fl() to be well-behaved by using
kvi_from_param(), which is used elsewhere for CLI/environment
variable-based config.
As a result, current_config_scope() has no more callers, so remove it.
Signed-off-by: Glen Choo <chooglen@google.com>
---
config.c | 46 -----------------------------------------
config.h | 1 -
trace2.c | 4 ++--
trace2.h | 3 ++-
trace2/tr2_cfg.c | 9 +++++---
trace2/tr2_tgt.h | 4 +++-
trace2/tr2_tgt_event.c | 4 ++--
trace2/tr2_tgt_normal.c | 4 ++--
trace2/tr2_tgt_perf.c | 4 ++--
9 files changed, 19 insertions(+), 60 deletions(-)
diff --git a/config.c b/config.c
index 4986942b091..d10faba56d3 100644
--- a/config.c
+++ b/config.c
@@ -85,16 +85,6 @@ struct config_reader {
*/
struct config_source *source;
struct key_value_info *config_kvi;
- /*
- * The "scope" of the current config source being parsed (repo, global,
- * etc). Like "source", this is only set when parsing a config source.
- * It's not part of "source" because it transcends a single file (i.e.,
- * a file included from .git/config is still in "repo" scope).
- *
- * When iterating through a configset, the equivalent value is
- * "config_kvi.scope" (see above).
- */
- enum config_scope parsing_scope;
};
/*
* Where possible, prefer to accept "struct config_reader" as an arg than to use
@@ -125,19 +115,9 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
static inline void config_reader_set_kvi(struct config_reader *reader,
struct key_value_info *kvi)
{
- if (kvi && (reader->source || reader->parsing_scope))
- BUG("kvi should not be set while parsing a config source");
reader->config_kvi = kvi;
}
-static inline void config_reader_set_scope(struct config_reader *reader,
- enum config_scope scope)
-{
- if (scope && reader->config_kvi)
- BUG("scope should only be set when iterating through a config source");
- reader->parsing_scope = scope;
-}
-
static int pack_compression_seen;
static int zlib_compression_seen;
@@ -412,19 +392,13 @@ static void populate_remote_urls(struct config_include_data *inc)
{
struct config_options opts;
- enum config_scope store_scope = inc->config_reader->parsing_scope;
-
opts = *inc->opts;
opts.unconditional_remote_url = 1;
- config_reader_set_scope(inc->config_reader, 0);
-
inc->remote_urls = xmalloc(sizeof(*inc->remote_urls));
string_list_init_dup(inc->remote_urls);
config_with_options(add_remote_url, inc->remote_urls,
inc->config_source, inc->repo, &opts);
-
- config_reader_set_scope(inc->config_reader, store_scope);
}
static int forbid_remote_url(const char *var, const char *value UNUSED,
@@ -2255,7 +2229,6 @@ static int do_git_config_sequence(struct config_reader *reader,
char *user_config = NULL;
char *repo_config;
char *worktree_config;
- enum config_scope prev_parsing_scope = reader->parsing_scope;
/*
* Ensure that either:
@@ -2273,7 +2246,6 @@ static int do_git_config_sequence(struct config_reader *reader,
worktree_config = NULL;
}
- config_reader_set_scope(reader, CONFIG_SCOPE_SYSTEM);
if (git_config_system() && system_config &&
!access_or_die(system_config, R_OK,
opts->system_gently ? ACCESS_EACCES_OK : 0))
@@ -2281,7 +2253,6 @@ static int do_git_config_sequence(struct config_reader *reader,
data, CONFIG_SCOPE_SYSTEM,
NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL);
git_global_config(&user_config, &xdg_config);
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
@@ -2292,13 +2263,11 @@ static int do_git_config_sequence(struct config_reader *reader,
ret += git_config_from_file_with_options(fn, user_config, data,
CONFIG_SCOPE_GLOBAL, NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL);
if (!opts->ignore_repo && repo_config &&
!access_or_die(repo_config, R_OK, 0))
ret += git_config_from_file_with_options(fn, repo_config, data,
CONFIG_SCOPE_LOCAL, NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE);
if (!opts->ignore_worktree && worktree_config &&
repo && repo->repository_format_worktree_config &&
!access_or_die(worktree_config, R_OK, 0)) {
@@ -2307,11 +2276,9 @@ static int do_git_config_sequence(struct config_reader *reader,
NULL);
}
- config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND);
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
die(_("unable to parse command-line config"));
- config_reader_set_scope(reader, prev_parsing_scope);
free(system_config);
free(xdg_config);
free(user_config);
@@ -2326,7 +2293,6 @@ int config_with_options(config_fn_t fn, void *data,
const struct config_options *opts)
{
struct config_include_data inc = CONFIG_INCLUDE_INIT;
- enum config_scope prev_scope = the_reader.parsing_scope;
int ret;
if (opts->respect_includes) {
@@ -2340,9 +2306,6 @@ int config_with_options(config_fn_t fn, void *data,
data = &inc;
}
- if (config_source)
- config_reader_set_scope(&the_reader, config_source->scope);
-
/*
* If we have a specific filename, use it. Otherwise, follow the
* regular lookup sequence.
@@ -2364,7 +2327,6 @@ int config_with_options(config_fn_t fn, void *data,
string_list_clear(inc.remote_urls, 0);
FREE_AND_NULL(inc.remote_urls);
}
- config_reader_set_scope(&the_reader, prev_scope);
return ret;
}
@@ -4088,14 +4050,6 @@ static int reader_config_name(struct config_reader *reader, const char **out)
return 0;
}
-enum config_scope current_config_scope(void)
-{
- if (the_reader.config_kvi)
- return the_reader.config_kvi->scope;
- else
- return the_reader.parsing_scope;
-}
-
int lookup_config(const char **mapping, int nr_mapping, const char *var)
{
int i;
diff --git a/config.h b/config.h
index ea92392400e..82eeba94e71 100644
--- a/config.h
+++ b/config.h
@@ -386,7 +386,6 @@ void git_global_config(char **user, char **xdg);
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
-enum config_scope current_config_scope(void);
const char *config_origin_type_name(enum config_origin_type type);
void kvi_from_param(struct key_value_info *out);
diff --git a/trace2.c b/trace2.c
index 0efc4e7b958..49c23bfd05a 100644
--- a/trace2.c
+++ b/trace2.c
@@ -634,7 +634,7 @@ void trace2_thread_exit_fl(const char *file, int line)
}
void trace2_def_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
struct tr2_tgt *tgt_j;
int j;
@@ -644,7 +644,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_param_fl)
- tgt_j->pfn_param_fl(file, line, param, value);
+ tgt_j->pfn_param_fl(file, line, param, value, kvi);
}
void trace2_def_repo_fl(const char *file, int line, struct repository *repo)
diff --git a/trace2.h b/trace2.h
index 4ced30c0db3..f5c5a9e6bac 100644
--- a/trace2.h
+++ b/trace2.h
@@ -325,6 +325,7 @@ void trace2_thread_exit_fl(const char *file, int line);
#define trace2_thread_exit() trace2_thread_exit_fl(__FILE__, __LINE__)
+struct key_value_info;
/*
* Emits a "def_param" message containing a key/value pair.
*
@@ -334,7 +335,7 @@ void trace2_thread_exit_fl(const char *file, int line);
* `core.abbrev`, `status.showUntrackedFiles`, or `--no-ahead-behind`.
*/
void trace2_def_param_fl(const char *file, int line, const char *param,
- const char *value);
+ const char *value, const struct key_value_info *kvi);
#define trace2_def_param(param, value) \
trace2_def_param_fl(__FILE__, __LINE__, (param), (value))
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 83bc4fd109c..733d9d2872a 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -100,7 +100,7 @@ struct tr2_cfg_data {
* See if the given config key matches any of our patterns of interest.
*/
static int tr2_cfg_cb(const char *key, const char *value,
- const struct config_context *ctx UNUSED, void *d)
+ const struct config_context *ctx, void *d)
{
struct strbuf **s;
struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
@@ -109,7 +109,8 @@ static int tr2_cfg_cb(const char *key, const char *value,
struct strbuf *buf = *s;
int wm = wildmatch(buf->buf, key, WM_CASEFOLD);
if (wm == WM_MATCH) {
- trace2_def_param_fl(data->file, data->line, key, value);
+ trace2_def_param_fl(data->file, data->line, key, value,
+ ctx->kvi);
return 0;
}
}
@@ -127,8 +128,10 @@ void tr2_cfg_list_config_fl(const char *file, int line)
void tr2_list_env_vars_fl(const char *file, int line)
{
+ struct key_value_info kvi = KVI_INIT;
struct strbuf **s;
+ kvi_from_param(&kvi);
if (tr2_load_env_vars() <= 0)
return;
@@ -136,7 +139,7 @@ void tr2_list_env_vars_fl(const char *file, int line)
struct strbuf *buf = *s;
const char *val = getenv(buf->buf);
if (val && *val)
- trace2_def_param_fl(file, line, buf->buf, val);
+ trace2_def_param_fl(file, line, buf->buf, val, &kvi);
}
}
diff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h
index bf8745c4f05..1f626cffea0 100644
--- a/trace2/tr2_tgt.h
+++ b/trace2/tr2_tgt.h
@@ -69,8 +69,10 @@ typedef void(tr2_tgt_evt_exec_result_fl_t)(const char *file, int line,
uint64_t us_elapsed_absolute,
int exec_id, int code);
+struct key_value_info;
typedef void(tr2_tgt_evt_param_fl_t)(const char *file, int line,
- const char *param, const char *value);
+ const char *param, const char *value,
+ const struct key_value_info *kvi);
typedef void(tr2_tgt_evt_repo_fl_t)(const char *file, int line,
const struct repository *repo);
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index 2af53e5d4de..53091781eca 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -477,11 +477,11 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
const char *event_name = "def_param";
struct json_writer jw = JSON_WRITER_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
jw_object_begin(&jw, 0);
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index 1ebfb464d54..d25ea131643 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -297,10 +297,10 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
struct strbuf buf_payload = STRBUF_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index 328e483a05e..a6f9a8a193e 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -439,12 +439,12 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
const char *event_name = "def_param";
struct strbuf buf_payload = STRBUF_INIT;
struct strbuf scope_payload = STRBUF_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
strbuf_addf(&buf_payload, "%s:%s", param, value);
--
gitgitgadget
^ permalink raw reply related
* [PATCH v5 03/11] config: add ctx arg to config_fn_t
From: Glen Choo via GitGitGadget @ 2023-06-28 19:26 UTC (permalink / raw)
To: git
Cc: Jonathan Tan, Ævar Arnfjörð Bjarmason,
Emily Shaffer, Phillip Wood, Jeff King, Glen Choo, Glen Choo
In-Reply-To: <pull.1497.v5.git.git.1687980390.gitgitgadget@gmail.com>
From: Glen Choo <chooglen@google.com>
Add a new "const struct config_context *ctx" arg to config_fn_t to hold
additional information about the config iteration operation.
config_context has a "struct key_value_info kvi" member that holds
metadata about the config source being read (e.g. what kind of config
source it is, the filename, etc). In this series, we're only interested
in .kvi, so we could have just used "struct key_value_info" as an arg,
but config_context makes it possible to add/adjust members in the future
without changing the config_fn_t signature. We could also consider other
ways of organizing the args (e.g. moving the config name and value into
config_context or key_value_info), but in my experiments, the
incremental benefit doesn't justify the added complexity (e.g. a
config_fn_t will sometimes invoke another config_fn_t but with a
different config value).
In subsequent commits, the .kvi member will replace the global "struct
config_reader" in config.c, making config iteration a global-free
operation. It requires much more work for the machinery to provide
meaningful values of .kvi, so for now, merely change the signature and
call sites, pass NULL as a placeholder value, and don't rely on the arg
in any meaningful way.
Most of the changes are performed by
contrib/coccinelle/config_fn_ctx.pending.cocci, which, for every
config_fn_t:
- Modifies the signature to accept "const struct config_context *ctx"
- Passes "ctx" to any inner config_fn_t, if needed
- Adds UNUSED attributes to "ctx", if needed
Most config_fn_t instances are easily identified by seeing if they are
called by the various config functions. Most of the remaining ones are
manually named in the .cocci patch. Manual cleanups are still needed,
but the majority of it is trivial; it's either adjusting config_fn_t
that the .cocci patch didn't catch, or adding forward declarations of
"struct config_context ctx" to make the signatures make sense.
The non-trivial changes are in cases where we are invoking a config_fn_t
outside of config machinery, and we now need to decide what value of
"ctx" to pass. These cases are:
- trace2/tr2_cfg.c:tr2_cfg_set_fl()
This is indirectly called by git_config_set() so that the trace2
machinery can notice the new config values and update its settings
using the tr2 config parsing function, i.e. tr2_cfg_cb().
- builtin/checkout.c:checkout_main()
This calls git_xmerge_config() as a shorthand for parsing a CLI arg.
This might be worth refactoring away in the future, since
git_xmerge_config() can call git_default_config(), which can do much
more than just parsing.
Handle them by creating a KVI_INIT macro that initializes "struct
key_value_info" to a reasonable default, and use that to construct the
"ctx" arg.
Signed-off-by: Glen Choo <chooglen@google.com>
---
alias.c | 3 +-
archive-tar.c | 3 +-
archive-zip.c | 1 +
builtin/add.c | 5 +-
builtin/blame.c | 5 +-
builtin/branch.c | 5 +-
builtin/cat-file.c | 5 +-
builtin/checkout.c | 12 +-
builtin/clean.c | 5 +-
builtin/clone.c | 11 +-
builtin/column.c | 3 +-
builtin/commit-graph.c | 1 +
builtin/commit.c | 10 +-
builtin/config.c | 10 +-
builtin/difftool.c | 5 +-
builtin/fetch.c | 9 +-
builtin/fsmonitor--daemon.c | 5 +-
builtin/grep.c | 7 +-
builtin/help.c | 5 +-
builtin/index-pack.c | 5 +-
builtin/log.c | 10 +-
builtin/merge.c | 7 +-
builtin/multi-pack-index.c | 1 +
builtin/pack-objects.c | 5 +-
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 | 5 +-
builtin/reflog.c | 7 +-
builtin/remote.c | 7 +-
builtin/repack.c | 5 +-
builtin/reset.c | 5 +-
builtin/send-pack.c | 5 +-
builtin/show-branch.c | 5 +-
builtin/stash.c | 5 +-
builtin/submodule--helper.c | 1 +
builtin/tag.c | 5 +-
builtin/var.c | 5 +-
builtin/worktree.c | 5 +-
bundle-uri.c | 8 +-
compat/mingw.c | 3 +-
compat/mingw.h | 4 +-
config.c | 38 +++--
config.h | 41 +++--
connect.c | 4 +-
.../coccinelle/config_fn_ctx.pending.cocci | 144 ++++++++++++++++++
convert.c | 4 +-
credential.c | 1 +
delta-islands.c | 4 +-
diff.c | 10 +-
diff.h | 7 +-
fetch-pack.c | 5 +-
fmt-merge-msg.c | 5 +-
fmt-merge-msg.h | 3 +-
fsck.c | 9 +-
fsck.h | 4 +-
git-compat-util.h | 2 +
gpg-interface.c | 7 +-
grep.c | 7 +-
grep.h | 4 +-
help.c | 7 +-
http.c | 5 +-
ident.c | 4 +-
ident.h | 4 +-
imap-send.c | 5 +-
ll-merge.c | 1 +
ls-refs.c | 1 +
mailinfo.c | 5 +-
notes-utils.c | 4 +-
notes.c | 4 +-
| 5 +-
pretty.c | 1 +
promisor-remote.c | 4 +-
remote.c | 3 +-
revision.c | 4 +-
scalar.c | 4 +-
sequencer.c | 9 +-
setup.c | 16 +-
submodule-config.c | 17 ++-
t/helper/test-config.c | 11 +-
t/helper/test-userdiff.c | 4 +-
trace2/tr2_cfg.c | 9 +-
trace2/tr2_sysenv.c | 3 +-
trailer.c | 2 +
upload-pack.c | 8 +-
urlmatch.c | 7 +-
urlmatch.h | 3 +-
xdiff-interface.c | 5 +-
xdiff-interface.h | 4 +-
91 files changed, 515 insertions(+), 181 deletions(-)
create mode 100644 contrib/coccinelle/config_fn_ctx.pending.cocci
diff --git a/alias.c b/alias.c
index 54a1a23d2cf..910dd252a01 100644
--- a/alias.c
+++ b/alias.c
@@ -12,7 +12,8 @@ struct config_alias_data {
struct string_list *list;
};
-static int config_alias_cb(const char *key, const char *value, void *d)
+static int config_alias_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
struct config_alias_data *data = d;
const char *p;
diff --git a/archive-tar.c b/archive-tar.c
index 4cd81d8161e..ef06e516b1f 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -411,7 +411,8 @@ static int tar_filter_config(const char *var, const char *value,
return 0;
}
-static int git_tar_config(const char *var, const char *value, void *cb)
+static int git_tar_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) {
diff --git a/archive-zip.c b/archive-zip.c
index d0d065a312e..b6811951955 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -617,6 +617,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
}
static int archive_zip_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
return userdiff_config(var, value);
diff --git a/builtin/add.c b/builtin/add.c
index e01efdfc50d..1009ae13c13 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -357,7 +357,8 @@ static struct option builtin_add_options[] = {
OPT_END(),
};
-static int add_config(const char *var, const char *value, void *cb)
+static int add_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "add.ignoreerrors") ||
!strcmp(var, "add.ignore-errors")) {
@@ -368,7 +369,7 @@ static int add_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static const char embedded_advice[] = N_(
diff --git a/builtin/blame.c b/builtin/blame.c
index 2df6039a6e0..d0970a1ab13 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -694,7 +694,8 @@ static const char *add_prefix(const char *prefix, const char *path)
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
}
-static int git_blame_config(const char *var, const char *value, void *cb)
+static int git_blame_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "blame.showroot")) {
show_root = git_config_bool(var, value);
@@ -767,7 +768,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
if (userdiff_config(var, value) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int blame_copy_callback(const struct option *option, const char *arg, int unset)
diff --git a/builtin/branch.c b/builtin/branch.c
index 8337b9e71bb..af6d2e75fb0 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -83,7 +83,8 @@ static unsigned int colopts;
define_list_config_array(color_branch_slots);
-static int git_branch_config(const char *var, const char *value, void *cb)
+static int git_branch_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -120,7 +121,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static const char *branch_get_color(enum color_branch ix)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 7ff56d5a781..b3c41b54c8d 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -873,12 +873,13 @@ static int batch_objects(struct batch_options *opt)
return retval;
}
-static int git_cat_file_config(const char *var, const char *value, void *cb)
+static int git_cat_file_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (userdiff_config(var, value) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int batch_option_callback(const struct option *opt,
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 715eeb5048f..4e1f7dc26c2 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1186,7 +1186,8 @@ static int switch_branches(const struct checkout_opts *opts,
return ret || writeout_error;
}
-static int git_checkout_config(const char *var, const char *value, void *cb)
+static int git_checkout_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct checkout_opts *opts = cb;
@@ -1202,7 +1203,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
if (starts_with(var, "submodule."))
return git_default_submodule_config(var, value, NULL);
- return git_xmerge_config(var, value, NULL);
+ return git_xmerge_config(var, value, ctx, NULL);
}
static void setup_new_branch_info_and_source_tree(
@@ -1689,8 +1690,13 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
}
if (opts->conflict_style) {
+ struct key_value_info kvi = KVI_INIT;
+ struct config_context ctx = {
+ .kvi = &kvi,
+ };
opts->merge = 1; /* implied */
- git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
+ git_xmerge_config("merge.conflictstyle", opts->conflict_style,
+ &ctx, NULL);
}
if (opts->force) {
opts->discard_changes = 1;
diff --git a/builtin/clean.c b/builtin/clean.c
index 57e7f7cac64..5eff1b802a7 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -103,7 +103,8 @@ struct menu_stuff {
define_list_config_array(color_interactive_slots);
-static int git_clean_config(const char *var, const char *value, void *cb)
+static int git_clean_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -133,7 +134,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static const char *clean_get_color(enum color_clean ix)
diff --git a/builtin/clone.c b/builtin/clone.c
index 15f9912b4ca..c0f6e067493 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -790,7 +790,8 @@ static int checkout(int submodule_progress, int filter_submodules)
return err;
}
-static int git_clone_config(const char *k, const char *v, void *cb)
+static int git_clone_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "clone.defaultremotename")) {
free(remote_name);
@@ -801,17 +802,19 @@ static int git_clone_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "clone.filtersubmodules"))
config_filter_submodules = git_config_bool(k, v);
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
-static int write_one_config(const char *key, const char *value, void *data)
+static int write_one_config(const char *key, const char *value,
+ const struct config_context *ctx,
+ void *data)
{
/*
* give git_clone_config a chance to write config values back to the
* environment, since git_config_set_multivar_gently only deals with
* config-file writes
*/
- int apply_failed = git_clone_config(key, value, data);
+ int apply_failed = git_clone_config(key, value, ctx, data);
if (apply_failed)
return apply_failed;
diff --git a/builtin/column.c b/builtin/column.c
index de623a16c2d..4a6148ca479 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -13,7 +13,8 @@ static const char * const builtin_column_usage[] = {
};
static unsigned int colopts;
-static int column_config(const char *var, const char *value, void *cb)
+static int column_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
return git_column_config(var, value, cb, &colopts);
}
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index dd732b35348..1185c49239a 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -186,6 +186,7 @@ static int write_option_max_new_filters(const struct option *opt,
}
static int git_commit_graph_write_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, "commitgraph.maxnewfilters"))
diff --git a/builtin/commit.c b/builtin/commit.c
index 9ab57ea1aaa..6a2b2503328 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1405,7 +1405,8 @@ static int parse_status_slot(const char *slot)
return LOOKUP_CONFIG(color_status_slots, slot);
}
-static int git_status_config(const char *k, const char *v, void *cb)
+static int git_status_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
const char *slot_name;
@@ -1490,7 +1491,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
s->detect_rename = git_config_rename(k, v);
return 0;
}
- return git_diff_ui_config(k, v, NULL);
+ return git_diff_ui_config(k, v, ctx, NULL);
}
int cmd_status(int argc, const char **argv, const char *prefix)
@@ -1605,7 +1606,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
return 0;
}
-static int git_commit_config(const char *k, const char *v, void *cb)
+static int git_commit_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
@@ -1627,7 +1629,7 @@ static int git_commit_config(const char *k, const char *v, void *cb)
return 0;
}
- return git_status_config(k, v, s);
+ return git_status_config(k, v, ctx, s);
}
int cmd_commit(int argc, const char **argv, const char *prefix)
diff --git a/builtin/config.c b/builtin/config.c
index d40fddb042a..f4fccf99cb8 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -217,6 +217,7 @@ static void show_config_scope(struct strbuf *buf)
}
static int show_all_config(const char *key_, const char *value_,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (show_origin || show_scope) {
@@ -301,7 +302,8 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
return 0;
}
-static int collect_config(const char *key_, const char *value_, void *cb)
+static int collect_config(const char *key_, const char *value_,
+ const struct config_context *ctx UNUSED, void *cb)
{
struct strbuf_list *values = cb;
@@ -470,6 +472,7 @@ static const char *get_colorbool_slot;
static char parsed_color[COLOR_MAXLEN];
static int git_get_color_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, get_color_slot)) {
@@ -503,6 +506,7 @@ static int get_colorbool_found;
static int get_diff_color_found;
static int get_color_ui_found;
static int git_get_colorbool_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
if (!strcmp(var, get_colorbool_slot))
@@ -561,7 +565,9 @@ struct urlmatch_current_candidate_value {
struct strbuf value;
};
-static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
+static int urlmatch_collect_fn(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct string_list *values = cb;
struct string_list_item *item = string_list_insert(values, var);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 0049342f5c0..f289530068b 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -40,14 +40,15 @@ static const char *const builtin_difftool_usage[] = {
NULL
};
-static int difftool_config(const char *var, const char *value, void *cb)
+static int difftool_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "difftool.trustexitcode")) {
trust_exit_code = git_config_bool(var, value);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int print_tool_help(void)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index e3871048cf6..a4aa0fbb8f5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -110,7 +110,8 @@ struct fetch_config {
int submodule_fetch_jobs;
};
-static int git_fetch_config(const char *k, const char *v, void *cb)
+static int git_fetch_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct fetch_config *fetch_config = cb;
@@ -164,7 +165,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
"fetch.output", v);
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@@ -1799,7 +1800,9 @@ struct remote_group_data {
struct string_list *list;
};
-static int get_remote_group(const char *key, const char *value, void *priv)
+static int get_remote_group(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *priv)
{
struct remote_group_data *g = priv;
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index f6dd9a784c1..91a776e2f17 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -37,7 +37,8 @@ static int fsmonitor__start_timeout_sec = 60;
#define FSMONITOR__ANNOUNCE_STARTUP "fsmonitor.announcestartup"
static int fsmonitor__announce_startup = 0;
-static int fsmonitor_config(const char *var, const char *value, void *cb)
+static int fsmonitor_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
int i = git_config_int(var, value);
@@ -67,7 +68,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
diff --git a/builtin/grep.c b/builtin/grep.c
index 76cf999d310..757d52b94ec 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -290,13 +290,14 @@ static int wait_all(void)
return hit;
}
-static int grep_cmd_config(const char *var, const char *value, void *cb)
+static int grep_cmd_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
- int st = grep_config(var, value, cb);
+ int st = grep_config(var, value, ctx, cb);
if (git_color_config(var, value, cb) < 0)
st = -1;
- else if (git_default_config(var, value, cb) < 0)
+ else if (git_default_config(var, value, ctx, cb) < 0)
st = -1;
if (!strcmp(var, "grep.threads")) {
diff --git a/builtin/help.c b/builtin/help.c
index d3cf4af3f6e..c348f201254 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -398,7 +398,8 @@ static int add_man_viewer_info(const char *var, const char *value)
return 0;
}
-static int git_help_config(const char *var, const char *value, void *cb)
+static int git_help_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "help.format")) {
if (!value)
@@ -421,7 +422,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
if (starts_with(var, "man."))
return add_man_viewer_info(var, value);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static struct cmdnames main_cmds, other_cmds;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d0d8067510b..de8884ea5c2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1581,7 +1581,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
strbuf_release(&pack_name);
}
-static int git_index_pack_config(const char *k, const char *v, void *cb)
+static int git_index_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct pack_idx_option *opts = cb;
@@ -1608,7 +1609,7 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
else
opts->flags &= ~WRITE_REV;
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
static int cmp_uint32(const void *a_, const void *b_)
diff --git a/builtin/log.c b/builtin/log.c
index c85f13a5d5e..09d6a13075b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -564,7 +564,8 @@ static int cmd_log_walk(struct rev_info *rev)
return retval;
}
-static int git_log_config(const char *var, const char *value, void *cb)
+static int git_log_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -613,7 +614,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_diff_ui_config(var, value, cb);
+ return git_diff_ui_config(var, value, ctx, cb);
}
int cmd_whatchanged(int argc, const char **argv, const char *prefix)
@@ -979,7 +980,8 @@ static enum cover_from_description parse_cover_from_description(const char *arg)
die(_("%s: invalid cover from description mode"), arg);
}
-static int git_format_config(const char *var, const char *value, void *cb)
+static int git_format_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "format.headers")) {
if (!value)
@@ -1108,7 +1110,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "diff.noprefix"))
return 0;
- return git_log_config(var, value, cb);
+ return git_log_config(var, value, ctx, cb);
}
static const char *output_directory = NULL;
diff --git a/builtin/merge.c b/builtin/merge.c
index 8da3e46abb0..cad624fb797 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -623,7 +623,8 @@ static void parse_branch_merge_options(char *bmo)
free(argv);
}
-static int git_merge_config(const char *k, const char *v, void *cb)
+static int git_merge_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
int status;
const char *str;
@@ -668,10 +669,10 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return 0;
}
- status = fmt_merge_msg_config(k, v, cb);
+ status = fmt_merge_msg_config(k, v, ctx, cb);
if (status)
return status;
- return git_diff_ui_config(k, v, cb);
+ return git_diff_ui_config(k, v, ctx, cb);
}
static int read_tree_trivial(struct object_id *common, struct object_id *head,
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1b5083f8b26..a0a7b82cc69 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -82,6 +82,7 @@ static struct option *add_common_options(struct option *prev)
}
static int git_multi_pack_index_write_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, "pack.writebitmaphashcache")) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 3af2d84f589..34aa0b483a0 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3135,7 +3135,8 @@ static void prepare_pack(int window, int depth)
free(delta_list);
}
-static int git_pack_config(const char *k, const char *v, void *cb)
+static int git_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "pack.window")) {
window = git_config_int(k, v);
@@ -3227,7 +3228,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
ex->uri = xstrdup(pack_end + 1);
oidmap_put(&configured_exclusions, ex);
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
/* Counters for trace2 output when in --stdin-packs mode. */
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 9d5585d3a72..03eddd0fb82 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -196,7 +196,8 @@ struct patch_id_opts {
int verbatim;
};
-static int git_patch_id_config(const char *var, const char *value, void *cb)
+static int git_patch_id_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct patch_id_opts *opts = cb;
@@ -209,7 +210,7 @@ static int git_patch_id_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_patch_id(int argc, const char **argv, const char *prefix)
diff --git a/builtin/pull.c b/builtin/pull.c
index 0c7bac97b75..83fca5b1d46 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -361,7 +361,8 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified)
/**
* Read config variables.
*/
-static int git_pull_config(const char *var, const char *value, void *cb)
+static int git_pull_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "rebase.autostash")) {
config_autostash = git_config_bool(var, value);
@@ -374,7 +375,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
check_trust_level = 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/**
diff --git a/builtin/push.c b/builtin/push.c
index dbdf609daf3..a2f68f77324 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -510,7 +510,8 @@ static void set_push_cert_flags(int *flags, int v)
}
-static int git_push_config(const char *k, const char *v, void *cb)
+static int git_push_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
int *flags = cb;
@@ -577,7 +578,7 @@ static int git_push_config(const char *k, const char *v, void *cb)
return 0;
}
- return git_default_config(k, v, NULL);
+ return git_default_config(k, v, ctx, NULL);
}
int cmd_push(int argc, const char **argv, const char *prefix)
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 440f19b1b87..8877dd6d4b5 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -102,12 +102,13 @@ static int debug_merge(const struct cache_entry * const *stages,
return 0;
}
-static int git_read_tree_config(const char *var, const char *value, void *cb)
+static int git_read_tree_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ace1d5e8d11..60930e2d8e0 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -772,7 +772,8 @@ static void parse_rebase_merges_value(struct rebase_options *options, const char
die(_("Unknown rebase-merges mode: %s"), value);
}
-static int rebase_config(const char *var, const char *value, void *data)
+static int rebase_config(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
struct rebase_options *opts = data;
@@ -831,7 +832,7 @@ static int rebase_config(const char *var, const char *value, void *data)
return git_config_string(&opts->default_backend, var, value);
}
- return git_default_config(var, value, data);
+ return git_default_config(var, value, ctx, data);
}
static int checkout_up_to_date(struct rebase_options *options)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1a31a583674..94d9898aff7 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -139,7 +139,8 @@ static enum deny_action parse_deny_action(const char *var, const char *value)
return DENY_IGNORE;
}
-static int receive_pack_config(const char *var, const char *value, void *cb)
+static int receive_pack_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
int status = parse_hide_refs_config(var, value, "receive", &hidden_refs);
@@ -266,7 +267,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void show_ref(const char *path, const struct object_id *oid)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a1fa0c855f4..84251cc9517 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -108,7 +108,8 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
#define EXPIRE_TOTAL 01
#define EXPIRE_UNREACH 02
-static int reflog_expire_config(const char *var, const char *value, void *cb)
+static int reflog_expire_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *pattern, *key;
size_t pattern_len;
@@ -117,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
struct reflog_expire_cfg *ent;
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
if (!strcmp(key, "reflogexpire")) {
slot = EXPIRE_TOTAL;
@@ -128,7 +129,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
if (git_config_expiry_date(&expire, var, value))
return -1;
} else
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
if (!pattern) {
switch (slot) {
diff --git a/builtin/remote.c b/builtin/remote.c
index 1e0b137d977..87de81105e2 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -268,6 +268,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
#define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
static int config_read_branches(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *orig_key = key;
@@ -645,7 +646,7 @@ struct push_default_info
};
static int config_read_push_default(const char *key, const char *value,
- void *cb)
+ const struct config_context *ctx UNUSED, void *cb)
{
struct push_default_info* info = cb;
if (strcmp(key, "remote.pushdefault") ||
@@ -1494,7 +1495,9 @@ static int prune(int argc, const char **argv, const char *prefix)
return result;
}
-static int get_remote_default(const char *key, const char *value UNUSED, void *priv)
+static int get_remote_default(const char *key, const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
+ void *priv)
{
if (strcmp(key, "remotes.default") == 0) {
int *found = priv;
diff --git a/builtin/repack.c b/builtin/repack.c
index 0541c3ce157..6f74570bf94 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -59,7 +59,8 @@ struct pack_objects_args {
int local;
};
-static int repack_config(const char *var, const char *value, void *cb)
+static int repack_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct pack_objects_args *cruft_po_args = cb;
if (!strcmp(var, "repack.usedeltabaseoffset")) {
@@ -91,7 +92,7 @@ static int repack_config(const char *var, const char *value, void *cb)
return git_config_string(&cruft_po_args->depth, var, value);
if (!strcmp(var, "repack.cruftthreads"))
return git_config_string(&cruft_po_args->threads, var, value);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
diff --git a/builtin/reset.c b/builtin/reset.c
index f99f32d5802..1ae82f2e89c 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -312,12 +312,13 @@ static int reset_refs(const char *rev, const struct object_id *oid)
return update_ref_status;
}
-static int git_reset_config(const char *var, const char *value, void *cb)
+static int git_reset_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_reset(int argc, const char **argv, const char *prefix)
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 4784143004d..cd6d9e41129 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -131,7 +131,8 @@ static void print_helper_status(struct ref *ref)
strbuf_release(&buf);
}
-static int send_pack_config(const char *k, const char *v, void *cb)
+static int send_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "push.gpgsign")) {
const char *value;
@@ -151,7 +152,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
}
}
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
int cmd_send_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index a2461270d4b..f2fd245b838 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -559,7 +559,8 @@ static void append_one_rev(const char *av)
die("bad sha1 reference %s", av);
}
-static int git_show_branch_config(const char *var, const char *value, void *cb)
+static int git_show_branch_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "showbranch.default")) {
if (!value)
@@ -582,7 +583,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe384..e5c4246d2d4 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -837,7 +837,8 @@ static int show_stat = 1;
static int show_patch;
static int show_include_untracked;
-static int git_stash_config(const char *var, const char *value, void *cb)
+static int git_stash_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "stash.showstat")) {
show_stat = git_config_bool(var, value);
@@ -851,7 +852,7 @@ static int git_stash_config(const char *var, const char *value, void *cb)
show_include_untracked = git_config_bool(var, value);
return 0;
}
- return git_diff_basic_config(var, value, cb);
+ return git_diff_basic_config(var, value, ctx, cb);
}
static void diff_include_untracked(const struct stash_info *info, struct diff_options *diff_opt)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6a16208e8a8..f8e9d85e77a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2192,6 +2192,7 @@ static int update_clone_task_finished(int result,
}
static int git_update_clone_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb)
{
int *max_jobs = cb;
diff --git a/builtin/tag.c b/builtin/tag.c
index 1acf5f7a59f..b7dfb5e2cad 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -188,7 +188,8 @@ static const char tag_template_nocleanup[] =
"Lines starting with '%c' will be kept; you may remove them"
" yourself if you want to.\n");
-static int git_tag_config(const char *var, const char *value, void *cb)
+static int git_tag_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "tag.gpgsign")) {
config_sign_tag = git_config_bool(var, value);
@@ -213,7 +214,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void write_tag_body(int fd, const struct object_id *oid)
diff --git a/builtin/var.c b/builtin/var.c
index 21499989807..ae011bdf409 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -71,13 +71,14 @@ static const struct git_var *get_git_var(const char *var)
return NULL;
}
-static int show_config(const char *var, const char *value, void *cb)
+static int show_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (value)
printf("%s=%s\n", var, value);
else
printf("%s\n", var);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 5a9cf076ad2..a30d37a273f 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -128,14 +128,15 @@ static int verbose;
static int guess_remote;
static timestamp_t expire;
-static int git_worktree_config(const char *var, const char *value, void *cb)
+static int git_worktree_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "worktree.guessremote")) {
guess_remote = git_config_bool(var, value);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int delete_git_dir(const char *id)
diff --git a/bundle-uri.c b/bundle-uri.c
index 2a2db1a1d39..0d5acc3dc51 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -224,7 +224,9 @@ static int bundle_list_update(const char *key, const char *value,
return 0;
}
-static int config_to_bundle_list(const char *key, const char *value, void *data)
+static int config_to_bundle_list(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct bundle_list *list = data;
return bundle_list_update(key, value, list);
@@ -871,7 +873,9 @@ cached:
return advertise_bundle_uri;
}
-static int config_to_packet_line(const char *key, const char *value, void *data)
+static int config_to_packet_line(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct packet_reader *writer = data;
diff --git a/compat/mingw.c b/compat/mingw.c
index d06cdc6254f..4186bc7a417 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -244,7 +244,8 @@ static int core_restrict_inherited_handles = -1;
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
static char *unset_environment_variables;
-int mingw_core_config(const char *var, const char *value, void *cb)
+int mingw_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.hidedotfiles")) {
if (value && !strcasecmp(value, "dotgitonly"))
diff --git a/compat/mingw.h b/compat/mingw.h
index 209cf7cebad..5e34c873473 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -11,7 +11,9 @@ typedef _sigset_t sigset_t;
#undef _POSIX_THREAD_SAFE_FUNCTIONS
#endif
-int mingw_core_config(const char *var, const char *value, void *cb);
+struct config_context;
+int mingw_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
#define platform_core_config mingw_core_config
/*
diff --git a/config.c b/config.c
index 2eeb6621421..850e432e301 100644
--- a/config.c
+++ b/config.c
@@ -209,7 +209,8 @@ struct config_include_data {
};
#define CONFIG_INCLUDE_INIT { 0 }
-static int git_config_include(const char *var, const char *value, void *data);
+static int git_config_include(const char *var, const char *value,
+ const struct config_context *ctx, void *data);
#define MAX_INCLUDE_DEPTH 10
static const char include_depth_advice[] = N_(
@@ -388,7 +389,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
return ret;
}
-static int add_remote_url(const char *var, const char *value, void *data)
+static int add_remote_url(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct string_list *remote_urls = data;
const char *remote_name;
@@ -423,6 +425,7 @@ static void populate_remote_urls(struct config_include_data *inc)
}
static int forbid_remote_url(const char *var, const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *remote_name;
@@ -486,7 +489,9 @@ static int include_condition_is_true(struct config_source *cs,
return 0;
}
-static int git_config_include(const char *var, const char *value, void *data)
+static int git_config_include(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *data)
{
struct config_include_data *inc = data;
struct config_source *cs = inc->config_reader->source;
@@ -498,7 +503,7 @@ static int git_config_include(const char *var, const char *value, void *data)
* Pass along all values, including "include" directives; this makes it
* possible to query information on the includes themselves.
*/
- ret = inc->fn(var, value, inc->data);
+ ret = inc->fn(var, value, NULL, inc->data);
if (ret < 0)
return ret;
@@ -680,7 +685,7 @@ static int config_parse_pair(const char *key, const char *value,
if (git_config_parse_key(key, &canonical_name, NULL))
return -1;
- ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
+ ret = (fn(canonical_name, value, NULL, data) < 0) ? -1 : 0;
free(canonical_name);
return ret;
}
@@ -968,7 +973,7 @@ static int get_value(struct config_source *cs, config_fn_t fn, void *data,
* accurate line number in error messages.
*/
cs->linenr--;
- ret = fn(name->buf, value, data);
+ ret = fn(name->buf, value, NULL, data);
if (ret >= 0)
cs->linenr++;
return ret;
@@ -1562,7 +1567,8 @@ int git_config_color(char *dest, const char *var, const char *value)
return 0;
}
-static int git_default_core_config(const char *var, const char *value, void *cb)
+static int git_default_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
/* This needs a better name */
if (!strcmp(var, "core.filemode")) {
@@ -1842,7 +1848,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
}
/* Add other config variables here and to Documentation/config.txt. */
- return platform_core_config(var, value, cb);
+ return platform_core_config(var, value, ctx, cb);
}
static int git_default_sparse_config(const char *var, const char *value)
@@ -1944,15 +1950,16 @@ static int git_default_mailmap_config(const char *var, const char *value)
return 0;
}
-int git_default_config(const char *var, const char *value, void *cb)
+int git_default_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (starts_with(var, "core."))
- return git_default_core_config(var, value, cb);
+ return git_default_core_config(var, value, ctx, cb);
if (starts_with(var, "user.") ||
starts_with(var, "author.") ||
starts_with(var, "committer."))
- return git_ident_config(var, value, cb);
+ return git_ident_config(var, value, ctx, cb);
if (starts_with(var, "i18n."))
return git_default_i18n_config(var, value);
@@ -2318,7 +2325,7 @@ static void configset_iter(struct config_reader *reader, struct config_set *set,
config_reader_set_kvi(reader, values->items[value_index].util);
- if (fn(entry->key, values->items[value_index].string, data) < 0)
+ if (fn(entry->key, values->items[value_index].string, NULL, data) < 0)
git_die_config_linenr(entry->key,
reader->config_kvi->filename,
reader->config_kvi->linenr);
@@ -2496,7 +2503,9 @@ struct configset_add_data {
};
#define CONFIGSET_ADD_INIT { 0 }
-static int config_set_callback(const char *key, const char *value, void *cb)
+static int config_set_callback(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct configset_add_data *data = cb;
configset_add_value(data->config_reader, data->config_set, key, value);
@@ -3106,7 +3115,8 @@ static int store_aux_event(enum config_event_t type,
return 0;
}
-static int store_aux(const char *key, const char *value, void *cb)
+static int store_aux(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
struct config_store_data *store = cb;
diff --git a/config.h b/config.h
index d1c5577589e..cd30125a8a4 100644
--- a/config.h
+++ b/config.h
@@ -110,8 +110,29 @@ struct config_options {
} error_action;
};
+/* Config source metadata for a given config key-value pair */
+struct key_value_info {
+ const char *filename;
+ int linenr;
+ enum config_origin_type origin_type;
+ enum config_scope scope;
+};
+#define KVI_INIT { \
+ .filename = NULL, \
+ .linenr = -1, \
+ .origin_type = CONFIG_ORIGIN_UNKNOWN, \
+ .scope = CONFIG_SCOPE_UNKNOWN, \
+}
+
+/* Captures additional information that a config callback can use. */
+struct config_context {
+ /* Config source metadata for key and value. */
+ const struct key_value_info *kvi;
+};
+#define CONFIG_CONTEXT_INIT { 0 }
+
/**
- * A config callback function takes three parameters:
+ * A config callback function takes four parameters:
*
* - the name of the parsed variable. This is in canonical "flat" form: the
* section, subsection, and variable segments will be separated by dots,
@@ -122,15 +143,22 @@ struct config_options {
* value specified, the value will be NULL (typically this means it
* should be interpreted as boolean true).
*
+ * - the 'config context', that is, additional information about the config
+ * iteration operation provided by the config machinery. For example, this
+ * includes information about the config source being parsed (e.g. the
+ * filename).
+ *
* - a void pointer passed in by the caller of the config API; this can
* contain callback-specific data
*
* A config callback should return 0 for success, or -1 if the variable
* could not be parsed properly.
*/
-typedef int (*config_fn_t)(const char *, const char *, void *);
+typedef int (*config_fn_t)(const char *, const char *,
+ const struct config_context *, void *);
-int git_default_config(const char *, const char *, void *);
+int git_default_config(const char *, const char *,
+ const struct config_context *, void *);
/**
* Read a specific file in git-config format.
@@ -667,13 +695,6 @@ int git_config_get_expiry(const char *key, const char **output);
/* parse either "this many days" integer, or "5.days.ago" approxidate */
int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
-struct key_value_info {
- const char *filename;
- int linenr;
- enum config_origin_type origin_type;
- enum config_scope scope;
-};
-
/**
* First prints the error message specified by the caller in `err` and then
* dies printing the line number and the file name of the highest priority
diff --git a/connect.c b/connect.c
index 3a0186280c4..cddac1d96b8 100644
--- a/connect.c
+++ b/connect.c
@@ -964,7 +964,7 @@ static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
static char *git_proxy_command;
static int git_proxy_command_options(const char *var, const char *value,
- void *cb)
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.gitproxy")) {
const char *for_pos;
@@ -1010,7 +1010,7 @@ static int git_proxy_command_options(const char *var, const char *value,
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int git_use_proxy(const char *host)
diff --git a/contrib/coccinelle/config_fn_ctx.pending.cocci b/contrib/coccinelle/config_fn_ctx.pending.cocci
new file mode 100644
index 00000000000..6d3d1000a96
--- /dev/null
+++ b/contrib/coccinelle/config_fn_ctx.pending.cocci
@@ -0,0 +1,144 @@
+@ get_fn @
+identifier fn, R;
+@@
+(
+(
+git_config_from_file
+|
+git_config_from_file_with_options
+|
+git_config_from_mem
+|
+git_config_from_blob_oid
+|
+read_early_config
+|
+read_very_early_config
+|
+config_with_options
+|
+git_config
+|
+git_protected_config
+|
+config_from_gitmodules
+)
+ (fn, ...)
+|
+repo_config(R, fn, ...)
+)
+
+@ extends get_fn @
+identifier C1, C2, D;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D);
+
+@ extends get_fn @
+@@
+int fn(const char *, const char *,
++ const struct config_context *,
+ void *);
+
+@ extends get_fn @
+// Don't change fns that look like callback fns but aren't
+identifier fn2 != tar_filter_config && != git_diff_heuristic_config &&
+ != git_default_submodule_config && != git_color_config &&
+ != bundle_list_update && != parse_object_filter_config;
+identifier C1, C2, D1, D2, S;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D1) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
+
+@ extends get_fn@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+
+// The previous rules don't catch all callbacks, especially if they're defined
+// in a separate file from the git_config() call. Fix these manually.
+@@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int
+(
+git_ident_config
+|
+urlmatch_collect_fn
+|
+write_one_config
+|
+forbid_remote_url
+|
+credential_config_callback
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+@@
+identifier C1, C2, D, D2, S, fn2;
+@@
+int
+(
+http_options
+|
+git_status_config
+|
+git_commit_config
+|
+git_default_core_config
+|
+grep_config
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
diff --git a/convert.c b/convert.c
index 9ee79fe4699..8e96cf83030 100644
--- a/convert.c
+++ b/convert.c
@@ -1015,7 +1015,9 @@ static int apply_filter(const char *path, const char *src, size_t len,
return 0;
}
-static int read_convert_config(const char *var, const char *value, void *cb UNUSED)
+static int read_convert_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
const char *key, *name;
size_t namelen;
diff --git a/credential.c b/credential.c
index 8825c6f1320..d6647541634 100644
--- a/credential.c
+++ b/credential.c
@@ -49,6 +49,7 @@ static int credential_from_potentially_partial_url(struct credential *c,
const char *url);
static int credential_config_callback(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data)
{
struct credential *c = data;
diff --git a/delta-islands.c b/delta-islands.c
index c824a5f6a42..5fc6ea6ff55 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -341,7 +341,9 @@ static void free_remote_islands(kh_str_t *remote_islands)
kh_destroy_str(remote_islands);
}
-static int island_config_callback(const char *k, const char *v, void *cb)
+static int island_config_callback(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct island_load_data *ild = cb;
diff --git a/diff.c b/diff.c
index c106f8a4ffa..0e382c8f7f0 100644
--- a/diff.c
+++ b/diff.c
@@ -357,7 +357,8 @@ static unsigned parse_color_moved_ws(const char *arg)
return ret;
}
-int git_diff_ui_config(const char *var, const char *value, void *cb)
+int git_diff_ui_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
diff_use_color_default = git_config_colorbool(var, value);
@@ -440,10 +441,11 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_diff_basic_config(var, value, cb);
+ return git_diff_basic_config(var, value, ctx, cb);
}
-int git_diff_basic_config(const char *var, const char *value, void *cb)
+int git_diff_basic_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *name;
@@ -495,7 +497,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
if (git_diff_heuristic_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static char *quote_two(const char *one, const char *two)
diff --git a/diff.h b/diff.h
index 6c10ce289da..33a4f4d5988 100644
--- a/diff.h
+++ b/diff.h
@@ -531,10 +531,13 @@ void free_diffstat_info(struct diffstat_t *diffstat);
int parse_long_opt(const char *opt, const char **argv,
const char **optarg);
-int git_diff_basic_config(const char *var, const char *value, void *cb);
+struct config_context;
+int git_diff_basic_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
void init_diff_ui_defaults(void);
-int git_diff_ui_config(const char *var, const char *value, void *cb);
+int git_diff_ui_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
void repo_diff_setup(struct repository *, struct diff_options *);
struct option *add_diff_options(const struct option *, struct diff_options *);
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f71054fbae..5f3d40f3d09 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1860,7 +1860,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
return ref;
}
-static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
+static int fetch_pack_config_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
const char *path;
@@ -1882,7 +1883,7 @@ static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void fetch_pack_config(void)
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 5af0d4715ba..10137444321 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -20,7 +20,8 @@ static int use_branch_desc;
static int suppress_dest_pattern_seen;
static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP;
-int fmt_merge_msg_config(const char *key, const char *value, void *cb)
+int fmt_merge_msg_config(const char *key, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
int is_bool;
@@ -40,7 +41,7 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb)
string_list_append(&suppress_dest_patterns, value);
suppress_dest_pattern_seen = 1;
} else {
- return git_default_config(key, value, cb);
+ return git_default_config(key, value, ctx, cb);
}
return 0;
}
diff --git a/fmt-merge-msg.h b/fmt-merge-msg.h
index 99054042dc5..73ca3e44652 100644
--- a/fmt-merge-msg.h
+++ b/fmt-merge-msg.h
@@ -13,7 +13,8 @@ struct fmt_merge_msg_opts {
};
extern int merge_log_config;
-int fmt_merge_msg_config(const char *key, const char *value, void *cb);
+int fmt_merge_msg_config(const char *key, const char *value,
+ const struct config_context *ctx, void *cb);
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct fmt_merge_msg_opts *);
diff --git a/fsck.c b/fsck.c
index 3261ef9ec28..55b6a694853 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1163,7 +1163,9 @@ struct fsck_gitmodules_data {
int ret;
};
-static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
+static int fsck_gitmodules_fn(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct fsck_gitmodules_data *data = vdata;
const char *subsection, *key;
@@ -1373,7 +1375,8 @@ int fsck_finish(struct fsck_options *options)
return ret;
}
-int git_fsck_config(const char *var, const char *value, void *cb)
+int git_fsck_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct fsck_options *options = cb;
if (strcmp(var, "fsck.skiplist") == 0) {
@@ -1394,7 +1397,7 @@ int git_fsck_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
diff --git a/fsck.h b/fsck.h
index e17730e9da9..6359ba359bd 100644
--- a/fsck.h
+++ b/fsck.h
@@ -233,10 +233,12 @@ void fsck_put_object_name(struct fsck_options *options,
const char *fsck_describe_object(struct fsck_options *options,
const struct object_id *oid);
+struct key_value_info;
/*
* git_config() callback for use by fsck-y tools that want to support
* fsck.<msg> fsck.skipList etc.
*/
-int git_fsck_config(const char *var, const char *value, void *cb);
+int git_fsck_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
#endif
diff --git a/git-compat-util.h b/git-compat-util.h
index 5b2b99c17c5..14e8aacb957 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -440,8 +440,10 @@ typedef uintmax_t timestamp_t;
#endif
#ifndef platform_core_config
+struct config_context;
static inline int noop_core_config(const char *var UNUSED,
const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
return 0;
diff --git a/gpg-interface.c b/gpg-interface.c
index 19a3471a0b5..57c862a3a22 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -14,7 +14,8 @@
#include "alias.h"
#include "wrapper.h"
-static int git_gpg_config(const char *, const char *, void *);
+static int git_gpg_config(const char *, const char *,
+ const struct config_context *, void *);
static void gpg_interface_lazy_init(void)
{
@@ -720,7 +721,9 @@ void set_signing_key(const char *key)
configured_signing_key = xstrdup(key);
}
-static int git_gpg_config(const char *var, const char *value, void *cb UNUSED)
+static int git_gpg_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
struct gpg_format *fmt = NULL;
char *fmtname = NULL;
diff --git a/grep.c b/grep.c
index f00986c451a..fc22c3e2afb 100644
--- a/grep.c
+++ b/grep.c
@@ -56,7 +56,8 @@ define_list_config_array_extra(color_grep_slots, {"match"});
* Read the configuration file once and store it in
* the grep_defaults template.
*/
-int grep_config(const char *var, const char *value, void *cb)
+int grep_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct grep_opt *opt = cb;
const char *slot;
@@ -91,9 +92,9 @@ int grep_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "color.grep"))
opt->color = git_config_colorbool(var, value);
if (!strcmp(var, "color.grep.match")) {
- if (grep_config("color.grep.matchcontext", value, cb) < 0)
+ if (grep_config("color.grep.matchcontext", value, ctx, cb) < 0)
return -1;
- if (grep_config("color.grep.matchselected", value, cb) < 0)
+ if (grep_config("color.grep.matchselected", value, ctx, cb) < 0)
return -1;
} else if (skip_prefix(var, "color.grep.", &slot)) {
int i = LOOKUP_CONFIG(color_grep_slots, slot);
diff --git a/grep.h b/grep.h
index c59592e3bdb..926c0875c42 100644
--- a/grep.h
+++ b/grep.h
@@ -202,7 +202,9 @@ struct grep_opt {
.output = std_output, \
}
-int grep_config(const char *var, const char *value, void *);
+struct config_context;
+int grep_config(const char *var, const char *value,
+ const struct config_context *ctx, void *data);
void grep_init(struct grep_opt *, struct repository *repo);
void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
diff --git a/help.c b/help.c
index 5d7637dce92..ac0ae5ac0dc 100644
--- a/help.c
+++ b/help.c
@@ -309,7 +309,8 @@ void load_command_list(const char *prefix,
exclude_cmds(other_cmds, main_cmds);
}
-static int get_colopts(const char *var, const char *value, void *data)
+static int get_colopts(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
unsigned int *colopts = data;
@@ -459,7 +460,8 @@ void list_developer_interfaces_help(void)
putchar('\n');
}
-static int get_alias(const char *var, const char *value, void *data)
+static int get_alias(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct string_list *list = data;
@@ -543,6 +545,7 @@ static struct cmdnames aliases;
#define AUTOCORRECT_IMMEDIATELY (-1)
static int git_unknown_cmd_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
const char *p;
diff --git a/http.c b/http.c
index bb58bb3e6a3..762502828c9 100644
--- a/http.c
+++ b/http.c
@@ -363,7 +363,8 @@ static void process_curl_messages(void)
}
}
-static int http_options(const char *var, const char *value, void *cb)
+static int http_options(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
if (!strcmp("http.version", var)) {
return git_config_string(&curl_http_version, var, value);
@@ -534,7 +535,7 @@ static int http_options(const char *var, const char *value, void *cb)
}
/* Fall back on the default ones */
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, data);
}
static int curl_empty_auth_enabled(void)
diff --git a/ident.c b/ident.c
index 8fad92d7007..08be4d0747d 100644
--- a/ident.c
+++ b/ident.c
@@ -671,7 +671,9 @@ static int set_ident(const char *var, const char *value)
return 0;
}
-int git_ident_config(const char *var, const char *value, void *data UNUSED)
+int git_ident_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data UNUSED)
{
if (!strcmp(var, "user.useconfigonly")) {
ident_use_config_only = git_config_bool(var, value);
diff --git a/ident.h b/ident.h
index 96a64896a01..6a79febba15 100644
--- a/ident.h
+++ b/ident.h
@@ -62,6 +62,8 @@ const char *fmt_name(enum want_ident);
int committer_ident_sufficiently_given(void);
int author_ident_sufficiently_given(void);
-int git_ident_config(const char *, const char *, void *);
+struct config_context;
+int git_ident_config(const char *, const char *, const struct config_context *,
+ void *);
#endif
diff --git a/imap-send.c b/imap-send.c
index 7f5426177a1..47777e76861 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1323,7 +1323,8 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
return 1;
}
-static int git_imap_config(const char *var, const char *val, void *cb)
+static int git_imap_config(const char *var, const char *val,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp("imap.sslverify", var))
@@ -1357,7 +1358,7 @@ static int git_imap_config(const char *var, const char *val, void *cb)
server.host = xstrdup(val);
}
} else
- return git_default_config(var, val, cb);
+ return git_default_config(var, val, ctx, cb);
return 0;
}
diff --git a/ll-merge.c b/ll-merge.c
index 07ec16e8e5b..3936d112e00 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -254,6 +254,7 @@ static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
static const char *default_ll_merge;
static int read_merge_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
struct ll_merge_driver *fn;
diff --git a/ls-refs.c b/ls-refs.c
index f385938b64c..a29c2364a59 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -137,6 +137,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data)
}
static int ls_refs_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb_data)
{
struct ls_refs_data *data = cb_data;
diff --git a/mailinfo.c b/mailinfo.c
index 2aeb20e5e62..931505363cd 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1241,12 +1241,13 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
return 0;
}
-static int git_mailinfo_config(const char *var, const char *value, void *mi_)
+static int git_mailinfo_config(const char *var, const char *value,
+ const struct config_context *ctx, void *mi_)
{
struct mailinfo *mi = mi_;
if (!starts_with(var, "mailinfo."))
- return git_default_config(var, value, NULL);
+ return git_default_config(var, value, ctx, NULL);
if (!strcmp(var, "mailinfo.scissors")) {
mi->use_scissors = git_config_bool(var, value);
return 0;
diff --git a/notes-utils.c b/notes-utils.c
index 4a793eb347f..97c031c26ec 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -94,7 +94,9 @@ static combine_notes_fn parse_combine_notes_fn(const char *v)
return NULL;
}
-static int notes_rewrite_config(const char *k, const char *v, void *cb)
+static int notes_rewrite_config(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct notes_rewrite_cfg *c = cb;
if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
diff --git a/notes.c b/notes.c
index f51a2d3630e..e68645a4b89 100644
--- a/notes.c
+++ b/notes.c
@@ -974,7 +974,9 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
free(globs_copy);
}
-static int notes_display_config(const char *k, const char *v, void *cb)
+static int notes_display_config(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
int *load_refs = cb;
--git a/pager.c b/pager.c
index 63055d0873f..b8822a9381e 100644
--- a/pager.c
+++ b/pager.c
@@ -43,6 +43,7 @@ static void wait_for_pager_signal(int signo)
}
static int core_pager_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
if (!strcmp(var, "core.pager"))
@@ -228,7 +229,9 @@ struct pager_command_config_data {
char *value;
};
-static int pager_command_config(const char *var, const char *value, void *vdata)
+static int pager_command_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct pager_command_config_data *data = vdata;
const char *cmd;
diff --git a/pretty.c b/pretty.c
index 0bb938021ba..87245353452 100644
--- a/pretty.c
+++ b/pretty.c
@@ -56,6 +56,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
}
static int git_pretty_formats_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
struct cmt_fmt_map *commit_format = NULL;
diff --git a/promisor-remote.c b/promisor-remote.c
index 1adcd6fb0a5..c22abb85b15 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -100,7 +100,9 @@ static void promisor_remote_move_to_tail(struct promisor_remote_config *config,
config->promisors_tail = &r->next;
}
-static int promisor_remote_config(const char *var, const char *value, void *data)
+static int promisor_remote_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct promisor_remote_config *config = data;
const char *name;
diff --git a/remote.c b/remote.c
index 1bcd36e358a..241999c2842 100644
--- a/remote.c
+++ b/remote.c
@@ -349,7 +349,8 @@ static void read_branches_file(struct remote_state *remote_state,
remote->fetch_tags = 1; /* always auto-follow */
}
-static int handle_config(const char *key, const char *value, void *cb)
+static int handle_config(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
const char *name;
size_t namelen;
diff --git a/revision.c b/revision.c
index b33cc1d106a..87ed8ccd444 100644
--- a/revision.c
+++ b/revision.c
@@ -1572,7 +1572,9 @@ struct exclude_hidden_refs_cb {
const char *section;
};
-static int hide_refs_config(const char *var, const char *value, void *cb_data)
+static int hide_refs_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
struct exclude_hidden_refs_cb *cb = cb_data;
cb->exclusions->hidden_refs_configured = 1;
diff --git a/scalar.c b/scalar.c
index 1326e1f6089..df7358f481c 100644
--- a/scalar.c
+++ b/scalar.c
@@ -594,7 +594,9 @@ static int cmd_register(int argc, const char **argv)
return register_dir();
}
-static int get_scalar_repos(const char *key, const char *value, void *data)
+static int get_scalar_repos(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct string_list *list = data;
diff --git a/sequencer.c b/sequencer.c
index bceb6abcb6c..34754d17596 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -219,7 +219,8 @@ static struct update_ref_record *init_update_ref_record(const char *ref)
return rec;
}
-static int git_sequencer_config(const char *k, const char *v, void *cb)
+static int git_sequencer_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct replay_opts *opts = cb;
int status;
@@ -274,7 +275,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference"))
opts->commit_use_reference = git_config_bool(k, v);
- return git_diff_basic_config(k, v, NULL);
+ return git_diff_basic_config(k, v, ctx, NULL);
}
void sequencer_init_config(struct replay_opts *opts)
@@ -2881,7 +2882,9 @@ static int git_config_string_dup(char **dest,
return 0;
}
-static int populate_opts_cb(const char *key, const char *value, void *data)
+static int populate_opts_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct replay_opts *opts = data;
int error_flag = 1;
diff --git a/setup.c b/setup.c
index 6f6e92b96be..fadba5bab4b 100644
--- a/setup.c
+++ b/setup.c
@@ -517,7 +517,9 @@ no_prevention_needed:
startup_info->original_cwd = NULL;
}
-static int read_worktree_config(const char *var, const char *value, void *vdata)
+static int read_worktree_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct repository_format *data = vdata;
@@ -588,7 +590,8 @@ static enum extension_result handle_extension(const char *var,
return EXTENSION_UNKNOWN;
}
-static int check_repo_format(const char *var, const char *value, void *vdata)
+static int check_repo_format(const char *var, const char *value,
+ const struct config_context *ctx, void *vdata)
{
struct repository_format *data = vdata;
const char *ext;
@@ -617,7 +620,7 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
}
}
- return read_worktree_config(var, value, vdata);
+ return read_worktree_config(var, value, ctx, vdata);
}
static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
@@ -1115,7 +1118,8 @@ struct safe_directory_data {
int is_safe;
};
-static int safe_directory_cb(const char *key, const char *value, void *d)
+static int safe_directory_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
struct safe_directory_data *data = d;
@@ -1171,7 +1175,9 @@ static int ensure_valid_ownership(const char *gitfile,
return data.is_safe;
}
-static int allowed_bare_repo_cb(const char *key, const char *value, void *d)
+static int allowed_bare_repo_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *d)
{
enum allowed_bare_repo *allowed_bare_repo = d;
diff --git a/submodule-config.c b/submodule-config.c
index 7eb7a0d88d2..a38d4d49731 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -426,7 +426,8 @@ struct parse_config_parameter {
* config store (.git/config, etc). Callers are responsible for
* checking for overrides in the main config store when appropriate.
*/
-static int parse_config(const char *var, const char *value, void *data)
+static int parse_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct parse_config_parameter *me = data;
struct submodule *submodule;
@@ -674,7 +675,8 @@ out:
}
}
-static int gitmodules_cb(const char *var, const char *value, void *data)
+static int gitmodules_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
struct repository *repo = data;
struct parse_config_parameter parameter;
@@ -684,7 +686,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
parameter.gitmodules_oid = null_oid();
parameter.overwrite = 1;
- return parse_config(var, value, ¶meter);
+ return parse_config(var, value, ctx, ¶meter);
}
void repo_read_gitmodules(struct repository *repo, int skip_if_read)
@@ -801,7 +803,9 @@ void submodule_free(struct repository *r)
submodule_cache_clear(r->submodule_cache);
}
-static int config_print_callback(const char *var, const char *value, void *cb_data)
+static int config_print_callback(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
char *wanted_key = cb_data;
@@ -843,7 +847,9 @@ struct fetch_config {
int *recurse_submodules;
};
-static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
+static int gitmodules_fetch_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct fetch_config *config = cb;
if (!strcmp(var, "submodule.fetchjobs")) {
@@ -871,6 +877,7 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
}
static int gitmodules_update_clone_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb)
{
int *max_jobs = cb;
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index ad78fc17683..85ad815358e 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -42,7 +42,9 @@
*
*/
-static int iterate_cb(const char *var, const char *value, void *data UNUSED)
+static int iterate_cb(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data UNUSED)
{
static int nr;
@@ -59,7 +61,8 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED)
return 0;
}
-static int parse_int_cb(const char *var, const char *value, void *data)
+static int parse_int_cb(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
const char *key_to_match = data;
@@ -70,7 +73,9 @@ static int parse_int_cb(const char *var, const char *value, void *data)
return 0;
}
-static int early_config_cb(const char *var, const char *value, void *vdata)
+static int early_config_cb(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
const char *key = vdata;
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 680124a6760..0ce31ce59f5 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -12,7 +12,9 @@ static int driver_cb(struct userdiff_driver *driver,
return 0;
}
-static int cmd__userdiff_config(const char *var, const char *value, void *cb UNUSED)
+static int cmd__userdiff_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
if (userdiff_config(var, value) < 0)
return -1;
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 78cfc15d52d..83bc4fd109c 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -99,7 +99,8 @@ struct tr2_cfg_data {
/*
* See if the given config key matches any of our patterns of interest.
*/
-static int tr2_cfg_cb(const char *key, const char *value, void *d)
+static int tr2_cfg_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
struct strbuf **s;
struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
@@ -142,8 +143,12 @@ void tr2_list_env_vars_fl(const char *file, int line)
void tr2_cfg_set_fl(const char *file, int line, const char *key,
const char *value)
{
+ struct key_value_info kvi = KVI_INIT;
+ struct config_context ctx = {
+ .kvi = &kvi,
+ };
struct tr2_cfg_data data = { file, line };
if (tr2_cfg_load_patterns() > 0)
- tr2_cfg_cb(key, value, &data);
+ tr2_cfg_cb(key, value, &ctx, &data);
}
diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c
index 069786cb927..f26ec95ab4d 100644
--- a/trace2/tr2_sysenv.c
+++ b/trace2/tr2_sysenv.c
@@ -57,7 +57,8 @@ static struct tr2_sysenv_entry tr2_sysenv_settings[] = {
};
/* clang-format on */
-static int tr2_sysenv_cb(const char *key, const char *value, void *d)
+static int tr2_sysenv_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
int k;
diff --git a/trailer.c b/trailer.c
index a2c3ed6f28c..06dc0b7f683 100644
--- a/trailer.c
+++ b/trailer.c
@@ -482,6 +482,7 @@ static struct {
};
static int git_trailer_default_config(const char *conf_key, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
const char *trailer_item, *variable_name;
@@ -514,6 +515,7 @@ static int git_trailer_default_config(const char *conf_key, const char *value,
}
static int git_trailer_config(const char *conf_key, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
const char *trailer_item, *variable_name;
diff --git a/upload-pack.c b/upload-pack.c
index d3312006a32..951fd1f9c25 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1309,7 +1309,9 @@ static int parse_object_filter_config(const char *var, const char *value,
return 0;
}
-static int upload_pack_config(const char *var, const char *value, void *cb_data)
+static int upload_pack_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
struct upload_pack_data *data = cb_data;
@@ -1350,7 +1352,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
}
-static int upload_pack_protected_config(const char *var, const char *value, void *cb_data)
+static int upload_pack_protected_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
struct upload_pack_data *data = cb_data;
diff --git a/urlmatch.c b/urlmatch.c
index eba0bdd77fe..1c45f23adf2 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -551,7 +551,8 @@ static int cmp_matches(const struct urlmatch_item *a,
return 0;
}
-int urlmatch_config_entry(const char *var, const char *value, void *cb)
+int urlmatch_config_entry(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct string_list_item *item;
struct urlmatch_config *collect = cb;
@@ -565,7 +566,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') {
if (collect->cascade_fn)
- return collect->cascade_fn(var, value, cb);
+ return collect->cascade_fn(var, value, ctx, cb);
return 0; /* not interested */
}
dot = strrchr(key, '.');
@@ -609,7 +610,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
strbuf_addstr(&synthkey, collect->section);
strbuf_addch(&synthkey, '.');
strbuf_addstr(&synthkey, key);
- retval = collect->collect_fn(synthkey.buf, value, collect->cb);
+ retval = collect->collect_fn(synthkey.buf, value, ctx, collect->cb);
strbuf_release(&synthkey);
return retval;
diff --git a/urlmatch.h b/urlmatch.h
index bee374a642c..5ba85cea139 100644
--- a/urlmatch.h
+++ b/urlmatch.h
@@ -71,7 +71,8 @@ struct urlmatch_config {
.vars = STRING_LIST_INIT_DUP, \
}
-int urlmatch_config_entry(const char *var, const char *value, void *cb);
+int urlmatch_config_entry(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
void urlmatch_config_release(struct urlmatch_config *config);
#endif /* URL_MATCH_H */
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0460e03f5ed..dcbb5e09857 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -307,7 +307,8 @@ int xdiff_compare_lines(const char *l1, long s1,
int git_xmerge_style = -1;
-int git_xmerge_config(const char *var, const char *value, void *cb)
+int git_xmerge_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "merge.conflictstyle")) {
if (!value)
@@ -327,5 +328,5 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
value, var);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 733c364d26c..e6f80df0462 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -50,7 +50,9 @@ int buffer_is_binary(const char *ptr, unsigned long size);
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
void xdiff_clear_find_func(xdemitconf_t *xecfg);
-int git_xmerge_config(const char *var, const char *value, void *cb);
+struct config_context;
+int git_xmerge_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
extern int git_xmerge_style;
/*
--
gitgitgadget
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox