Commit 70d9bfa4 by Edward Thomson

packbuilder: use the packfile name instead of hash

Deprecate the `git_packfile_hash` function.  Callers should use the new
`git_packfile_name` function which provides a unique packfile name.
parent d2458af7
......@@ -101,13 +101,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup;
if (git_str_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
if (git_str_printf(&path, "pack-%s.idx", git_indexer_name(indexer)) < 0)
goto cleanup;
p_unlink(git_str_cstr(&path));
git_str_clear(&path);
if (git_str_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0)
if (git_str_printf(&path, "pack-%s.pack", git_indexer_name(indexer)) < 0)
goto cleanup;
p_unlink(git_str_cstr(&path));
......
......@@ -170,16 +170,30 @@ GIT_EXTERN(int) git_packbuilder_write(
git_indexer_progress_cb progress_cb,
void *progress_cb_payload);
#ifndef GIT_DEPRECATE_HARD
/**
* 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
* 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.
*
* @deprecated use git_packbuilder_name
* @param pb The packbuilder object
* @return 0 or an error code
*/
*/
GIT_EXTERN(const git_oid *) git_packbuilder_hash(git_packbuilder *pb);
#endif
/**
* Get the unique name for the resulting packfile.
*
* The packfile's name is derived from the packfile's content.
* This is only correct after the packfile has been written.
*
* @param pb the packbuilder instance
* @return a NUL terminated string for the packfile name
*/
GIT_EXTERN(const char *) git_packbuilder_name(git_packbuilder *pb);
/**
* Callback used to iterate over packed objects
......
......@@ -1422,7 +1422,12 @@ int git_packbuilder_write(
if ((error = git_indexer_commit(indexer, &stats)) < 0)
goto cleanup;
#ifndef GIT_DEPRECATE_HARD
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
#endif
pb->pack_name = git__strdup(git_indexer_name(indexer));
GIT_ERROR_CHECK_ALLOC(pb->pack_name);
cleanup:
git_indexer_free(indexer);
......@@ -1432,10 +1437,17 @@ cleanup:
#undef PREPARE_PACK
#ifndef GIT_DEPRECATE_HARD
const git_oid *git_packbuilder_hash(git_packbuilder *pb)
{
return &pb->pack_oid;
}
#endif
const char *git_packbuilder_name(git_packbuilder *pb)
{
return pb->pack_name;
}
static int cb_tree_walk(
......@@ -1803,5 +1815,7 @@ void git_packbuilder_free(git_packbuilder *pb)
git_hash_ctx_cleanup(&pb->ctx);
git_zstream_free(&pb->zstream);
git__free(pb->pack_name);
git__free(pb);
}
......@@ -73,7 +73,10 @@ struct git_packbuilder {
git_oidmap *walk_objects;
git_pool object_pool;
#ifndef GIT_DEPRECATE_HARD
git_oid pack_oid; /* hash of written pack */
#endif
char *pack_name; /* name of written pack */
/* synchronization objects */
git_mutex cache_mutex;
......
......@@ -239,10 +239,10 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
cl_repo_set_bool(g_repo, "core.autocrlf", false);
git_repository_index(&index, g_repo);
cl_git_pass(git_repository_index(&index, g_repo));
tick_index(index);
git_checkout_head(g_repo, &opts);
cl_git_pass(git_checkout_head(g_repo, &opts));
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
......
......@@ -138,16 +138,12 @@ void test_pack_packbuilder__create_pack(void)
cl_assert_equal_s(hex, "5d410bdf97cf896f9007681b92868471d636954b");
}
void test_pack_packbuilder__get_hash(void)
void test_pack_packbuilder__get_name(void)
{
char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
seed_packbuilder();
cl_git_pass(git_packbuilder_write(_packbuilder, ".", 0, NULL, NULL));
git_oid_fmt(hex, git_packbuilder_hash(_packbuilder));
cl_assert_equal_s(hex, "7f5fa362c664d68ba7221259be1cbd187434b2f0");
cl_assert_equal_s("7f5fa362c664d68ba7221259be1cbd187434b2f0", git_packbuilder_name(_packbuilder));
}
void test_pack_packbuilder__write_default_path(void)
......
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