diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2015-05-11 17:25:06 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-05-11 11:50:17 -0700 |
commit | 6075f3076e8a7fea0a132d459d1e21e771cdd880 (patch) | |
tree | 90d6a2070e240656cf888a67b97e0209ff914ad0 | |
parent | is_refname_available(): avoid shadowing "dir" variable (diff) | |
download | tgif-6075f3076e8a7fea0a132d459d1e21e771cdd880.tar.xz |
is_refname_available(): convert local variable "dirname" to strbuf
This change wouldn't be worth it by itself, but in a moment we will
use the strbuf for more string juggling.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
-rw-r--r-- | refs.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -887,9 +887,8 @@ static int is_refname_available(const char *refname, struct ref_dir *dir) { const char *slash; - size_t len; int pos; - char *dirname; + struct strbuf dirname = STRBUF_INIT; /* * For the sake of comments in this function, suppose that @@ -955,11 +954,10 @@ static int is_refname_available(const char *refname, * names are in the "refs/foo/bar/" namespace, because they * *do* conflict. */ - len = strlen(refname); - dirname = xmallocz(len + 1); - sprintf(dirname, "%s/", refname); - pos = search_ref_dir(dir, dirname, len + 1); - free(dirname); + strbuf_addstr(&dirname, refname); + strbuf_addch(&dirname, '/'); + pos = search_ref_dir(dir, dirname.buf, dirname.len); + strbuf_release(&dirname); if (pos >= 0) { /* |