summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-03-24 19:43:43 +0100
committerPatrick Steinhardt <ps@pks.im>2020-03-24 19:43:43 +0100
commit3ff71a888619335878820bca28285fee56fccfde (patch)
treefbcd04103850883cb954cf0211fc96ba3e111b1a
parent1ee3afb3138224cb3da9ac3727a802a2768dce4b (diff)
downloadlibgit2-pks/reftables-support.tar.gz
wire up reftablepks/reftables-support
-rw-r--r--include/git2/sys/refdb_backend.h4
-rw-r--r--src/refdb.c35
-rw-r--r--src/refdb_reftable.c2
3 files changed, 28 insertions, 13 deletions
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
index 8e22c4f02..0bdd2242c 100644
--- a/include/git2/sys/refdb_backend.h
+++ b/include/git2/sys/refdb_backend.h
@@ -235,6 +235,10 @@ GIT_EXTERN(int) git_refdb_backend_fs(
git_refdb_backend **backend_out,
git_repository *repo);
+GIT_EXTERN(int) git_refdb_backend_reftable(
+ git_refdb_backend **out,
+ git_repository *repository);
+
/**
* Sets the custom backend to an existing reference DB
*
diff --git a/src/refdb.c b/src/refdb.c
index fbbf5193c..82284b2de 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -35,27 +35,40 @@ int git_refdb_new(git_refdb **out, git_repository *repo)
int git_refdb_open(git_refdb **out, git_repository *repo)
{
+ git_buf refs = GIT_BUF_INIT;
+ git_refdb_backend *backend;
git_refdb *db;
- git_refdb_backend *dir;
+ int error;
assert(out && repo);
*out = NULL;
- if (git_refdb_new(&db, repo) < 0)
- return -1;
-
- /* Add the default (filesystem) backend */
- if (git_refdb_backend_fs(&dir, repo) < 0) {
- git_refdb_free(db);
- return -1;
+ if ((error = git_refdb_new(&db, repo)) < 0)
+ goto out;
+
+ if ((error = git_buf_joinpath(&refs, git_repository_path(repo), "refs")) < 0)
+ goto out;
+
+ /*
+ * Use filesystem-based backend in case ".git/refs" is a directory,
+ * otherwise use the reftable backend.
+ */
+ if (git_path_isfile(refs.ptr)) {
+ if ((error = git_refdb_backend_reftable(&backend, repo)) < 0)
+ goto out;
+ } else {
+ if ((error = git_refdb_backend_fs(&backend, repo)) < 0)
+ goto out;
}
db->repo = repo;
- db->backend = dir;
-
+ db->backend = backend;
*out = db;
- return 0;
+out:
+ if (error)
+ git_refdb_free(db);
+ return error;
}
static void refdb_free_backend(git_refdb *db)
diff --git a/src/refdb_reftable.c b/src/refdb_reftable.c
index 601f3bb9e..74d0462b4 100644
--- a/src/refdb_reftable.c
+++ b/src/refdb_reftable.c
@@ -5,8 +5,6 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "refdb_fs.h"
-
#include "git2/sys/refdb_backend.h"
#include "git2/sys/refs.h"
#include "wildmatch.h"