summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-05-01 14:25:44 +0200
committerJunio C Hamano <gitster@pobox.com>2015-05-10 11:31:31 -0700
commit68ff34b31c7a63b025a9e687b3680ad9e4101497 (patch)
treebc244afb9051ee266fda71a662f3a5815db73010
parentbf21943f173a9d0c40adeb75b775357ee4d209fc (diff)
downloadgit-68ff34b31c7a63b025a9e687b3680ad9e4101497.tar.gz
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.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/refs.c b/refs.c
index 7a68994306..4924b203be 100644
--- a/refs.c
+++ b/refs.c
@@ -893,9 +893,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 (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
/*
@@ -943,11 +942,10 @@ static int is_refname_available(const char *refname,
* We are at the leaf of our refname; we want to
* make sure there are no directories which match it.
*/
- 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) {
/*