commit - deeca23839609f94e076f97f16d1d7cde09daf3b
commit + 4986b9d5fdccbfe5567643b87d0c855fc7eca8b0
blob - 104167f68a48a72f7981d96d863de1f3e09e7fac
blob + 2eecc5f80f379b929f5aceb980431c7b171e883f
--- lib/got_repository_lib.h
+++ lib/got_repository_lib.h
struct got_repository {
char *path;
+ char *path_git_dir;
/* The pack index cache speeds up search for packed objects. */
struct got_packidx_v2_hdr *packidx_cache[GOT_PACKIDX_CACHE_SIZE];
blob - c13711cf098cbc488fdb86c373f4b4d4461cb3f5
blob + 96fa4ce373bd26fae26fa0ef06ec8d581f1b0d3a
--- lib/repository.c
+++ lib/repository.c
char *
got_repo_get_path_git_dir(struct got_repository *repo)
{
- char *path_git;
-
- if (asprintf(&path_git, "%s/%s", repo->path, GOT_GIT_DIR) == -1)
- return NULL;
-
- return path_git;
+ return strdup(repo->path_git_dir);
}
static char *
{
char *path_child;
- if (asprintf(&path_child, "%s/%s/%s", repo->path, GOT_GIT_DIR,
+ if (asprintf(&path_child, "%s/%s", repo->path_git_dir,
basename) == -1)
return NULL;
goto done;
}
- if (!is_git_repo(repo)) {
- err = got_error(GOT_ERR_NOT_GIT_REPO);
+ repo->path_git_dir = strdup(repo->path);
+ if (repo->path_git_dir == NULL) {
+ err = got_error(GOT_ERR_NO_MEM);
goto done;
}
+ if (!is_git_repo(repo)) {
+ free(repo->path_git_dir);
+ if (asprintf(&repo->path_git_dir, "%s/%s", repo->path,
+ GOT_GIT_DIR) == -1) {
+ err = got_error(GOT_ERR_NO_MEM);
+ goto done;
+ }
+ if (!is_git_repo(repo)) {
+ err = got_error(GOT_ERR_NOT_GIT_REPO);
+ goto done;
+ }
+ }
*ret = repo;
done:
if (err)
- free(repo);
+ got_repo_close(repo);
free(abspath);
return err;
}
got_packidx_close(repo->packidx_cache[i]);
}
free(repo->path);
+ free(repo->path_git_dir);
free(repo);
}