Commit cc2447da by Edward Thomson

Add git_packbuilder_hash to query pack filename

parent e87d9d3d
...@@ -130,6 +130,16 @@ GIT_EXTERN(int) git_packbuilder_write( ...@@ -130,6 +130,16 @@ GIT_EXTERN(int) git_packbuilder_write(
git_transfer_progress_callback progress_cb, git_transfer_progress_callback progress_cb,
void *progress_cb_payload); void *progress_cb_payload);
/**
* Get the packfile's hash
*
* A packfile's name is derived from the sorted hashing of all object
* names. This is only correct after the packfile has been written.
*
* @param pb The packbuilder object
*/
GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb);
typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload); typedef int (*git_packbuilder_foreach_cb)(void *buf, size_t size, void *payload);
/** /**
* Create the new pack and pass each object to the callback * Create the new pack and pass each object to the callback
......
...@@ -560,6 +560,7 @@ static int write_pack(git_packbuilder *pb, ...@@ -560,6 +560,7 @@ static int write_pack(git_packbuilder *pb,
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
enum write_one_status status; enum write_one_status status;
struct git_pack_header ph; struct git_pack_header ph;
git_oid entry_oid;
unsigned int i = 0; unsigned int i = 0;
int error = 0; int error = 0;
...@@ -596,10 +597,10 @@ static int write_pack(git_packbuilder *pb, ...@@ -596,10 +597,10 @@ static int write_pack(git_packbuilder *pb,
} while (pb->nr_remaining && i < pb->nr_objects); } while (pb->nr_remaining && i < pb->nr_objects);
if ((error = git_hash_final(&pb->pack_oid, &pb->ctx)) < 0) if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0)
goto done; goto done;
error = cb(pb->pack_oid.id, GIT_OID_RAWSZ, data); error = cb(entry_oid.id, GIT_OID_RAWSZ, data);
done: done:
git__free(write_order); git__free(write_order);
...@@ -1269,12 +1270,19 @@ int git_packbuilder_write( ...@@ -1269,12 +1270,19 @@ int git_packbuilder_write(
return -1; return -1;
} }
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
git_indexer_free(indexer); git_indexer_free(indexer);
return 0; return 0;
} }
#undef PREPARE_PACK #undef PREPARE_PACK
const git_oid *git_packbuilder_hash(git_packbuilder *pb)
{
return &pb->pack_oid;
}
static int cb_tree_walk(const char *root, const git_tree_entry *entry, void *payload) static int cb_tree_walk(const char *root, const git_tree_entry *entry, void *payload)
{ {
struct tree_walk_context *ctx = payload; struct tree_walk_context *ctx = payload;
......
...@@ -128,6 +128,18 @@ void test_pack_packbuilder__create_pack(void) ...@@ -128,6 +128,18 @@ void test_pack_packbuilder__create_pack(void)
cl_assert_equal_s(hex, "5d410bdf97cf896f9007681b92868471d636954b"); cl_assert_equal_s(hex, "5d410bdf97cf896f9007681b92868471d636954b");
} }
void test_pack_packbuilder__get_hash(void)
{
char hex[41]; hex[40] = '\0';
seed_packbuilder();
git_packbuilder_write(_packbuilder, ".", NULL, NULL);
git_oid_fmt(hex, git_packbuilder_hash(_packbuilder));
cl_assert_equal_s(hex, "80e61eb315239ef3c53033e37fee43b744d57122");
}
static git_transfer_progress stats; static git_transfer_progress stats;
static int foreach_cb(void *buf, size_t len, void *payload) static int foreach_cb(void *buf, size_t len, void *payload)
{ {
......
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