Commit e61fac75 by Edward Thomson

packbuilder: write sha256 trailers when expected

parent a850a421
...@@ -127,6 +127,7 @@ out: ...@@ -127,6 +127,7 @@ out:
int git_packbuilder_new(git_packbuilder **out, git_repository *repo) int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
{ {
git_hash_algorithm_t hash_algorithm;
git_packbuilder *pb; git_packbuilder *pb;
*out = NULL; *out = NULL;
...@@ -134,6 +135,11 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo) ...@@ -134,6 +135,11 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
pb = git__calloc(1, sizeof(*pb)); pb = git__calloc(1, sizeof(*pb));
GIT_ERROR_CHECK_ALLOC(pb); GIT_ERROR_CHECK_ALLOC(pb);
pb->oid_type = repo->oid_type;
hash_algorithm = git_oid_algorithm(pb->oid_type);
GIT_ASSERT(hash_algorithm);
if (git_oidmap_new(&pb->object_ix) < 0 || if (git_oidmap_new(&pb->object_ix) < 0 ||
git_oidmap_new(&pb->walk_objects) < 0 || git_oidmap_new(&pb->walk_objects) < 0 ||
git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0) git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0)
...@@ -142,7 +148,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo) ...@@ -142,7 +148,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
pb->repo = repo; pb->repo = repo;
pb->nr_threads = 1; /* do not spawn any thread by default */ pb->nr_threads = 1; /* do not spawn any thread by default */
if (git_hash_ctx_init(&pb->ctx, GIT_HASH_ALGORITHM_SHA1) < 0 || if (git_hash_ctx_init(&pb->ctx, hash_algorithm) < 0 ||
git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 || git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
git_repository_odb(&pb->odb, repo) < 0 || git_repository_odb(&pb->odb, repo) < 0 ||
packbuilder_config(pb) < 0) packbuilder_config(pb) < 0)
...@@ -315,9 +321,11 @@ static int write_object( ...@@ -315,9 +321,11 @@ static int write_object(
git_object_t type; git_object_t type;
unsigned char hdr[10], *zbuf = NULL; unsigned char hdr[10], *zbuf = NULL;
void *data = NULL; void *data = NULL;
size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len; size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len, oid_size;
int error; int error;
oid_size = git_oid_size(pb->oid_type);
/* /*
* If we have a delta base, let's use the delta to save space. * If we have a delta base, let's use the delta to save space.
* Otherwise load the whole object. 'data' ends up pointing to * Otherwise load the whole object. 'data' ends up pointing to
...@@ -347,8 +355,8 @@ static int write_object( ...@@ -347,8 +355,8 @@ static int write_object(
goto done; goto done;
if (type == GIT_OBJECT_REF_DELTA) { if (type == GIT_OBJECT_REF_DELTA) {
if ((error = write_cb(po->delta->id.id, GIT_OID_SHA1_SIZE, cb_data)) < 0 || if ((error = write_cb(po->delta->id.id, oid_size, cb_data)) < 0 ||
(error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_SHA1_SIZE)) < 0) (error = git_hash_update(&pb->ctx, po->delta->id.id, oid_size)) < 0)
goto done; goto done;
} }
...@@ -668,7 +676,7 @@ static int write_pack(git_packbuilder *pb, ...@@ -668,7 +676,7 @@ static int write_pack(git_packbuilder *pb,
if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0) if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0)
goto done; goto done;
error = write_cb(entry_oid.id, GIT_OID_SHA1_SIZE, cb_data); error = write_cb(entry_oid.id, git_oid_size(pb->oid_type), cb_data);
done: done:
/* if callback cancelled writing, we must still free delta_data */ /* if callback cancelled writing, we must still free delta_data */
......
...@@ -56,6 +56,8 @@ struct git_packbuilder { ...@@ -56,6 +56,8 @@ struct git_packbuilder {
git_repository *repo; /* associated repository */ git_repository *repo; /* associated repository */
git_odb *odb; /* associated object database */ git_odb *odb; /* associated object database */
git_oid_t oid_type;
git_hash_ctx ctx; git_hash_ctx ctx;
git_zstream zstream; git_zstream zstream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment