public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
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 08/11] config-batch: pass prefix through commands
Date: Wed, 04 Feb 2026 14:20:00 +0000	[thread overview]
Message-ID: <60443c56f456ca794e299ae8d8bbea23793780b5.1770214803.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2033.git.1770214803.gitgitgadget@gmail.com>

From: Derrick Stolee <stolee@gmail.com>

The 'help' and 'get' commands of 'git config-batch' have not needed the
prefix parameter from the builtin entrance point, but an upcoming
command will need it in order to identify the location of the
appropriate config file. Pass it through the appropriate functions and
function pointers.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
---
 builtin/config-batch.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/builtin/config-batch.c b/builtin/config-batch.c
index 2c48c4ea37..9829b16c6f 100644
--- a/builtin/config-batch.c
+++ b/builtin/config-batch.c
@@ -67,9 +67,11 @@ static int command_parse_error(const char *command)
  * Return 0 on success.
  */
 typedef int (*command_fn)(struct repository *repo,
+			  const char *prefix,
 			  char *data, size_t data_len);
 
 static int unknown_command(struct repository *repo UNUSED,
+			   const char *prefix UNUSED,
 			   char *data UNUSED, size_t data_len UNUSED)
 {
 	return emit_response(UNKNOWN_COMMAND, NULL);
@@ -176,6 +178,7 @@ static size_t parse_token(char **data, size_t *data_len,
 }
 
 static int help_command_1(struct repository *repo,
+			  const char *prefix UNUSED,
 			  char *data, size_t data_len);
 
 enum value_match_mode {
@@ -292,6 +295,7 @@ static int parse_scope(const char *str, enum config_scope *scope)
  * [N*] indicates optional parameters that are not needed.
  */
 static int get_command_1(struct repository *repo,
+			 const char *prefix UNUSED,
 			 char *data,
 			 size_t data_len)
 {
@@ -402,6 +406,7 @@ static struct command commands[] = {
 #define COMMAND_COUNT ((size_t)(sizeof(commands) / sizeof(*commands)))
 
 static int help_command_1(struct repository *repo UNUSED,
+			  const char *prefix UNUSED,
 			  char *data UNUSED, size_t data_len UNUSED)
 {
 	struct strbuf fmt_str = STRBUF_INIT;
@@ -424,7 +429,8 @@ static int help_command_1(struct repository *repo UNUSED,
 	return 0;
 }
 
-static int process_command_nul(struct repository *repo)
+static int process_command_nul(struct repository *repo,
+			       const char *prefix)
 {
 	static struct strbuf line = STRBUF_INIT;
 	char *data, *command, *versionstr;
@@ -476,7 +482,7 @@ static int process_command_nul(struct repository *repo)
 		if (!commands[i].name[0] ||
 		    (!strcmp(command, commands[i].name) &&
 		     commands[i].version == version)) {
-			res = commands[i].fn(repo, data, data_len);
+			res = commands[i].fn(repo, prefix, data, data_len);
 			goto cleanup;
 		}
 	}
@@ -484,14 +490,15 @@ static int process_command_nul(struct repository *repo)
 	BUG(_("scanned to end of command list, including 'unknown_command'"));
 
 parse_error:
-	res = unknown_command(repo, NULL, 0);
+	res = unknown_command(repo, prefix, NULL, 0);
 
 cleanup:
 	strbuf_release(&line);
 	return res;
 }
 
-static int process_command_whitespace(struct repository *repo)
+static int process_command_whitespace(struct repository *repo,
+				      const char *prefix)
 {
 	static struct strbuf line = STRBUF_INIT;
 	struct string_list tokens = STRING_LIST_INIT_NODUP;
@@ -536,7 +543,7 @@ static int process_command_whitespace(struct repository *repo)
 		if (!commands[i].name[0] ||
 		    (!strcmp(command, commands[i].name) &&
 		     commands[i].version == version)) {
-			res = commands[i].fn(repo, data, data_len);
+			res = commands[i].fn(repo, prefix, data, data_len);
 			goto cleanup;
 		}
 	}
@@ -559,11 +566,12 @@ cleanup:
  *
  * Returns negative value on other catastrophic error.
  */
-static int process_command(struct repository *repo)
+static int process_command(struct repository *repo,
+			   const char *prefix)
 {
 	if (zformat)
-		return process_command_nul(repo);
-	return process_command_whitespace(repo);
+		return process_command_nul(repo, prefix);
+	return process_command_whitespace(repo, prefix);
 }
 
 int cmd_config_batch(int argc,
@@ -586,7 +594,7 @@ int cmd_config_batch(int argc,
 
 	repo_config(repo, git_default_config, NULL);
 
-	while (!(res = process_command(repo)));
+	while (!(res = process_command(repo, prefix)));
 
 	if (res == 1)
 		return 0;
-- 
gitgitgadget


  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 ` [PATCH 04/11] config-batch: create 'help' command Derrick Stolee via GitGitGadget
2026-02-06  4:49   ` 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 ` Derrick Stolee via GitGitGadget [this message]
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=60443c56f456ca794e299ae8d8bbea23793780b5.1770214803.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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