diff options
author | Brandon Williams <bmwill@google.com> | 2017-06-22 11:43:41 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-23 18:24:34 -0700 |
commit | b42b0c09199db794b2a34ae9ce293d6711fb6a4f (patch) | |
tree | dde62fe0f95a623d1780e8ceee3872ec828639ea /path.c | |
parent | path: add repo_git_path and strbuf_repo_git_path (diff) | |
download | tgif-b42b0c09199db794b2a34ae9ce293d6711fb6a4f.tar.xz |
path: add repo_worktree_path and strbuf_repo_worktree_path
Introduce 'repo_worktree_path' and 'strbuf_repo_worktree_path' which
take a repository struct and constructs a path relative to the
repository's worktree.
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -506,6 +506,47 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...) return pathname->buf; } +static void do_worktree_path(const struct repository *repo, + struct strbuf *buf, + const char *fmt, va_list args) +{ + strbuf_addstr(buf, repo->worktree); + if(buf->len && !is_dir_sep(buf->buf[buf->len - 1])) + strbuf_addch(buf, '/'); + + strbuf_vaddf(buf, fmt, args); + strbuf_cleanup_path(buf); +} + +char *repo_worktree_path(const struct repository *repo, const char *fmt, ...) +{ + struct strbuf path = STRBUF_INIT; + va_list args; + + if (!repo->worktree) + return NULL; + + va_start(args, fmt); + do_worktree_path(repo, &path, fmt, args); + va_end(args); + + return strbuf_detach(&path, NULL); +} + +void strbuf_repo_worktree_path(struct strbuf *sb, + const struct repository *repo, + const char *fmt, ...) +{ + va_list args; + + if (!repo->worktree) + return; + + va_start(args, fmt); + do_worktree_path(repo, sb, fmt, args); + va_end(args); +} + /* Returns 0 on success, negative on failure. */ static int do_submodule_path(struct strbuf *buf, const char *path, const char *fmt, va_list args) |