summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2020-02-18 00:02:13 +0000
committerlhchavez <lhchavez@lhchavez.com>2021-08-27 04:12:16 -0700
commitea285904dcb1350d99703df86a5f38662935cbbc (patch)
treefaeda30d856e43a6939f4ca13f0f41774fa6b9d7 /src/odb.c
parent9d117e3857b447b47df38081d7f40f4b2226621b (diff)
downloadlibgit2-ea285904dcb1350d99703df86a5f38662935cbbc.tar.gz
midx: Introduce git_odb_write_multi_pack_index()
This change introduces git_odb_write_multi_pack_index(), which creates a `multi-pack-index` file from all the `.pack` files that have been loaded in the ODB. Fixes: #5399
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/odb.c b/src/odb.c
index e3a5381e6..7834e5f15 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1703,6 +1703,35 @@ int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_indexer_
return error;
}
+int git_odb_write_multi_pack_index(git_odb *db)
+{
+ size_t i, writes = 0;
+ int error = GIT_ERROR;
+
+ GIT_ASSERT_ARG(db);
+
+ for (i = 0; i < db->backends.length && error < 0; ++i) {
+ backend_internal *internal = git_vector_get(&db->backends, i);
+ git_odb_backend *b = internal->backend;
+
+ /* we don't write in alternates! */
+ if (internal->is_alternate)
+ continue;
+
+ if (b->writemidx != NULL) {
+ ++writes;
+ error = b->writemidx(b);
+ }
+ }
+
+ if (error == GIT_PASSTHROUGH)
+ error = 0;
+ if (error < 0 && !writes)
+ error = git_odb__error_unsupported_in_backend("write multi-pack-index");
+
+ return error;
+}
+
void *git_odb_backend_data_alloc(git_odb_backend *backend, size_t len)
{
GIT_UNUSED(backend);