git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>, shejialuo <shejialuo@gmail.com>
Subject: [PATCH v2 08/16] path: drop `git_path_buf()` in favor of `repo_git_path_replace()`
Date: Fri, 07 Feb 2025 12:03:33 +0100	[thread overview]
Message-ID: <20250207-b4-pks-path-drop-the-repository-v2-8-13cad3c11b8a@pks.im> (raw)
In-Reply-To: <20250207-b4-pks-path-drop-the-repository-v2-0-13cad3c11b8a@pks.im>

Remove `git_path_buf()` in favor of `repo_git_path_replace()`. The
latter does essentially the same, with the only exception that it does
not rely on `the_repository` but takes the repo as separate parameter.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/worktree.c       |  2 +-
 compat/precompose_utf8.c |  6 +++---
 notes-merge.c            |  4 ++--
 object-file.c            |  4 ++--
 path.h                   | 16 ----------------
 setup.c                  | 33 ++++++++++++++++-----------------
 6 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index c84e6aa2cb..7959b10d26 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -457,7 +457,7 @@ static int add_worktree(const char *path, const char *refname,
 		BUG("How come '%s' becomes empty after sanitization?", sb.buf);
 	strbuf_reset(&sb);
 	name = sb_name.buf;
-	git_path_buf(&sb_repo, "worktrees/%s", name);
+	repo_git_path_replace(the_repository, &sb_repo, "worktrees/%s", name);
 	len = sb_repo.len;
 	if (safe_create_leading_directories_const(sb_repo.buf))
 		die_errno(_("could not create leading directories of '%s'"),
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index f7cc7b3be5..12e38e0ea3 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -50,15 +50,15 @@ void probe_utf8_pathname_composition(void)
 	int output_fd;
 	if (precomposed_unicode != -1)
 		return; /* We found it defined in the global config, respect it */
-	git_path_buf(&path, "%s", auml_nfc);
+	repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
 	output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
 	if (output_fd >= 0) {
 		close(output_fd);
-		git_path_buf(&path, "%s", auml_nfd);
+		repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
 		precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
 		git_config_set("core.precomposeunicode",
 			       precomposed_unicode ? "true" : "false");
-		git_path_buf(&path, "%s", auml_nfc);
+		repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
 		if (unlink(path.buf))
 			die_errno(_("failed to unlink '%s'"), path.buf);
 	}
diff --git a/notes-merge.c b/notes-merge.c
index c997c0c1e3..8c22a171c1 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -695,7 +695,7 @@ int notes_merge_commit(struct notes_merge_options *o,
 	const char *msg = strstr(buffer, "\n\n");
 	int baselen;
 
-	git_path_buf(&path, NOTES_MERGE_WORKTREE);
+	repo_git_path_replace(the_repository, &path, NOTES_MERGE_WORKTREE);
 	if (o->verbosity >= 3)
 		printf("Committing notes in notes merge worktree at %s\n",
 			path.buf);
@@ -757,7 +757,7 @@ int notes_merge_abort(struct notes_merge_options *o)
 	struct strbuf buf = STRBUF_INIT;
 	int ret;
 
-	git_path_buf(&buf, NOTES_MERGE_WORKTREE);
+	repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE);
 	if (o->verbosity >= 3)
 		printf("Removing notes merge worktree at %s/*\n", buf.buf);
 	ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);
diff --git a/object-file.c b/object-file.c
index 335cc2a5da..dc9fcaf3e9 100644
--- a/object-file.c
+++ b/object-file.c
@@ -476,14 +476,14 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
 	 * restrictive except to remove write permission.
 	 */
 	int mode = 0444;
-	git_path_buf(temp_filename, "objects/%s", pattern);
+	repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
 	fd = git_mkstemp_mode(temp_filename->buf, mode);
 	if (0 <= fd)
 		return fd;
 
 	/* slow path */
 	/* some mkstemp implementations erase temp_filename on failure */
-	git_path_buf(temp_filename, "objects/%s", pattern);
+	repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
 	safe_create_leading_directories(temp_filename->buf);
 	return xmkstemp_mode(temp_filename->buf, mode);
 }
diff --git a/path.h b/path.h
index 65a8f21c4c..cdc26acb74 100644
--- a/path.h
+++ b/path.h
@@ -256,22 +256,6 @@ static inline const char *git_common_path(const char *fmt, ...)
 	return pathname->buf;
 }
 
-/*
- * Construct a path into the main repository's (the_repository) git directory
- * and place it in the provided buffer `buf`, the contents of the buffer will
- * be overridden.
- */
-__attribute__((format (printf, 2, 3)))
-static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
-{
-	va_list args;
-	strbuf_reset(buf);
-	va_start(args, fmt);
-	repo_git_pathv(the_repository, NULL, buf, fmt, args);
-	va_end(args);
-	return buf->buf;
-}
-
 /*
  * Return a statically allocated path into the main repository's
  * (the_repository) git directory.
diff --git a/setup.c b/setup.c
index 74b5ba5325..30889386f7 100644
--- a/setup.c
+++ b/setup.c
@@ -2264,7 +2264,7 @@ static int is_reinit(void)
 	char junk[2];
 	int ret;
 
-	git_path_buf(&buf, "HEAD");
+	repo_git_path_replace(the_repository, &buf, "HEAD");
 	ret = !access(buf.buf, R_OK) || readlink(buf.buf, junk, sizeof(junk) - 1) != -1;
 	strbuf_release(&buf);
 	return ret;
@@ -2316,8 +2316,7 @@ static int create_default_files(const char *template_path,
 				int init_shared_repository)
 {
 	struct stat st1;
-	struct strbuf buf = STRBUF_INIT;
-	char *path;
+	struct strbuf path = STRBUF_INIT;
 	int reinit;
 	int filemode;
 	const char *work_tree = repo_get_work_tree(the_repository);
@@ -2358,14 +2357,14 @@ static int create_default_files(const char *template_path,
 	initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, reinit);
 
 	/* Check filemode trustability */
-	path = git_path_buf(&buf, "config");
+	repo_git_path_replace(the_repository, &path, "config");
 	filemode = TEST_FILEMODE;
-	if (TEST_FILEMODE && !lstat(path, &st1)) {
+	if (TEST_FILEMODE && !lstat(path.buf, &st1)) {
 		struct stat st2;
-		filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
-				!lstat(path, &st2) &&
+		filemode = (!chmod(path.buf, st1.st_mode ^ S_IXUSR) &&
+				!lstat(path.buf, &st2) &&
 				st1.st_mode != st2.st_mode &&
-				!chmod(path, st1.st_mode));
+				!chmod(path.buf, st1.st_mode));
 		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
 			filemode = 0;
 	}
@@ -2384,24 +2383,24 @@ static int create_default_files(const char *template_path,
 
 	if (!reinit) {
 		/* Check if symlink is supported in the work tree */
-		path = git_path_buf(&buf, "tXXXXXX");
-		if (!close(xmkstemp(path)) &&
-		    !unlink(path) &&
-		    !symlink("testing", path) &&
-		    !lstat(path, &st1) &&
+		repo_git_path_replace(the_repository, &path, "tXXXXXX");
+		if (!close(xmkstemp(path.buf)) &&
+		    !unlink(path.buf) &&
+		    !symlink("testing", path.buf) &&
+		    !lstat(path.buf, &st1) &&
 		    S_ISLNK(st1.st_mode))
-			unlink(path); /* good */
+			unlink(path.buf); /* good */
 		else
 			git_config_set("core.symlinks", "false");
 
 		/* Check if the filesystem is case-insensitive */
-		path = git_path_buf(&buf, "CoNfIg");
-		if (!access(path, F_OK))
+		repo_git_path_replace(the_repository, &path, "CoNfIg");
+		if (!access(path.buf, F_OK))
 			git_config_set("core.ignorecase", "true");
 		probe_utf8_pathname_composition();
 	}
 
-	strbuf_release(&buf);
+	strbuf_release(&path);
 	return reinit;
 }
 

-- 
2.48.1.538.gc4cfc42d60.dirty


  parent reply	other threads:[~2025-02-07 11:03 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06  7:57 [PATCH 00/16] path: remove dependency on `the_repository` Patrick Steinhardt
2025-02-06  7:57 ` [PATCH 01/16] path: refactor `repo_common_path()` family of functions Patrick Steinhardt
2025-02-06 11:17   ` Karthik Nayak
2025-02-07  6:16     ` Patrick Steinhardt
2025-02-06 14:21   ` shejialuo
2025-02-07  6:16     ` Patrick Steinhardt
2025-02-06  7:57 ` [PATCH 02/16] path: refactor `repo_git_path()` " Patrick Steinhardt
2025-02-06 11:53   ` Karthik Nayak
2025-02-07  6:15     ` Patrick Steinhardt
2025-02-06  7:57 ` [PATCH 03/16] path: refactor `repo_worktree_path()` " Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 04/16] submodule: refactor `submodule_to_gitdir()` to accept a repo Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 05/16] path: refactor `repo_submodule_path()` family of functions Patrick Steinhardt
2025-02-06 12:05   ` Karthik Nayak
2025-02-07  6:16     ` Patrick Steinhardt
2025-02-07  7:04       ` Karthik Nayak
2025-02-06 15:03   ` shejialuo
2025-02-06  7:58 ` [PATCH 06/16] path: drop unused `strbuf_git_path()` function Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 07/16] path: drop `git_pathdup()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 08/16] path: drop `git_path_buf()` in favor of `repo_git_path_replace()` Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 09/16] worktree: return allocated string from `get_worktree_git_dir()` Patrick Steinhardt
2025-02-07  7:15   ` Karthik Nayak
2025-02-07 10:49     ` Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 10/16] path: drop `git_common_path()` in favor of `repo_common_path()` Patrick Steinhardt
2025-02-06 15:54   ` shejialuo
2025-02-07  6:16     ` Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 11/16] rerere: let `rerere_path()` write paths into a caller-provided buffer Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 12/16] path: drop `git_path()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-06 16:01   ` shejialuo
2025-02-07  6:16     ` Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 13/16] repo-settings: introduce function to clear struct Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 14/16] environment: move access to "core.hooksPath" into repo settings Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 15/16] environment: move access to "core.sharedRepository" " Patrick Steinhardt
2025-02-06  7:58 ` [PATCH 16/16] path: adjust last remaining users of `the_repository` Patrick Steinhardt
2025-02-06 16:14 ` [PATCH 00/16] path: remove dependency on `the_repository` shejialuo
2025-02-07  6:16   ` Patrick Steinhardt
2025-02-07  8:17 ` Karthik Nayak
2025-02-07 11:03 ` [PATCH v2 " Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 01/16] path: refactor `repo_common_path()` family of functions Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 02/16] path: refactor `repo_git_path()` " Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 03/16] path: refactor `repo_worktree_path()` " Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 04/16] submodule: refactor `submodule_to_gitdir()` to accept a repo Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 05/16] path: refactor `repo_submodule_path()` family of functions Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 06/16] path: drop unused `strbuf_git_path()` function Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 07/16] path: drop `git_pathdup()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-07 11:03   ` Patrick Steinhardt [this message]
2025-02-07 11:03   ` [PATCH v2 09/16] worktree: return allocated string from `get_worktree_git_dir()` Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 10/16] path: drop `git_common_path()` in favor of `repo_common_path()` Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 11/16] rerere: let `rerere_path()` write paths into a caller-provided buffer Patrick Steinhardt
2025-02-22  7:20     ` Jeff King
2025-02-24 16:14       ` Junio C Hamano
2025-02-24 22:19         ` Jeff King
2025-02-24 22:50           ` Junio C Hamano
2025-02-24 23:10             ` Jeff King
2025-02-24 23:14               ` Junio C Hamano
2025-02-25  6:24                 ` Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 12/16] path: drop `git_path()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 13/16] repo-settings: introduce function to clear struct Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 14/16] environment: move access to "core.hooksPath" into repo settings Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 15/16] environment: move access to "core.sharedRepository" " Patrick Steinhardt
2025-02-07 11:03   ` [PATCH v2 16/16] path: adjust last remaining users of `the_repository` Patrick Steinhardt
2025-02-07 11:44   ` [PATCH v2 00/16] path: remove dependency on `the_repository` Karthik Nayak
2025-02-08 15:31   ` shejialuo
2025-02-10 18:32     ` Junio C Hamano
2025-02-11 10:03       ` shejialuo

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=20250207-b4-pks-path-drop-the-repository-v2-8-13cad3c11b8a@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=shejialuo@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;
as well as URLs for NNTP newsgroup(s).