diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-03-15 13:42:52 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-03-17 08:56:18 +0100 |
commit | 3e9c5d8a05b364a27514bd3f9e0c4170f2e16084 (patch) | |
tree | da9b231a5bd8b876af4280c4ac7c79317b053a86 | |
parent | f3c30686701ed0593cdcbb50085fd2fa0e706cf7 (diff) | |
download | libgit2-3e9c5d8a05b364a27514bd3f9e0c4170f2e16084.tar.gz |
worktree: have `is_worktree_dir` accept a string instead of buffer
This will be used in later commits, where it becomes cumbersome to
always pass in a buffer.
-rw-r--r-- | src/worktree.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/worktree.c b/src/worktree.c index 5abc98945..7977d8e7b 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -14,11 +14,20 @@ #include "repository.h" #include "worktree.h" -static bool is_worktree_dir(git_buf *dir) +static bool is_worktree_dir(const char *dir) { - return git_path_contains_file(dir, "commondir") - && git_path_contains_file(dir, "gitdir") - && git_path_contains_file(dir, "HEAD"); + git_buf buf = GIT_BUF_INIT; + int error; + + if (git_buf_sets(&buf, dir) < 0) + return -1; + + error = git_path_contains_file(&buf, "commondir") + && git_path_contains_file(&buf, "gitdir") + && git_path_contains_file(&buf, "HEAD"); + + git_buf_free(&buf); + return error; } int git_worktree_list(git_strarray *wts, git_repository *repo) @@ -47,7 +56,7 @@ int git_worktree_list(git_strarray *wts, git_repository *repo) git_buf_truncate(&path, len); git_buf_puts(&path, worktree); - if (!is_worktree_dir(&path)) { + if (!is_worktree_dir(path.ptr)) { git_vector_remove(&worktrees, i); git__free(worktree); } @@ -125,7 +134,7 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na if ((error = git_buf_printf(&path, "%s/worktrees/%s", repo->commondir, name)) < 0) goto out; - if (!is_worktree_dir(&path)) { + if (!is_worktree_dir(path.ptr)) { error = -1; goto out; } @@ -177,7 +186,7 @@ int git_worktree_validate(const git_worktree *wt) assert(wt); git_buf_puts(&buf, wt->gitdir_path); - if (!is_worktree_dir(&buf)) { + if (!is_worktree_dir(buf.ptr)) { giterr_set(GITERR_WORKTREE, "Worktree gitdir ('%s') is not valid", wt->gitlink_path); |