Skip to content

Commit 8c2ca3a

Browse files
peffgitster
authored andcommitted
replace strbuf_addstr(git_path()) with git_path_buf()
Writing directly into the strbuf avoids a useless copy of the data, and dropping calls to git_path() makes it easier to audit for dangerous calls. Note that git_path() does an implicit strbuf_reset(), but in each of these cases we were either already doing that reset, or writing into a fresh strbuf anyway. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9c6964 commit 8c2ca3a

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

builtin/worktree.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ static void prune_worktrees(void)
106106
printf("%s\n", reason.buf);
107107
if (show_only)
108108
continue;
109-
strbuf_reset(&path);
110-
strbuf_addstr(&path, git_path("worktrees/%s", d->d_name));
109+
git_path_buf(&path, "worktrees/%s", d->d_name);
111110
ret = remove_dir_recursively(&path, 0);
112111
if (ret < 0 && errno == ENOTDIR)
113112
ret = unlink(path.buf);
@@ -215,8 +214,7 @@ static int add_worktree(const char *path, const char *refname,
215214
}
216215

217216
name = worktree_basename(path, &len);
218-
strbuf_addstr(&sb_repo,
219-
git_path("worktrees/%.*s", (int)(path + len - name), name));
217+
git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name);
220218
len = sb_repo.len;
221219
if (safe_create_leading_directories_const(sb_repo.buf))
222220
die_errno(_("could not create leading directories of '%s'"),

notes-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ int notes_merge_commit(struct notes_merge_options *o,
676676
const char *msg = strstr(buffer, "\n\n");
677677
int baselen;
678678

679-
strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
679+
git_path_buf(&path, NOTES_MERGE_WORKTREE);
680680
if (o->verbosity >= 3)
681681
printf("Committing notes in notes merge worktree at %s\n",
682682
path.buf);
@@ -741,7 +741,7 @@ int notes_merge_abort(struct notes_merge_options *o)
741741
struct strbuf buf = STRBUF_INIT;
742742
int ret;
743743

744-
strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE));
744+
git_path_buf(&buf, NOTES_MERGE_WORKTREE);
745745
if (o->verbosity >= 3)
746746
printf("Removing notes merge worktree at %s/*\n", buf.buf);
747747
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);

0 commit comments

Comments
 (0)