Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2012-07-21 18:23:49 +0400
committerCarlos Martín Nieto <cmn@elego.de>2012-07-21 18:23:49 +0400
commit507523c32f71056a106f85712fe2086fdb94fbd0 (patch)
treed369f3f39a14fa48a06a24a632b1f1916b93670d /src/odb_pack.c
parent71d273583755c0a2b7f5d608f017f4586add51e4 (diff)
odb: allow creating an ODB backend from a packfile index
git_odb_backend_one_packfile() allows us to create an ODB backend out of an .idx file.
Diffstat (limited to 'src/odb_pack.c')
-rw-r--r--src/odb_pack.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 4b860e864..0f34ebdf8 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -458,6 +458,41 @@ static void pack_backend__free(git_odb_backend *_backend)
git__free(backend);
}
+int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
+{
+ struct pack_backend *backend = NULL;
+ struct git_pack_file *packfile = NULL;
+
+ if (git_packfile_check(&packfile, idx) < 0)
+ return -1;
+
+ backend = git__calloc(1, sizeof(struct pack_backend));
+ GITERR_CHECK_ALLOC(backend);
+
+ if (git_vector_init(&backend->packs, 1, NULL) < 0)
+ goto on_error;
+
+ if (git_vector_insert(&backend->packs, packfile) < 0)
+ goto on_error;
+
+ backend->parent.read = &pack_backend__read;
+ backend->parent.read_prefix = &pack_backend__read_prefix;
+ backend->parent.read_header = NULL;
+ backend->parent.exists = &pack_backend__exists;
+ backend->parent.foreach = &pack_backend__foreach;
+ backend->parent.free = &pack_backend__free;
+
+ *backend_out = (git_odb_backend *)backend;
+
+ return 0;
+
+on_error:
+ git_vector_free(&backend->packs);
+ git__free(backend);
+ git__free(packfile);
+ return -1;
+}
+
int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
{
struct pack_backend *backend = NULL;