From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: gitster@pobox•com, Derrick Stolee <stolee@gmail•com>,
Derrick Stolee <stolee@gmail•com>
Subject: [PATCH 04/11] config-batch: create 'help' command
Date: Wed, 04 Feb 2026 14:19:56 +0000 [thread overview]
Message-ID: <d5e0c32497581e6ac4890c6e71c5c33b92d67d51.1770214803.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2033.git.1770214803.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail•com>
Tools that use the 'git config-batch' tool will want to know which commands
are available in the current Git version. Having a 'help' command assists
greatly to give a clear set of available commands and their versions.
Signed-off-by: Derrick Stolee <stolee@gmail•com>
---
Documentation/git-config-batch.adoc | 17 +++++++++++++++
builtin/config-batch.c | 32 +++++++++++++++++++++++++++++
t/t1312-config-batch.sh | 13 ++++++++++++
3 files changed, 62 insertions(+)
diff --git a/Documentation/git-config-batch.adoc b/Documentation/git-config-batch.adoc
index 31dd42f481..1fff68a13c 100644
--- a/Documentation/git-config-batch.adoc
+++ b/Documentation/git-config-batch.adoc
@@ -38,6 +38,23 @@ unknown_command LF
These are the commands that are currently understood:
+`help` version 1::
+ The `help` command lists the currently-available commands in
+ this version of Git. The output is multi-line, but the first
+ line provides the count of possible commands via `help count <N>`.
+ The next `<N>` lines are of the form `help <command> <version>`
+ to state that this Git version supports that `<command>` at
+ version `<version>`. Note that the same command may have multiple
+ available versions.
++
+Here is the currentl output of the help text at the latest version:
++
+------------
+help 1 count 2
+help 1 help 1
+help 1 get 1
+------------
+
`get` version 1::
The `get` command searches the config key-value pairs within a
given `<scope>` for values that match the fixed `<key>` and
diff --git a/builtin/config-batch.c b/builtin/config-batch.c
index 5782004080..1c19e4889f 100644
--- a/builtin/config-batch.c
+++ b/builtin/config-batch.c
@@ -12,6 +12,7 @@ static const char *const builtin_config_batch_usage[] = {
};
#define UNKNOWN_COMMAND "unknown_command"
+#define HELP_COMMAND "help"
#define GET_COMMAND "get"
#define COMMAND_PARSE_ERROR "command_parse_error"
@@ -104,6 +105,9 @@ static size_t parse_token(char **data, size_t *data_len,
return parse_whitespace_token(data, data_len, token, err);
}
+static int help_command_1(struct repository *repo,
+ char *data, size_t data_len);
+
enum value_match_mode {
MATCH_ALL,
MATCH_EXACT,
@@ -302,6 +306,11 @@ struct command {
};
static struct command commands[] = {
+ {
+ .name = HELP_COMMAND,
+ .fn = help_command_1,
+ .version = 1,
+ },
{
.name = GET_COMMAND,
.fn = get_command_1,
@@ -316,6 +325,29 @@ static struct command commands[] = {
#define COMMAND_COUNT ((size_t)(sizeof(commands) / sizeof(*commands)))
+static int help_command_1(struct repository *repo UNUSED,
+ char *data UNUSED, size_t data_len UNUSED)
+{
+ struct strbuf fmt_str = STRBUF_INIT;
+
+ strbuf_addf(&fmt_str, "%"PRIu32, (uint32_t)(COMMAND_COUNT - 1));
+ emit_response(HELP_COMMAND, "1", "count", fmt_str.buf, NULL);
+ strbuf_reset(&fmt_str);
+
+ for (size_t i = 0; i < COMMAND_COUNT; i++) {
+ /* Halt at unknown command. */
+ if (!commands[i].name[0])
+ break;
+
+ strbuf_addf(&fmt_str, "%d", commands[i].version);
+ emit_response(HELP_COMMAND, "1", commands[i].name, fmt_str.buf, NULL);
+ strbuf_reset(&fmt_str);
+ }
+
+ strbuf_release(&fmt_str);
+ return 0;
+}
+
/**
* Process a single line from stdin and process the command.
*
diff --git a/t/t1312-config-batch.sh b/t/t1312-config-batch.sh
index e638b54d13..6b550a0e76 100755
--- a/t/t1312-config-batch.sh
+++ b/t/t1312-config-batch.sh
@@ -23,6 +23,19 @@ test_expect_success 'completely broken input' '
test_grep "an unrecoverable error occurred during command execution" err
'
+test_expect_success 'help command' '
+ echo "help 1" >in &&
+
+ cat >expect <<-\EOF &&
+ help 1 count 2
+ help 1 help 1
+ help 1 get 1
+ EOF
+
+ git config-batch >out <in &&
+ test_cmp expect out
+'
+
test_expect_success 'failed to parse version' '
echo "bogus BAD_VERSION line of tokens" >in &&
test_must_fail git config-batch 2>err <in &&
--
gitgitgadget
next prev parent reply other threads:[~2026-02-04 14:20 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 14:19 [PATCH 00/11] [RFC] config-batch: a new builtin for tools querying config Derrick Stolee via GitGitGadget
2026-02-04 14:19 ` [PATCH 01/11] config-batch: basic boilerplate of new builtin Derrick Stolee via GitGitGadget
2026-02-04 23:23 ` Junio C Hamano
2026-02-05 14:17 ` Derrick Stolee
2026-02-05 17:26 ` Kristoffer Haugsbakk
2026-02-05 17:29 ` Kristoffer Haugsbakk
2026-02-06 4:11 ` Jean-Noël Avila
2026-02-04 14:19 ` [PATCH 02/11] config-batch: create parse loop and unknown command Derrick Stolee via GitGitGadget
2026-02-04 23:26 ` Junio C Hamano
2026-02-05 17:30 ` Kristoffer Haugsbakk
2026-02-06 4:15 ` Jean-Noël Avila
2026-02-04 14:19 ` [PATCH 03/11] config-batch: implement get v1 Derrick Stolee via GitGitGadget
2026-02-06 4:41 ` Jean-Noël Avila
2026-02-04 14:19 ` Derrick Stolee via GitGitGadget [this message]
2026-02-06 4:49 ` [PATCH 04/11] config-batch: create 'help' command Jean-Noël Avila
2026-02-10 4:20 ` Derrick Stolee
2026-02-04 14:19 ` [PATCH 05/11] config-batch: add NUL-terminated I/O format Derrick Stolee via GitGitGadget
2026-02-05 17:44 ` Kristoffer Haugsbakk
2026-02-06 4:58 ` Jean-Noël Avila
2026-02-04 14:19 ` [PATCH 06/11] docs: add design doc for config-batch Derrick Stolee via GitGitGadget
2026-02-05 17:38 ` Kristoffer Haugsbakk
2026-02-10 4:22 ` Derrick Stolee
2026-02-04 14:19 ` [PATCH 07/11] config: extract location structs from builtin Derrick Stolee via GitGitGadget
2026-02-04 14:20 ` [PATCH 08/11] config-batch: pass prefix through commands Derrick Stolee via GitGitGadget
2026-02-04 14:20 ` [PATCH 09/11] config-batch: add 'set' v1 command Derrick Stolee via GitGitGadget
2026-02-05 17:21 ` Kristoffer Haugsbakk
2026-02-05 18:58 ` Kristoffer Haugsbakk
2026-02-05 19:01 ` Kristoffer Haugsbakk
2026-02-10 4:25 ` Derrick Stolee
2026-02-06 5:04 ` Jean-Noël Avila
2026-02-04 14:20 ` [PATCH 10/11] t1312: create read/write test Derrick Stolee via GitGitGadget
2026-02-04 14:20 ` [PATCH 11/11] config-batch: add unset v1 command Derrick Stolee via GitGitGadget
2026-02-05 17:36 ` Kristoffer Haugsbakk
2026-02-04 23:04 ` [PATCH 00/11] [RFC] config-batch: a new builtin for tools querying config Junio C Hamano
2026-02-05 14:10 ` Derrick Stolee
2026-02-05 0:04 ` brian m. carlson
2026-02-05 13:52 ` Derrick Stolee
2026-02-10 4:49 ` Derrick Stolee
2026-02-05 14:45 ` Phillip Wood
2026-02-05 17:20 ` Kristoffer Haugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d5e0c32497581e6ac4890c6e71c5c33b92d67d51.1770214803.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=stolee@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox