diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-22 17:34:36 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-23 09:48:20 -0500 |
commit | 69ca594bafd438fea419b1ebe757a9d13da4d254 (patch) | |
tree | b7b760bb90311ee4cd511d697d54c1ff8a1d97a8 | |
parent | 55eb096b93d4e658bfc0d19270b56f00dff9ec0d (diff) | |
download | libgit2-69ca594bafd438fea419b1ebe757a9d13da4d254.tar.gz |
packbuilder: use the packfile name instead of hashethomson/oid_cleanups
Deprecate the `git_packfile_hash` function. Callers should use the new
`git_packfile_name` function which provides a unique packfile name.
-rw-r--r-- | fuzzers/packfile_fuzzer.c | 4 | ||||
-rw-r--r-- | include/git2/pack.h | 28 | ||||
-rw-r--r-- | src/pack-objects.c | 14 | ||||
-rw-r--r-- | src/pack-objects.h | 3 | ||||
-rw-r--r-- | tests/checkout/crlf.c | 4 | ||||
-rw-r--r-- | tests/pack/packbuilder.c | 8 |
6 files changed, 44 insertions, 17 deletions
diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index 8667cb9c5..6002fa1de 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -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)); diff --git a/include/git2/pack.h b/include/git2/pack.h index 253a860cd..0f6bd2ab9 100644 --- a/include/git2/pack.h +++ b/include/git2/pack.h @@ -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 diff --git a/src/pack-objects.c b/src/pack-objects.c index e5fc625a4..35c1d55db 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -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); } diff --git a/src/pack-objects.h b/src/pack-objects.h index cefee40ef..53c9f5d45 100644 --- a/src/pack-objects.h +++ b/src/pack-objects.h @@ -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; diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c index 8fd16a004..21f8a852a 100644 --- a/tests/checkout/crlf.c +++ b/tests/checkout/crlf.c @@ -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)); diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c index 73bc6674b..f23579817 100644 --- a/tests/pack/packbuilder.c +++ b/tests/pack/packbuilder.c @@ -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) |