summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2012-05-22 18:50:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-05-22 20:32:26 (GMT)
commitdd02e72852280d73bfd845703476b230475b2776 (patch)
tree2abb0bb47e7804e3a25dada2d85e1e6b38e1e07f /refs.c
parentb9146f517a312fed42d12b32e3ee3bd99944121d (diff)
downloadgit-dd02e72852280d73bfd845703476b230475b2776.zip
git-dd02e72852280d73bfd845703476b230475b2776.tar.gz
git-dd02e72852280d73bfd845703476b230475b2776.tar.bz2
refs: use strings directly in find_containing_dir()
Convert the parameter subdirname of search_for_subdir() to a length-limted string and then simply pass the interesting slice of the refname from find_containing_dir(), thereby avoiding to duplicate the string. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/refs.c b/refs.c
index c5e167b..96e943c 100644
--- a/refs.c
+++ b/refs.c
@@ -352,9 +352,9 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir,
* directory cannot be found. dir must already be complete.
*/
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
- const char *subdirname, int mkdir)
+ const char *subdirname, size_t len,
+ int mkdir)
{
- size_t len = strlen(subdirname);
struct ref_entry *entry = search_ref_dir(dir, subdirname, len);
if (!entry) {
if (!mkdir)
@@ -383,15 +383,11 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
static struct ref_dir *find_containing_dir(struct ref_dir *dir,
const char *refname, int mkdir)
{
- struct strbuf dirname;
const char *slash;
- strbuf_init(&dirname, PATH_MAX);
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
+ size_t dirnamelen = slash - refname + 1;
struct ref_dir *subdir;
- strbuf_add(&dirname,
- refname + dirname.len,
- (slash + 1) - (refname + dirname.len));
- subdir = search_for_subdir(dir, dirname.buf, mkdir);
+ subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
if (!subdir) {
dir = NULL;
break;
@@ -399,7 +395,6 @@ static struct ref_dir *find_containing_dir(struct ref_dir *dir,
dir = subdir;
}
- strbuf_release(&dirname);
return dir;
}