Skip to content

Commit

Permalink
is_refname_available(): convert local variable "dirname" to strbuf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed May 11, 2015
1 parent 9ef6eaa commit 6075f30
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
/*
Expand Down

0 comments on commit 6075f30

Please sign in to comment.