diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2012-04-27 00:27:00 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-05-03 13:15:35 -0700 |
commit | 5fa0441844b1d23e6a2a3c369651dc8c13712ef6 (patch) | |
tree | 709bbcd4c6201573a370205dfed6632d5b56fbce /refs.c | |
parent | 144e7090045a703c8f5d140474f202ba4f38ac9a (diff) | |
download | git-5fa0441844b1d23e6a2a3c369651dc8c13712ef6.tar.gz git-5fa0441844b1d23e6a2a3c369651dc8c13712ef6.tar.xz |
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>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -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, const char *refname, int mkdir) { - char *refname_copy = xstrdup(refname); - char *slash; - struct ref_entry *entry; - for (slash = strchr(refname_copy, '/'); slash; slash = strchr(slash + 1, '/')) { - char tmp = slash[1]; - slash[1] = '\0'; - entry = search_for_subdir(dir, refname_copy, mkdir); - slash[1] = tmp; + struct strbuf dirname; + const char *slash; + strbuf_init(&dirname, PATH_MAX); + for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) { + struct ref_entry *entry; + strbuf_add(&dirname, + refname + dirname.len, + (slash + 1) - (refname + dirname.len)); + entry = search_for_subdir(dir, dirname.buf, mkdir); if (!entry) break; dir = &entry->u.subdir; } - free(refname_copy); + strbuf_release(&dirname); return dir; } |