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

[Outreachy PATCH v3 1/2] gpg-interface: replace strbuf_split*() with string_list_split*()

From
Olamide Caleb Bello <belkid98@gmail.com>
Date
Oct 19, 2025, 12:07 UTC
Message-ID
<7da4fded535984faea52d5f88793d3c8e47c0091.1760869186.git.belkid98@gmail.com>
In-Reply-To
<cover.1760869186.git.belkid98@gmail.com>

In get_ssh_finger_print(), the output of the `ssh-keygen` command is put into `fingerprint_stdout

The string in fingerprint_stdout is then split into 3 strbufs using strbuf_split_max(), however they are not modified after the split thereby not making use of the strbuf API as the fingerprint token is merely returned as a char * and not a strbuf, hence they do not need to be strbufs.

Use string_list_split_in_place() instead for simplicity.

Note that strbuf_split_max() uses 3 to specify the number of tokens to extract from the string, while string_list_split_in_place() uses 2 because it specifies the number of times the split will be done on the string, so 2 gives 3 tokens as it is in the original instance.

string_list_split_in_place() returns the number of substrings added to the `split.items` so for a successful split of the string in fingerprint_stdout, at least two items should be added to split.items so we can always be certain that the substring at index 1 is the ssh fingerprint even if the key owner's identity part is missing from the string in fingerprint_stdout.

Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
Reported-by: Junio Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Helped-by: Junio Hamano <gitster@pobox.com>
---
 gpg-interface.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index 2f4f0e32cb..cb182f4c11 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -14,6 +14,7 @@
 #include "sigchain.h"
 #include "tempfile.h"
 #include "alias.h"
+#include "string-list.h"
 
 static int git_gpg_config(const char *, const char *,
 			  const struct config_context *, void *);
@@ -821,7 +822,7 @@ static char *get_ssh_key_fingerprint(const char *signing_key)
 	struct child_process ssh_keygen = CHILD_PROCESS_INIT;
 	int ret = -1;
 	struct strbuf fingerprint_stdout = STRBUF_INIT;
-	struct strbuf **fingerprint;
+	struct string_list split = STRING_LIST_INIT_NODUP;
 	char *fingerprint_ret;
 	const char *literal_key = NULL;
 
@@ -845,13 +846,12 @@ static char *get_ssh_key_fingerprint(const char *signing_key)
 		die_errno(_("failed to get the ssh fingerprint for key '%s'"),
 			  signing_key);
 
-	fingerprint = strbuf_split_max(&fingerprint_stdout, ' ', 3);
-	if (!fingerprint[1])
+	if (string_list_split_in_place(&split, fingerprint_stdout.buf, " ", 2) <= 1)
 		die_errno(_("failed to get the ssh fingerprint for key '%s'"),
 			  signing_key);
 
-	fingerprint_ret = strbuf_detach(fingerprint[1], NULL);
-	strbuf_list_free(fingerprint);
+	fingerprint_ret = xstrdup(split.items[1].string);
+	string_list_clear(&split, 0);
 	strbuf_release(&fingerprint_stdout);
 	return fingerprint_ret;
 }
-- 
2.51.0.463.g79cf913ea9
Previous: Olamide Caleb BelloNext: Junio C Hamano
Message 2 of 17 in “gpg-interface.c: use string_list_split*() instead of strbuf_split*()”
  1. 0/2 gpg-interface.c: use string_list_split*() instead of strbuf_split*()Olamide Caleb Bello, Oct 19, 2025
  2. 1/2 gpg-interface: replace strbuf_split*() with string_list_split*()Olamide Caleb Bello, Oct 19, 2025
  3. Junio C HamanoOct 19, 2025
  4. Bello OlamideOct 20, 2025
  5. Junio C HamanoOct 20, 2025
  6. Junio C HamanoOct 20, 2025
  7. Bello OlamideOct 20, 2025
  8. Bello OlamideOct 20, 2025
  9. Kristoffer HaugsbakkOct 20, 2025
  10. Bello OlamideOct 20, 2025
  11. Kristoffer HaugsbakkOct 20, 2025
  12. Bello OlamideOct 20, 2025
  13. 2/2 gpg-interface: use string_list_split*() instead of strbuf_split*()Olamide Caleb Bello, Oct 19, 2025
  14. Junio C HamanoOct 19, 2025
  15. Bello OlamideOct 20, 2025
  16. Junio C HamanoOct 20, 2025
  17. Bello OlamideOct 20, 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.