summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-07-26 16:27:54 -0400
committerGitHub <noreply@github.com>2021-07-26 16:27:54 -0400
commit2370e4910262f941a3bb0f70ce05ff7a90679fe1 (patch)
tree1d3b183d7b14ab3bf4a2d3b11ead833ef073a825 /src/odb.c
parent43b5075df4c543fc8801ed4b829702d7f9f2c0ad (diff)
parent25b75cd9bc01896a2b74c748ceef7110ea1b165f (diff)
downloadlibgit2-2370e4910262f941a3bb0f70ce05ff7a90679fe1.tar.gz
Merge pull request #5765 from lhchavez/cgraph-revwalks
commit-graph: Use the commit-graph in revwalks
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/odb.c b/src/odb.c
index 7625ce6e3..05bdaf6a3 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -621,6 +621,16 @@ int git_odb__add_default_backends(
add_backend_internal(db, packed, GIT_PACKED_PRIORITY, as_alternates, inode) < 0)
return -1;
+ if (git_mutex_lock(&db->lock) < 0) {
+ git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock");
+ return -1;
+ }
+ if (!db->cgraph && git_commit_graph_new(&db->cgraph, objects_dir, false) < 0) {
+ git_mutex_unlock(&db->lock);
+ return -1;
+ }
+ git_mutex_unlock(&db->lock);
+
return load_alternates(db, objects_dir, alternate_depth);
}
@@ -682,6 +692,23 @@ int git_odb_add_disk_alternate(git_odb *odb, const char *path)
return git_odb__add_default_backends(odb, path, true, 0);
}
+int git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph)
+{
+ int error = 0;
+
+ GIT_ASSERT_ARG(odb);
+
+ if ((error = git_mutex_lock(&odb->lock)) < 0) {
+ git_error_set(GIT_ERROR_ODB, "failed to acquire the db lock");
+ return error;
+ }
+ git_commit_graph_free(odb->cgraph);
+ odb->cgraph = cgraph;
+ git_mutex_unlock(&odb->lock);
+
+ return error;
+}
+
int git_odb_open(git_odb **out, const char *objects_dir)
{
git_odb *db;
@@ -741,6 +768,7 @@ static void odb_free(git_odb *db)
if (locked)
git_mutex_unlock(&db->lock);
+ git_commit_graph_free(db->cgraph);
git_vector_free(&db->backends);
git_cache_dispose(&db->own_cache);
git_mutex_free(&db->lock);
@@ -785,6 +813,29 @@ static int odb_exists_1(
return (int)found;
}
+int git_odb__get_commit_graph_file(git_commit_graph_file **out, git_odb *db)
+{
+ int error = 0;
+ git_commit_graph_file *result = NULL;
+
+ if ((error = git_mutex_lock(&db->lock)) < 0) {
+ git_error_set(GIT_ERROR_ODB, "failed to acquire the db lock");
+ return error;
+ }
+ if (!db->cgraph) {
+ error = GIT_ENOTFOUND;
+ goto done;
+ }
+ error = git_commit_graph_get_file(&result, db->cgraph);
+ if (error)
+ goto done;
+ *out = result;
+
+done:
+ git_mutex_unlock(&db->lock);
+ return error;
+}
+
static int odb_freshen_1(
git_odb *db,
const git_oid *id,
@@ -1694,6 +1745,8 @@ int git_odb_refresh(struct git_odb *db)
}
}
}
+ if (db->cgraph)
+ git_commit_graph_refresh(db->cgraph);
git_mutex_unlock(&db->lock);
return 0;