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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 20, 2017 at 17:09 UTC
8c2ca3a6d6d0bf51332f92d25b7902f9943aaaf2
2 files changed
+4
-6
builtin/worktree.c
+2
-4
@@ -106,8 +106,7 @@ static void prune_worktrees(void)
106
printf("%s\n", reason.buf);
107
if (show_only)
108
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);
110
ret = remove_dir_recursively(&path, 0);
111
if (ret < 0 && errno == ENOTDIR)
112
ret = unlink(path.buf);
@@ -215,8 +214,7 @@ static int add_worktree(const char *path, const char *refname,
214
}
215
216
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);
218
len = sb_repo.len;
219
if (safe_create_leading_directories_const(sb_repo.buf))
220
die_errno(_("could not create leading directories of '%s'"),
notes-merge.c
+2
-2
@@ -676,7 +676,7 @@ int notes_merge_commit(struct notes_merge_options *o,
676
const char *msg = strstr(buffer, "\n\n");
677
int baselen;
678
679
- strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
679
+ git_path_buf(&path, NOTES_MERGE_WORKTREE);
680
if (o->verbosity >= 3)
681
printf("Committing notes in notes merge worktree at %s\n",
682
path.buf);
@@ -741,7 +741,7 @@ int notes_merge_abort(struct notes_merge_options *o)
741
struct strbuf buf = STRBUF_INIT;
742
int ret;
743
744
- strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE));
744
+ git_path_buf(&buf, NOTES_MERGE_WORKTREE);
745
if (o->verbosity >= 3)
746
printf("Removing notes merge worktree at %s/*\n", buf.buf);
747
ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);