insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
- strbuf_git_common_path(&path, repo, "objects/loose-object-idx");
+ repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
if (!fp) {
strbuf_release(&path);
if (!should_use_loose_object_map(repo))
return 0;
- strbuf_git_common_path(&path, repo, "objects/loose-object-idx");
+ repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fd = hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
iter = kh_begin(map);
if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
struct stat st;
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
- strbuf_git_common_path(&path, repo, "objects/loose-object-idx");
+ repo_common_path_replace(repo, &path, "objects/loose-object-idx");
hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
else if (!wt->id)
strbuf_addstr(buf, repo->commondir);
else
- strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id);
+ repo_common_path_append(repo, buf, "worktrees/%s", wt->id);
}
void repo_git_pathv(const struct repository *repo,
strbuf_cleanup_path(sb);
}
-void strbuf_git_common_path(struct strbuf *sb,
- const struct repository *repo,
- const char *fmt, ...)
+char *repo_common_path(const struct repository *repo,
+ const char *fmt, ...)
+{
+ struct strbuf sb = STRBUF_INIT;
+ va_list args;
+ va_start(args, fmt);
+ repo_common_pathv(repo, &sb, fmt, args);
+ va_end(args);
+ return strbuf_detach(&sb, NULL);
+}
+
+const char *repo_common_path_append(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ repo_common_pathv(repo, sb, fmt, args);
+ va_end(args);
+ return sb->buf;
+}
+
+const char *repo_common_path_replace(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
{
va_list args;
+ strbuf_reset(sb);
va_start(args, fmt);
repo_common_pathv(repo, sb, fmt, args);
va_end(args);
+ return sb->buf;
}
static struct passwd *getpw_str(const char *username, size_t len)
__attribute__((format (printf, 1, 2)));
/*
- * The `strbuf_git_common_path` family of functions will construct a path into a
+ * The `repo_common_path` family of functions will construct a path into a
* repository's common git directory, which is shared by all worktrees.
*/
-
-/*
- * Constructs a path into the common git directory of repository `repo` and
- * append it in the provided buffer `sb`.
- */
-void strbuf_git_common_path(struct strbuf *sb,
- const struct repository *repo,
- const char *fmt, ...)
+char *repo_common_path(const struct repository *repo,
+ const char *fmt, ...)
+ __attribute__((format (printf, 2, 3)));
+const char *repo_common_path_append(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
+ __attribute__((format (printf, 3, 4)));
+const char *repo_common_path_replace(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
-void repo_common_pathv(const struct repository *repo,
- struct strbuf *buf,
- const char *fmt,
- va_list args);
/*
* The `repo_git_path` family of functions will construct a path into a repository's
# include "strbuf.h"
# include "repository.h"
+/* Internal implementation detail that should not be used. */
+void repo_common_pathv(const struct repository *repo,
+ struct strbuf *buf,
+ const char *fmt,
+ va_list args);
+
/*
* Return a statically allocated path into the main repository's
* (the_repository) common git directory.
if (wt->id) {
struct strbuf common_path = STRBUF_INIT;
- strbuf_git_common_path(&common_path, wt->repo,
- "worktrees/%s", wt->id);
+ repo_common_path_append(wt->repo, &common_path,
+ "worktrees/%s", wt->id);
refs = ref_store_init(wt->repo, wt->repo->ref_storage_format,
common_path.buf, REF_STORE_ALL_CAPS);
strbuf_release(&common_path);
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
int ret;
- strbuf_git_common_path(&sb, the_repository, "config");
+ repo_common_path_append(the_repository, &sb, "config");
read_repository_format(&repo_fmt, sb.buf);
strbuf_release(&sb);
struct strbuf config = STRBUF_INIT;
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
- strbuf_git_common_path(&config, the_repository, "config");
+ repo_common_path_append(the_repository, &config, "config");
read_repository_format(&repo_fmt, config.buf);
if (repo_fmt.v1_only_extensions.nr)
if (!id)
die("Missing linked worktree name");
- strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id);
+ repo_common_path_append(the_repository, &path, "worktrees/%s/gitdir", id);
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
/* invalid gitdir file */
goto done;
id++; /* advance past '/' to point at <id> */
if (!*id)
goto error;
- strbuf_reset(inferred);
- strbuf_git_common_path(inferred, the_repository, "worktrees/%s", id);
+ repo_common_path_replace(the_repository, inferred, "worktrees/%s", id);
if (!is_directory(inferred->buf))
goto error;