Commit 87d3acf4 by Vicent Marti

Finish the References API

The following methods have been implemented:

	git_reference_packall
	git_reference_rename
	git_reference_delete

The library now has full support for packed references, including
partial and total writing. Internal documentation has been updated with
the details.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 17cdf252
...@@ -187,6 +187,24 @@ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name); ...@@ -187,6 +187,24 @@ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name);
*/ */
GIT_EXTERN(int) git_reference_delete(git_reference *ref); GIT_EXTERN(int) git_reference_delete(git_reference *ref);
/**
* Pack all the loose references in the repository
*
* This method will load into the cache all the loose
* references on the repository and update the
* `packed-refs` file with them.
*
* Once the `packed-refs` file has been written properly,
* the loose references will be removed from disk.
*
* WARNING: calling this method may invalidate any existing
* references previously loaded on the cache.
*
* @param repo Repository where the loose refs will be packed
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_reference_packall(git_repository *repo);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -23,10 +23,8 @@ struct git_reference { ...@@ -23,10 +23,8 @@ struct git_reference {
}; };
typedef struct { typedef struct {
git_hashtable *packed_refs; git_hashtable *packfile;
git_hashtable *loose_refs; git_hashtable *loose_cache;
unsigned pack_loaded:1;
} git_refcache; } git_refcache;
......
...@@ -296,6 +296,13 @@ BEGIN_TEST("createref", create_new_object_id_ref) ...@@ -296,6 +296,13 @@ BEGIN_TEST("createref", create_new_object_id_ref)
must_pass(gitfo_unlink(ref_path)); /* TODO: replace with git_reference_delete() when available */ must_pass(gitfo_unlink(ref_path)); /* TODO: replace with git_reference_delete() when available */
END_TEST END_TEST
BEGIN_TEST("packrefs", create_packfile)
git_repository *repo;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_reference_packall(repo));
git_repository_free(repo);
END_TEST
static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname) static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname)
{ {
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
...@@ -494,6 +501,7 @@ git_testsuite *libgit2_suite_refs(void) ...@@ -494,6 +501,7 @@ git_testsuite *libgit2_suite_refs(void)
ADD_TEST(suite, "normalizeref", normalize_object_id_ref); ADD_TEST(suite, "normalizeref", normalize_object_id_ref);
ADD_TEST(suite, "normalizeref", normalize_symbolic_ref); ADD_TEST(suite, "normalizeref", normalize_symbolic_ref);
ADD_TEST(suite, "normalizeref", jgit_tests); ADD_TEST(suite, "normalizeref", jgit_tests);
//ADD_TEST(suite, "packrefs", create_packfile);
return suite; return suite;
} }
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