aboutsummaryrefslogtreecommitdiffstats
path: root/path.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-02-07 12:03:28 +0100
committerJunio C Hamano <gitster@pobox.com>2025-02-07 09:59:21 -0800
commit93a8cfaf3c24f8c1f999b2ca5532ff8f46e0808d (patch)
treef64efa23c359303513f89a6c321e93f22015df9b /path.c
parentpath: refactor `repo_git_path()` family of functions (diff)
downloadgit-93a8cfaf3c24f8c1f999b2ca5532ff8f46e0808d.tar.gz
git-93a8cfaf3c24f8c1f999b2ca5532ff8f46e0808d.zip
path: refactor `repo_worktree_path()` family of functions
As explained in an earlier commit, we're refactoring path-related functions to provide a consistent interface for computing paths into the commondir, gitdir and worktree. Refactor the "worktree" family of functions accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/path.c b/path.c
index 779aa94b56..499116dd1e 100644
--- a/path.c
+++ b/path.c
@@ -519,28 +519,44 @@ char *repo_worktree_path(const struct repository *repo, const char *fmt, ...)
struct strbuf path = STRBUF_INIT;
va_list args;
+ va_start(args, fmt);
+ do_worktree_path(repo, &path, fmt, args);
+ va_end(args);
+
+ return strbuf_detach(&path, NULL);
+}
+
+const char *repo_worktree_path_append(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
+{
+ va_list args;
+
if (!repo->worktree)
return NULL;
va_start(args, fmt);
- do_worktree_path(repo, &path, fmt, args);
+ do_worktree_path(repo, sb, fmt, args);
va_end(args);
- return strbuf_detach(&path, NULL);
+ return sb->buf;
}
-void strbuf_repo_worktree_path(struct strbuf *sb,
- const struct repository *repo,
- const char *fmt, ...)
+const char *repo_worktree_path_replace(const struct repository *repo,
+ struct strbuf *sb,
+ const char *fmt, ...)
{
va_list args;
+ strbuf_reset(sb);
if (!repo->worktree)
- return;
+ return NULL;
va_start(args, fmt);
do_worktree_path(repo, sb, fmt, args);
va_end(args);
+
+ return sb->buf;
}
/* Returns 0 on success, negative on failure. */