diff options
author | Brandon Williams <bmwill@google.com> | 2017-06-22 11:43:38 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-23 18:24:34 -0700 |
commit | f9a8a47e3951581e09d1f97ebe70f0e3f75c63af (patch) | |
tree | 5e7fd7050b1450d127c7a378ef8c9debf0b5e39e | |
parent | b337172c834b854903fb523416b53fe354b6e2a5 (diff) | |
download | git-f9a8a47e3951581e09d1f97ebe70f0e3f75c63af.tar.gz |
path: convert do_git_path to take a 'struct repository'
In preparation to adding 'git_path' like functions which operate on a
'struct repository' convert 'do_git_path' to take a 'struct repository'.
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | path.c | 42 |
1 files changed, 28 insertions, 14 deletions
@@ -371,33 +371,47 @@ void report_linked_checkout_garbage(void) 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); + adjust_git_path(repo, buf, gitdir_len); strbuf_cleanup_path(buf); } @@ -406,7 +420,7 @@ 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; } @@ -415,7 +429,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) { 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); } @@ -424,7 +438,7 @@ const char *git_path(const char *fmt, ...) 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; } @@ -434,7 +448,7 @@ char *git_pathdup(const char *fmt, ...) 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); } @@ -465,7 +479,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...) 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; } |