-
Notifications
You must be signed in to change notification settings - Fork 178
[RFC] config-batch: a new builtin for tools querying config #2033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
c4dab06
ecd26a0
3de1bba
d5e0c32
33faa3f
014e959
4be089a
60443c5
fdeef53
cf4f054
59d19fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| /git-commit-graph | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Kristoffer Haugsbakk" wrote on the Git mailing list (how to reply to this email): On Wed, Feb 4, 2026, at 15:19, Derrick Stolee via GitGitGadget wrote:
>[snip]
> +git-config-batch(1)
> +===================
> +
> +NAME
> +----
> +git-config-batch - Get and set options using machine-parseable
> interface
> +
> +
> +SYNOPSIS
> +--------
> +[verse]
There’s work lead by Jean-Noël Avila to use `[synopsis]` instead of
`[verse]`.[1] Would it make sense to start off with that?
† 1: E.g. acffc5e9 (doc: convert git-remote to synopsis style, 2025-12-20)
> +'git config-batch' <options>
> +
> +DESCRIPTION
> +-----------
>[snip]There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jean-Noël Avila wrote on the Git mailing list (how to reply to this email): Le 04/02/2026 à 15:19, Derrick Stolee via GitGitGadget a écrit :
> From: Derrick Stolee <stolee@gmail.com>
>
> Later changes will document, implement, and test this new builtin. For now,
> this serves as the latest example of the minimum boilerplate to introduce a
> new builtin.
>
> Recently, we updated the comment in builtin.h about how to create a new
> builtin, but failed to mention the required change to meson.build files for
> some CI builds to pass. Fix that oversight.
>
> Signed-off-by: Derrick Stolee <stolee@gmail.com>
> ---
> .gitignore | 1 +
> Documentation/git-config-batch.adoc | 24 +++++++++++++++++++++++
> Documentation/meson.build | 1 +
> Makefile | 1 +
> builtin.h | 7 +++++++
> builtin/config-batch.c | 30 +++++++++++++++++++++++++++++
> command-list.txt | 1 +
> git.c | 1 +
> meson.build | 1 +
> t/meson.build | 1 +
> t/t1312-config-batch.sh | 12 ++++++++++++
> 11 files changed, 80 insertions(+)
> create mode 100644 Documentation/git-config-batch.adoc
> create mode 100644 builtin/config-batch.c
> create mode 100755 t/t1312-config-batch.sh
>
> diff --git a/.gitignore b/.gitignore
> index 78a45cb5be..42640b5e24 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -44,6 +44,7 @@
> /git-commit-graph
> /git-commit-tree
> /git-config
> +/git-config-batch
> /git-count-objects
> /git-credential
> /git-credential-cache
> diff --git a/Documentation/git-config-batch.adoc b/Documentation/git-config-batch.adoc
> new file mode 100644
> index 0000000000..dfa0bd83e2
> --- /dev/null
> +++ b/Documentation/git-config-batch.adoc
> @@ -0,0 +1,24 @@
> +git-config-batch(1)
> +===================
> +
> +NAME
> +----
> +git-config-batch - Get and set options using machine-parseable interface
> +
> +
> +SYNOPSIS
> +--------
> +[verse]
> +'git config-batch' <options>
For this new manual page, please use the synopsis style:
[synopsis]
git config-batch <options>
Thanks |
||
| /git-commit-tree | ||
| /git-config | ||
| /git-config-batch | ||
| /git-count-objects | ||
| /git-credential | ||
| /git-credential-cache | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| git-config-batch(1) | ||
| =================== | ||
|
|
||
| NAME | ||
| ---- | ||
| git-config-batch - Get and set options using machine-parseable interface | ||
|
|
||
|
|
||
| SYNOPSIS | ||
| -------- | ||
| [verse] | ||
| 'git config-batch' <options> | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Junio C Hamano wrote on the Git mailing list (how to reply to this email): "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +static struct command commands[] = {
> + /* unknown_command must be last. */
> + {
> + .name = "",
> + .fn = unknown_command,
> + },
> +};
A useful trick is to deliberately omit the trailing comma after the
element that MUST be last. You did that for the __NR enum element
in a later step.
> +#define COMMAND_COUNT ((size_t)(sizeof(commands) / sizeof(*commands)))
Isn't this ARRAY_SIZE(commands)?
> + while (!(res = process_command(repo)));
Please write an empty statement on its own line, i.e.
while (!(res = process_command(repo)))
;
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Kristoffer Haugsbakk" wrote on the Git mailing list (how to reply to this email): On Wed, Feb 4, 2026, at 15:19, Derrick Stolee via GitGitGadget wrote:
>[snip]
> DESCRIPTION
> -----------
> -TODO
> +Tools frequently need to change their behavior based on values stored in
> +Git's configuration files. These files may have complicated conditions
> +for including extra files, so it is difficult to produce an independent
> +parser. To avoid executing multiple processes to discover or modify
> +multiple configuration values, the `git config-batch` command allows a
> +single process to handle multiple requests using a machine-parseable
> +interface across `stdin` and `stdout`.
I really like that the doc itself motivates the command. Many man pages
on git(1) just tells you what it does as if you would already know why
you need it.
> +
>[snip]There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jean-Noël Avila wrote on the Git mailing list (how to reply to this email): Le 04/02/2026 à 15:19, Derrick Stolee via GitGitGadget a écrit :
> From: Derrick Stolee <stolee@gmail.com>
>
> As we build new features in the config-batch command, we define the
> plaintext protocol with line-by-line output and responses. To think to the
> future, we make sure that the protocol has a clear way to respond to an
> unknown command or an unknown version of that command.
>
> As some commands will allow the final argument to contain spaces or even be
> able to parse "\ " as a non-split token, we only provide the remaining line
> as data.
>
> Signed-off-by: Derrick Stolee <stolee@gmail.com>
> ---
> Documentation/git-config-batch.adoc | 23 ++++-
> builtin/config-batch.c | 133 +++++++++++++++++++++++++++-
> t/t1312-config-batch.sh | 19 +++-
> 3 files changed, 170 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/git-config-batch.adoc b/Documentation/git-config-batch.adoc
> index dfa0bd83e2..9ca04b0c1e 100644
> --- a/Documentation/git-config-batch.adoc
> +++ b/Documentation/git-config-batch.adoc
> @@ -13,7 +13,28 @@ SYNOPSIS
>
> DESCRIPTION
> -----------
> -TODO
> +Tools frequently need to change their behavior based on values stored in
> +Git's configuration files. These files may have complicated conditions
> +for including extra files, so it is difficult to produce an independent
> +parser. To avoid executing multiple processes to discover or modify
> +multiple configuration values, the `git config-batch` command allows a
> +single process to handle multiple requests using a machine-parseable
> +interface across `stdin` and `stdout`.
> +
> +PROTOCOL
> +--------
> +By default, the protocol uses line feeds (`LF`) to signal the end of a
Characters are typefaced as placeholders: _LF_
> +command over `stdin` or a response over `stdout`.
> +
> +The protocol will be extended in the future, and consumers should be
> +resilient to older Git versions not understanding the latest command
> +set. Thus, if the Git version includes the `git config-batch` builtin
> +but doesn't understand an input command, it will return a single line
> +response:
> +
> +```
> +unknown_command LF> +```
>
This is Markdown. For Asciidoc, use code block:
----
unknown_command LF
----
|
||
| DESCRIPTION | ||
| ----------- | ||
| TODO | ||
|
|
||
| SEE ALSO | ||
| -------- | ||
| linkgit:git-config[1] | ||
|
|
||
| GIT | ||
| --- | ||
| Part of the linkgit:git[1] suite | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #define USE_THE_REPOSITORY_VARIABLE | ||
| #include "builtin.h" | ||
| #include "config.h" | ||
| #include "environment.h" | ||
| #include "parse-options.h" | ||
|
|
||
| static const char *const builtin_config_batch_usage[] = { | ||
| N_("git config-batch <options>"), | ||
| NULL | ||
| }; | ||
|
|
||
| int cmd_config_batch(int argc, | ||
| const char **argv, | ||
| const char *prefix, | ||
| struct repository *repo) | ||
| { | ||
| struct option options[] = { | ||
| OPT_END(), | ||
| }; | ||
|
|
||
| show_usage_with_options_if_asked(argc, argv, | ||
| builtin_config_batch_usage, options); | ||
|
|
||
| argc = parse_options(argc, argv, prefix, options, builtin_config_batch_usage, | ||
| 0); | ||
|
|
||
| repo_config(repo, git_default_config, NULL); | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/sh | ||
|
|
||
| test_description='Test git config-batch' | ||
|
|
||
| . ./test-lib.sh | ||
|
|
||
| test_expect_success 'help text' ' | ||
| test_must_fail git config-batch -h >out && | ||
| grep usage out | ||
| ' | ||
|
|
||
| test_done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derrick Stolee wrote on the Git mailing list (how to reply to this email):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Kristoffer Haugsbakk" wrote on the Git mailing list (how to reply to this email):