summaryrefslogtreecommitdiff
path: root/src/refdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/refdb.c')
-rw-r--r--src/refdb.c35
1 files changed, 24 insertions, 11 deletions
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)