Skip to content

Commit 6075f30

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]>
1 parent 9ef6eaa commit 6075f30

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

refs.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,8 @@ static int is_refname_available(const char *refname,
887887
struct ref_dir *dir)
888888
{
889889
const char *slash;
890-
size_t len;
891890
int pos;
892-
char *dirname;
891+
struct strbuf dirname = STRBUF_INIT;
893892

894893
/*
895894
* For the sake of comments in this function, suppose that
@@ -955,11 +954,10 @@ static int is_refname_available(const char *refname,
955954
* names are in the "refs/foo/bar/" namespace, because they
956955
* *do* conflict.
957956
*/
958-
len = strlen(refname);
959-
dirname = xmallocz(len + 1);
960-
sprintf(dirname, "%s/", refname);
961-
pos = search_ref_dir(dir, dirname, len + 1);
962-
free(dirname);
957+
strbuf_addstr(&dirname, refname);
958+
strbuf_addch(&dirname, '/');
959+
pos = search_ref_dir(dir, dirname.buf, dirname.len);
960+
strbuf_release(&dirname);
963961

964962
if (pos >= 0) {
965963
/*

0 commit comments

Comments
 (0)