Skip to content

Commit 4584660

Browse files
committed
bugfix: don't generate paths with empty segments
1 parent d095502 commit 4584660

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/refdb_fs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
578578
}
579579
}
580580

581-
if ((error = git_buf_printf(&path, "%s/", backend->commonpath)) < 0 ||
581+
if ((error = git_buf_puts(&path, backend->commonpath)) < 0 ||
582582
(error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
583583
git_buf_dispose(&path);
584584
return error;
@@ -1609,8 +1609,9 @@ static char *setup_namespace(git_repository *repo, const char *in)
16091609
GIT_MKDIR_PATH, NULL) < 0)
16101610
goto done;
16111611

1612-
/* Return root of the namespaced gitpath, i.e. without the trailing '/refs' */
1612+
/* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */
16131613
git_buf_rtruncate_at_char(&path, '/');
1614+
git_buf_putc(&path, '/');
16141615
out = git_buf_detach(&path);
16151616

16161617
done:

src/worktree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
4343
wts->count = 0;
4444
wts->strings = NULL;
4545

46-
if ((error = git_buf_printf(&path, "%s/worktrees/", repo->commondir)) < 0)
46+
if ((error = git_buf_joinpath(&path, repo->commondir, "worktrees/")) < 0)
4747
goto exit;
4848
if (!git_path_exists(path.ptr) || git_path_is_empty_dir(path.ptr))
4949
goto exit;
@@ -182,7 +182,7 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
182182

183183
*out = NULL;
184184

185-
if ((error = git_buf_printf(&path, "%s/worktrees/%s", repo->commondir, name)) < 0)
185+
if ((error = git_buf_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
186186
goto out;
187187

188188
if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
@@ -592,7 +592,7 @@ int git_worktree_prune(git_worktree *wt,
592592
}
593593

594594
/* Delete gitdir in parent repository */
595-
if ((err = git_buf_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name)) < 0)
595+
if ((err = git_buf_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
596596
goto out;
597597
if (!git_path_exists(path.ptr))
598598
{

0 commit comments

Comments
 (0)