summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-06-01 18:34:21 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-01 18:54:47 +0200
commitf7e59c4dcf46e0815ab0e7d435fd16755fdf616c (patch)
tree353d781e1efab8b73eb81a848da8bb276a001dd3 /src
parentef5ffed39a91e8e645ed77f52ec862d47b081e9c (diff)
downloadlibgit2-f7e59c4dcf46e0815ab0e7d435fd16755fdf616c.tar.gz
index: Change the memory management for repo indexes
The `git_repository_index` call now returns a brand new index that must be manually free'd.
Diffstat (limited to 'src')
-rw-r--r--src/index.c12
-rw-r--r--src/repository.c23
-rw-r--r--src/repository.h1
3 files changed, 9 insertions, 27 deletions
diff --git a/src/index.c b/src/index.c
index 389780295..c1edd156d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -168,13 +168,19 @@ static int index_initialize(git_index **index_out, git_repository *owner, const
return git_index_read(index);
}
-int git_index_open_bare(git_index **index_out, const char *index_path)
+int git_index_open(git_index **index_out, const char *index_path)
{
+ assert(index_out && index_path);
return index_initialize(index_out, NULL, index_path);
}
-int git_index_open_inrepo(git_index **index_out, git_repository *repo)
+/*
+ * Moved from `repository.c`
+ */
+int git_repository_index(git_index **index_out, git_repository *repo)
{
+ assert(index_out && repo);
+
if (repo->is_bare)
return git__throw(GIT_EBAREINDEX, "Failed to open index. Repository is bare");
@@ -183,7 +189,7 @@ int git_index_open_inrepo(git_index **index_out, git_repository *repo)
void git_index_free(git_index *index)
{
- if (index == NULL || index->repository != NULL)
+ if (index == NULL)
return;
git_index_clear(index);
diff --git a/src/repository.c b/src/repository.c
index 468c88851..0dd36688b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -315,32 +315,9 @@ void git_repository_free(git_repository *repo)
if (repo->db != NULL)
git_odb_close(repo->db);
- if (repo->index != NULL) {
- repo->index->repository = NULL;
- git_index_free(repo->index);
- }
-
free(repo);
}
-int git_repository_index(git_index **index_out, git_repository *repo)
-{
- int error;
-
- assert(index_out && repo);
-
- if (repo->index == NULL) {
- error = git_index_open_inrepo(&repo->index, repo); /* TODO: move index.c to new error handling */
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to open repository index");
-
- assert(repo->index != NULL);
- }
-
- *index_out = repo->index;
- return GIT_SUCCESS;
-}
-
git_odb *git_repository_database(git_repository *repo)
{
assert(repo);
diff --git a/src/repository.h b/src/repository.h
index 813cac942..bcf9b2bc8 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -25,7 +25,6 @@ struct git_object {
struct git_repository {
git_odb *db;
- git_index *index;
git_cache objects;
git_refcache references;