git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] [Outreachy] gpg-interface: use string_list_split instead of strbuf_split

From
Olamide Caleb Bello <belkid98@gmail.com>
Date
Oct 15, 2025, 02:19 UTC
Message-ID
<d1c20c911637870c3cacfedf763ce508a641710f.1760490943.git.belkid98@gmail.com>
In-Reply-To
<cover.1760490943.git.belkid98@gmail.com>

get_default_ssh_signing_key() gets the signing key via the pipe_command and stores the output in key_stdout. The output string is then split using strbuf_split_max into two tokens at a new line and the first token is returned. This makes the function lack the use of strbuf API as no edits was performed on the split tokens.

Replace strbuf_split_max with string_list_split for simplicity.
Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
---
 gpg-interface.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index 043a808577..7a78cbd8b2 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -862,7 +862,7 @@ static char *get_default_ssh_signing_key(void)
 	struct child_process ssh_default_key = CHILD_PROCESS_INIT;
 	int ret = -1;
 	struct strbuf key_stdout = STRBUF_INIT, key_stderr = STRBUF_INIT;
-	struct strbuf **keys;
+	struct string_list keys = STRING_LIST_INIT_DUP;
 	char *key_command = NULL;
 	const char **argv;
 	int n;
@@ -884,19 +884,15 @@ static char *get_default_ssh_signing_key(void)
 			   &key_stderr, 0);
 
 	if (!ret) {
-		keys = strbuf_split_max(&key_stdout, '\n', 2);
-		if (keys[0] && is_literal_ssh_key(keys[0]->buf, &literal_key)) {
-			/*
-			 * We only use `is_literal_ssh_key` here to check validity
-			 * The prefix will be stripped when the key is used.
-			 */
-			default_key = strbuf_detach(keys[0], NULL);
+		if (string_list_split(&keys, key_stdout.buf, "\n", 1) > 0 &&
+			is_literal_ssh_key(keys.items[0].string, &literal_key)) {
+				default_key = xstrdup(keys.items[0].string);
 		} else {
 			warning(_("gpg.ssh.defaultKeyCommand succeeded but returned no keys: %s %s"),
 				key_stderr.buf, key_stdout.buf);
 		}
 
-		strbuf_list_free(keys);
+		string_list_clear(&keys, 0);
 	} else {
 		warning(_("gpg.ssh.defaultKeyCommand failed: %s %s"),
 			key_stderr.buf, key_stdout.buf);
-- 
2.51.0.463.g79cf913ea9
Previous: Bello OlamideNext: Christian Couder
Message 5 of 9 in “[Outreachy] gpg-interface.c: use string_list_split instead of strbuf_split_max”
  1. 0/2 [Outreachy] gpg-interface.c: use string_list_split instead of strbuf_split_maxOlamide Caleb Bello, Oct 15, 2025
  2. 1/2 [Outreachy] gpg-interface: replace strbuf_split with string_list_splitOlamide Caleb Bello, Oct 15, 2025
  3. Christian CouderOct 15, 2025
  4. Bello OlamideOct 15, 2025
  5. 2/2 [Outreachy] gpg-interface: use string_list_split instead of strbuf_splitOlamide Caleb Bello, Oct 15, 2025
  6. Christian CouderOct 15, 2025
  7. Bello OlamideOct 15, 2025
  8. Christian CouderOct 15, 2025
  9. Bello OlamideOct 15, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.