diff options
author | Vicent Martà <vicent@github.com> | 2012-07-31 10:16:21 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-07-31 10:16:21 -0700 |
commit | bfb59164687408bcc61b9b75bb391770fae7d9c2 (patch) | |
tree | f688fc7c41b7d9c16f7243753db2b5a27f04af90 /src/odb_pack.c | |
parent | 577cd8aec1b112fc099035817cdb69ec79edc569 (diff) | |
parent | 6782245e51af13427cce7eb4dd4d3a4f202c9150 (diff) | |
download | libgit2-bfb59164687408bcc61b9b75bb391770fae7d9c2.tar.gz |
Merge pull request #833 from carlosmn/odb-one
odb: allow creating an ODB backend from a packfile index
Diffstat (limited to 'src/odb_pack.c')
-rw-r--r-- | src/odb_pack.c | 35 |
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; |