find_containing_dir(): use strbuf in implementation of this function

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty
2012-04-27 00:27:00 +02:00
committed by Junio C Hamano
parent 144e709004
commit 5fa0441844

17
refs.c
View File

@ -309,20 +309,21 @@ static struct ref_entry *search_for_subdir(struct ref_dir *dir,
static struct ref_dir *find_containing_dir(struct ref_dir *dir, static struct ref_dir *find_containing_dir(struct ref_dir *dir,
const char *refname, int mkdir) const char *refname, int mkdir)
{ {
char *refname_copy = xstrdup(refname); struct strbuf dirname;
char *slash; const char *slash;
strbuf_init(&dirname, PATH_MAX);
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
struct ref_entry *entry; struct ref_entry *entry;
for (slash = strchr(refname_copy, '/'); slash; slash = strchr(slash + 1, '/')) { strbuf_add(&dirname,
char tmp = slash[1]; refname + dirname.len,
slash[1] = '\0'; (slash + 1) - (refname + dirname.len));
entry = search_for_subdir(dir, refname_copy, mkdir); entry = search_for_subdir(dir, dirname.buf, mkdir);
slash[1] = tmp;
if (!entry) if (!entry)
break; break;
dir = &entry->u.subdir; dir = &entry->u.subdir;
} }
free(refname_copy); strbuf_release(&dirname);
return dir; return dir;
} }