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

[PATCH 2/4] config.c: introduce git_config_strbuf_pathname

From
Rubén Justo <rjusto@gmail.com>
Date
Apr 6, 2024, 14:32 UTC
Message-ID
<f58d8114-f6fe-4b4e-85be-3b57609a3687@gmail.com>
In-Reply-To
<f4af1e88-5bd9-4b3c-8691-84dbf0ca3ee2@gmail.com>

Add a new git_config_strbuf_pathname function, similar to git_config_pathname, that works with a strbuf relying on the recently introduced strbuf_interpolate_path.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 config.c | 10 ++++++++++
 config.h |  2 ++
 2 files changed, 12 insertions(+)
diff --git a/config.c b/config.c
index eebce8c7e0..9beeb63b50 100644
--- a/config.c
+++ b/config.c
@@ -1355,6 +1355,16 @@ int git_config_pathname(const char **dest, const char *var, const char *value)
 	return 0;
 }
 
+int git_config_strbuf_pathname(struct strbuf *dest, const char *var, const char *value)
+{
+	if (!value)
+		return config_error_nonbool(var);
+	strbuf_interpolate_path(value, 0, dest);
+	if (!dest->len)
+		die(_("failed to expand user dir in: '%s'"), value);
+	return 0;
+}
+
 int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *value)
 {
 	if (!value)
diff --git a/config.h b/config.h
index f4966e3749..e405f1c140 100644
--- a/config.h
+++ b/config.h
@@ -22,6 +22,7 @@
  */
 
 struct object_id;
+struct strbuf;
 
 /* git_config_parse_key() returns these negated: */
 #define CONFIG_INVALID_KEY 1
@@ -287,6 +288,7 @@ int git_config_string(const char **, const char *, const char *);
  * user's home directory when found at the beginning of the path.
  */
 int git_config_pathname(const char **, const char *, const char *);
+int git_config_strbuf_pathname(struct strbuf *, const char *, const char *);
 
 int git_config_expiry_date(timestamp_t *, const char *, const char *);
 int git_config_color(char *, const char *, const char *);
-- 
2.44.0.697.g9b33b46f29
Previous: Rubén JustoNext: Rubén Justo
Message 3 of 9 in “fix a leak with excludes_file”
  1. 0/4 fix a leak with excludes_fileRubén Justo, Apr 6, 2024
  2. 1/4 path.c: introduce strbuf_interpolate_pathRubén Justo, Apr 6, 2024
  3. 2/4 config.c: introduce git_config_strbuf_pathnameRubén Justo, Apr 6, 2024
  4. 3/4 environment.c: convert excludes_file to struct strbufRubén Justo, Apr 6, 2024
  5. 4/4 t7300: mark as leak-freeRubén Justo, Apr 6, 2024
  6. Junio C HamanoApr 6, 2024
  7. Rubén JustoApr 7, 2024
  8. Junio C HamanoApr 8, 2024
  9. Rubén JustoApr 8, 2024

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.