summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-10-24 13:54:42 +0200
committerPatrick Steinhardt <ps@pks.im>2020-06-27 14:33:58 +0200
commit79af067665c37b6dc0b31edb35596c362b0cd9a0 (patch)
treebd42cc75226476bcb5541bda7a79d7b22b91a2e4
parenta4803c3c5ae2d3e038d56fcfe52215bc2364521a (diff)
downloadlibgit2-79af067665c37b6dc0b31edb35596c362b0cd9a0.tar.gz
repository: do not expose grafting mechanism
Currently, we expose the function `git_repository_shallow_roots` to get all grafted roots of the repository. This already paints us into a corner, though, as we certainly need to experiment with some functionality of the grafting mechanism before we can happily expose some of its functionality. Most importantly, we need to get right when to refresh grafts and when not. Thus, this commit removes the public function with no public replacement. We should first try and see what usecases people come up with to e.g. expose the `git_grafts` mechanism directly in the future or do something different altogether. Instead, we provide an internal interface to get weak pointers to the grafting structs part of the repository itself.
-rw-r--r--include/git2/repository.h12
-rw-r--r--src/repository.c33
-rw-r--r--src/repository.h2
-rw-r--r--tests/grafts/shallow.c53
4 files changed, 43 insertions, 57 deletions
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 59e938710..aa81e3843 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -876,18 +876,6 @@ GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
/**
- * Determine the shallow roots of the repository
- *
- * The resulting OID array needs to be free'd by calling
- * `git_oidarray_free`.
- *
- * @param out An array of shallow oids.
- * @param repo The repository
- * @return 0 on success, an error otherwise.
- */
-GIT_EXTERN(int) git_repository_shallow_roots(git_oidarray *out, git_repository *repo);
-
-/**
* Retrieve the configured identity to use for reflogs
*
* The memory is owned by the repository and must not be freed by the
diff --git a/src/repository.c b/src/repository.c
index 730f19c20..bc5ee6ac0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1263,6 +1263,20 @@ int git_repository_set_index(git_repository *repo, git_index *index)
return 0;
}
+int git_repository_grafts__weakptr(git_grafts **out, git_repository *repo)
+{
+ assert(out && repo && repo->shallow_grafts);
+ *out = repo->grafts;
+ return 0;
+}
+
+int git_repository_shallow_grafts__weakptr(git_grafts **out, git_repository *repo)
+{
+ assert(out && repo && repo->shallow_grafts);
+ *out = repo->shallow_grafts;
+ return 0;
+}
+
int git_repository_set_namespace(git_repository *repo, const char *namespace)
{
git__free(repo->namespace);
@@ -2923,25 +2937,6 @@ int git_repository_state_cleanup(git_repository *repo)
return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
}
-int git_repository_shallow_roots(git_oidarray *out, git_repository *repo)
-{
- git_buf path = GIT_BUF_INIT, contents = GIT_BUF_INIT;
- int error;
-
- assert(out && repo);
-
- memset(out, 0, sizeof(*out));
-
- if ((error = git_grafts_refresh(repo->shallow_grafts)) < 0 ||
- (error = git_grafts_get_oids(out, repo->shallow_grafts)) < 0)
- goto error;
-
-error:
- git_buf_dispose(&path);
- git_buf_dispose(&contents);
- return error;
-}
-
int git_repository_is_shallow(git_repository *repo)
{
git_buf path = GIT_BUF_INIT;
diff --git a/src/repository.h b/src/repository.h
index 81f2bc101..5922bf02a 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -211,6 +211,8 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo);
int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
int git_repository_index__weakptr(git_index **out, git_repository *repo);
+int git_repository_grafts__weakptr(git_grafts **out, git_repository *repo);
+int git_repository_shallow_grafts__weakptr(git_grafts **out, git_repository *repo);
/*
* Configuration map cache
diff --git a/tests/grafts/shallow.c b/tests/grafts/shallow.c
index fc74de438..8fe3421f2 100644
--- a/tests/grafts/shallow.c
+++ b/tests/grafts/shallow.c
@@ -1,5 +1,8 @@
#include "clar_libgit2.h"
+
#include "futils.h"
+#include "grafts.h"
+#include "repository.h"
static git_repository *g_repo;
static git_oid g_shallow_oid;
@@ -42,61 +45,59 @@ void test_grafts_shallow__clears_errors(void)
void test_grafts_shallow__shallow_oids(void)
{
- git_oidarray oids;
- g_repo = cl_git_sandbox_init("shallow.git");
+ git_commit_graft *graft;
+ git_grafts *grafts;
- cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
- cl_assert_equal_i(1, oids.count);
- cl_assert_equal_oid(&g_shallow_oid, &oids.ids[0]);
+ g_repo = cl_git_sandbox_init("shallow.git");
- git_oidarray_free(&oids);
+ cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo));
+ cl_assert_equal_i(1, git_grafts_size(grafts));
+ cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid));
}
void test_grafts_shallow__cache_clearing(void)
{
- git_oidarray oids;
+ git_commit_graft *graft;
+ git_grafts *grafts;
git_oid tmp_oid;
cl_git_pass(git_oid_fromstr(&tmp_oid, "0000000000000000000000000000000000000000"));
g_repo = cl_git_sandbox_init("shallow.git");
+ cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo));
- cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
- cl_assert_equal_i(1, oids.count);
- cl_assert_equal_oid(&g_shallow_oid, &oids.ids[0]);
- git_oidarray_free(&oids);
+ cl_assert_equal_i(1, git_grafts_size(grafts));
+ cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid));
cl_git_mkfile("shallow.git/shallow",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644\n"
"0000000000000000000000000000000000000000\n"
);
- cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
- cl_assert_equal_i(2, oids.count);
- cl_assert((git_oid_equal(&g_shallow_oid, &oids.ids[0]) &&
- git_oid_equal(&tmp_oid, &oids.ids[1])) ||
- (git_oid_equal(&g_shallow_oid, &oids.ids[1]) &&
- git_oid_equal(&tmp_oid, &oids.ids[0])));
- git_oidarray_free(&oids);
+ cl_git_pass(git_grafts_refresh(grafts));
+ cl_assert_equal_i(2, git_grafts_size(grafts));
+ cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid));
+ cl_git_pass(git_grafts_get(&graft, grafts, &tmp_oid));
cl_git_pass(p_unlink("shallow.git/shallow"));
- cl_git_pass(git_repository_shallow_roots(&oids, g_repo));
- cl_assert_equal_i(0, oids.count);
- git_oidarray_free(&oids);
+ cl_git_pass(git_grafts_refresh(grafts));
+ cl_assert_equal_i(0, git_grafts_size(grafts));
}
void test_grafts_shallow__errors_on_borked(void)
{
- git_oidarray oids;
+ git_grafts *grafts;
g_repo = cl_git_sandbox_init("shallow.git");
cl_git_mkfile("shallow.git/shallow", "lolno");
-
- cl_git_fail_with(-1, git_repository_shallow_roots(&oids, g_repo));
+ cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo));
+ cl_git_fail(git_grafts_refresh(grafts));
+ cl_assert_equal_i(0, git_grafts_size(grafts));
cl_git_mkfile("shallow.git/shallow", "lolno\n");
-
- cl_git_fail_with(-1, git_repository_shallow_roots(&oids, g_repo));
+ cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo));
+ cl_git_fail(git_grafts_refresh(grafts));
+ cl_assert_equal_i(0, git_grafts_size(grafts));
}
void test_grafts_shallow__revwalk_behavior(void)