Commit 879458e7 by Vicent Marti

repo: Add `git_repository__cleanup`

parent 2370b4d7
......@@ -27,6 +27,20 @@ GIT_BEGIN_DECL
*/
GIT_EXTERN(int) git_repository_new(git_repository **out);
/**
* Reset all the internal state in a repository.
*
* This will free all the mapped memory and internal objects
* of the repository and leave it in a "blank" state.
*
* There's no need to call this function directly unless you're
* trying to aggressively cleanup the repo before its
* deallocation. `git_repository_free` already performs this operation
* before deallocation the repo.
*/
GIT_EXTERN(void) git_repository__cleanup(git_repository *repo);
/**
* Set the configuration file for this repository
*
......
......@@ -77,6 +77,9 @@ static void clear_cache(git_cache *cache)
{
git_cached_obj *evict = NULL;
if (kh_size(cache->map) == 0)
return;
kh_foreach_value(cache->map, evict, {
git_cached_obj_decref(evict);
});
......
......@@ -42,6 +42,7 @@ int git_cache_set_max_object_size(git_otype type, size_t size);
int git_cache_init(git_cache *cache);
void git_cache_free(git_cache *cache);
void git_cache_clear(git_cache *cache);
void *git_cache_store_raw(git_cache *cache, git_odb_object *entry);
void *git_cache_store_parsed(git_cache *cache, git_object *entry);
......
......@@ -86,19 +86,28 @@ static void set_index(git_repository *repo, git_index *index)
}
}
void git_repository_free(git_repository *repo)
void git_repository__cleanup(git_repository *repo)
{
if (repo == NULL)
return;
assert(repo);
git_cache_free(&repo->objects);
git_cache_clear(&repo->objects);
git_attr_cache_flush(repo);
git_submodule_config_free(repo);
set_config(repo, NULL);
set_index(repo, NULL);
set_odb(repo, NULL);
set_refdb(repo, NULL);
}
void git_repository_free(git_repository *repo)
{
if (repo == NULL)
return;
git_repository__cleanup(repo);
git_cache_free(&repo->objects);
git_submodule_config_free(repo);
git__free(repo->path_repository);
git__free(repo->workdir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment