]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replace strbuf_addstr(git_path()) with git_path_buf()
authorJeff King <peff@peff.net>
Thu, 20 Apr 2017 21:09:30 +0000 (17:09 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Apr 2017 04:04:20 +0000 (21:04 -0700)
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>
builtin/worktree.c
notes-merge.c

index 831fe058a53da95643b1a93038f576d5bffea7ef..9cceaf451963987f361cd5e3d81b930004f079b9 100644 (file)
@@ -106,8 +106,7 @@ static void prune_worktrees(void)
                        printf("%s\n", reason.buf);
                if (show_only)
                        continue;
-               strbuf_reset(&path);
-               strbuf_addstr(&path, git_path("worktrees/%s", d->d_name));
+               git_path_buf(&path, "worktrees/%s", d->d_name);
                ret = remove_dir_recursively(&path, 0);
                if (ret < 0 && errno == ENOTDIR)
                        ret = unlink(path.buf);
@@ -215,8 +214,7 @@ static int add_worktree(const char *path, const char *refname,
        }
 
        name = worktree_basename(path, &len);
-       strbuf_addstr(&sb_repo,
-                     git_path("worktrees/%.*s", (int)(path + len - name), name));
+       git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name);
        len = sb_repo.len;
        if (safe_create_leading_directories_const(sb_repo.buf))
                die_errno(_("could not create leading directories of '%s'"),
index 5998605acc64471193dc9d945610db8491f34bd8..32caaaff7477d3640c81a19c54c1c92ffb8ca8b1 100644 (file)
@@ -676,7 +676,7 @@ int notes_merge_commit(struct notes_merge_options *o,
        const char *msg = strstr(buffer, "\n\n");
        int baselen;
 
-       strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
+       git_path_buf(&path, NOTES_MERGE_WORKTREE);
        if (o->verbosity >= 3)
                printf("Committing notes in notes merge worktree at %s\n",
                        path.buf);
@@ -741,7 +741,7 @@ int notes_merge_abort(struct notes_merge_options *o)
        struct strbuf buf = STRBUF_INIT;
        int ret;
 
-       strbuf_addstr(&buf, git_path(NOTES_MERGE_WORKTREE));
+       git_path_buf(&buf, NOTES_MERGE_WORKTREE);
        if (o->verbosity >= 3)
                printf("Removing notes merge worktree at %s/*\n", buf.buf);
        ret = remove_dir_recursively(&buf, REMOVE_DIR_KEEP_TOPLEVEL);