git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Rubén Justo" <rjusto@gmail.com>
To: Git List <git@vger.kernel.org>
Subject: [PATCH 2/4] config.c: introduce git_config_strbuf_pathname
Date: Sat, 6 Apr 2024 16:32:17 +0200	[thread overview]
Message-ID: <f58d8114-f6fe-4b4e-85be-3b57609a3687@gmail.com> (raw)
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


  parent reply	other threads:[~2024-04-06 14:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-06 14:29 [PATCH 0/4] fix a leak with excludes_file Rubén Justo
2024-04-06 14:31 ` [PATCH 1/4] path.c: introduce strbuf_interpolate_path Rubén Justo
2024-04-06 14:32 ` Rubén Justo [this message]
2024-04-06 14:32 ` [PATCH 3/4] environment.c: convert excludes_file to struct strbuf Rubén Justo
2024-04-06 14:32 ` [PATCH 4/4] t7300: mark as leak-free Rubén Justo
2024-04-06 17:53 ` [PATCH 0/4] fix a leak with excludes_file Junio C Hamano
2024-04-07 17:48   ` Rubén Justo
2024-04-08 17:36     ` Junio C Hamano
2024-04-08 19:33       ` Rubén Justo

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f58d8114-f6fe-4b4e-85be-3b57609a3687@gmail.com \
    --to=rjusto@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).