strbuf_release(&sb);
}
-static void adjust_git_path(struct strbuf *buf, int git_dir_len)
+static void adjust_git_path(const struct repository *repo,
+ struct strbuf *buf, int git_dir_len)
{
const char *base = buf->buf + git_dir_len;
if (is_dir_file(base, "info", "grafts"))
strbuf_splice(buf, 0, buf->len,
- get_graft_file(), strlen(get_graft_file()));
+ repo->graft_file, strlen(repo->graft_file));
else if (!strcmp(base, "index"))
strbuf_splice(buf, 0, buf->len,
- get_index_file(), strlen(get_index_file()));
+ repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, get_object_directory());
+ replace_dir(buf, git_dir_len + 7, repo->objectdir);
else if (git_hooks_path && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, git_hooks_path);
- else if (the_repository->different_commondir)
- update_common_dir(buf, git_dir_len, get_git_common_dir());
+ else if (repo->different_commondir)
+ update_common_dir(buf, git_dir_len, repo->commondir);
}
-static void do_git_path(const struct worktree *wt, struct strbuf *buf,
+static void strbuf_worktree_gitdir(struct strbuf *buf,
+ const struct repository *repo,
+ const struct worktree *wt)
+{
+ if (!wt)
+ strbuf_addstr(buf, repo->gitdir);
+ else if (!wt->id)
+ strbuf_addstr(buf, repo->commondir);
+ else
+ strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id);
+}
+
+static void do_git_path(const struct repository *repo,
+ const struct worktree *wt, struct strbuf *buf,
const char *fmt, va_list args)
{
int gitdir_len;
- strbuf_addstr(buf, get_worktree_git_dir(wt));
+ strbuf_worktree_gitdir(buf, repo, wt);
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
strbuf_addch(buf, '/');
gitdir_len = buf->len;
strbuf_vaddf(buf, fmt, args);
- adjust_git_path(buf, gitdir_len);
+ if (!wt)
+ adjust_git_path(repo, buf, gitdir_len);
strbuf_cleanup_path(buf);
}
+char *repo_git_path(const struct repository *repo,
+ const char *fmt, ...)
+{
+ struct strbuf path = STRBUF_INIT;
+ va_list args;
+ va_start(args, fmt);
+ do_git_path(repo, NULL, &path, fmt, args);
+ va_end(args);
+ return strbuf_detach(&path, NULL);
+}
+
+void strbuf_repo_git_path(struct strbuf *sb,
+ const struct repository *repo,
+ const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ do_git_path(repo, NULL, sb, fmt, args);
+ va_end(args);
+}
+
char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
{
va_list args;
strbuf_reset(buf);
va_start(args, fmt);
- do_git_path(NULL, buf, fmt, args);
+ do_git_path(the_repository, NULL, buf, fmt, args);
va_end(args);
return buf->buf;
}
{
va_list args;
va_start(args, fmt);
- do_git_path(NULL, sb, fmt, args);
+ do_git_path(the_repository, NULL, sb, fmt, args);
va_end(args);
}
struct strbuf *pathname = get_pathname();
va_list args;
va_start(args, fmt);
- do_git_path(NULL, pathname, fmt, args);
+ do_git_path(the_repository, NULL, pathname, fmt, args);
va_end(args);
return pathname->buf;
}
struct strbuf path = STRBUF_INIT;
va_list args;
va_start(args, fmt);
- do_git_path(NULL, &path, fmt, args);
+ do_git_path(the_repository, NULL, &path, fmt, args);
va_end(args);
return strbuf_detach(&path, NULL);
}
struct strbuf *pathname = get_pathname();
va_list args;
va_start(args, fmt);
- do_git_path(wt, pathname, fmt, args);
+ do_git_path(the_repository, wt, pathname, fmt, args);
va_end(args);
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)
return err;
}
-static void do_git_common_path(struct strbuf *buf,
+static void do_git_common_path(const struct repository *repo,
+ struct strbuf *buf,
const char *fmt,
va_list args)
{
- strbuf_addstr(buf, get_git_common_dir());
+ strbuf_addstr(buf, repo->commondir);
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
strbuf_addch(buf, '/');
strbuf_vaddf(buf, fmt, args);
struct strbuf *pathname = get_pathname();
va_list args;
va_start(args, fmt);
- do_git_common_path(pathname, fmt, args);
+ do_git_common_path(the_repository, pathname, fmt, args);
va_end(args);
return pathname->buf;
}
-void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...)
+void strbuf_git_common_path(struct strbuf *sb,
+ const struct repository *repo,
+ const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- do_git_common_path(sb, fmt, args);
+ do_git_common_path(repo, sb, fmt, args);
va_end(args);
}