Skip to content

Commit c0e5415

Browse files
committed
indexer: name pack files after trailer hash
Upstream git.git has changed the way how packfiles are named. Previously, they were using a hash of the contained object's OIDs, which has then been changed to use the hash of the complete packfile instead. See 1190a1acf (pack-objects: name pack files after trailer hash, 2013-12-05) in the git.git repository for more information on this change. This commit changes our logic to match the behavior of core git.
1 parent 1196807 commit c0e5415

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/indexer.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,6 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
931931
git_buf filename = GIT_BUF_INIT;
932932
struct entry *entry;
933933
git_oid trailer_hash, file_hash;
934-
git_hash_ctx ctx;
935934
git_filebuf index_file = {0};
936935
void *packfile_trailer;
937936

@@ -940,9 +939,6 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
940939
return -1;
941940
}
942941

943-
if (git_hash_ctx_init(&ctx) < 0)
944-
return -1;
945-
946942
/* Test for this before resolve_deltas(), as it plays with idx->off */
947943
if (idx->off + 20 < idx->pack->mwf.size) {
948944
giterr_set(GITERR_INDEXER, "unexpected data at the end of the pack");
@@ -986,6 +982,10 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
986982

987983
git_vector_sort(&idx->objects);
988984

985+
/* Use the trailer hash as the pack file name to ensure
986+
* files with different contents have different names */
987+
git_oid_cpy(&idx->hash, &trailer_hash);
988+
989989
git_buf_sets(&filename, idx->pack->pack_name);
990990
git_buf_shorten(&filename, strlen("pack"));
991991
git_buf_puts(&filename, "idx");
@@ -1010,9 +1010,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
10101010
/* Write out the object names (SHA-1 hashes) */
10111011
git_vector_foreach(&idx->objects, i, entry) {
10121012
git_filebuf_write(&index_file, &entry->oid, sizeof(git_oid));
1013-
git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ);
10141013
}
1015-
git_hash_final(&idx->hash, &ctx);
10161014

10171015
/* Write out the CRC32 values */
10181016
git_vector_foreach(&idx->objects, i, entry) {
@@ -1086,14 +1084,12 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
10861084
idx->pack_committed = 1;
10871085

10881086
git_buf_free(&filename);
1089-
git_hash_ctx_cleanup(&ctx);
10901087
return 0;
10911088

10921089
on_error:
10931090
git_mwindow_free_all(&idx->pack->mwf);
10941091
git_filebuf_cleanup(&index_file);
10951092
git_buf_free(&filename);
1096-
git_hash_ctx_cleanup(&ctx);
10971093
return -1;
10981094
}
10991095

tests/pack/indexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void test_pack_indexer__fix_thin(void)
8585
cl_assert_equal_i(stats.indexed_objects, 2);
8686
cl_assert_equal_i(stats.local_objects, 1);
8787

88-
git_oid_fromstr(&should_id, "11f0f69b334728fdd8bc86b80499f22f29d85b15");
88+
git_oid_fromstr(&should_id, "fefdb2d740a3a6b6c03a0c7d6ce431c6d5810e13");
8989
cl_assert_equal_oid(&should_id, git_indexer_hash(idx));
9090

9191
git_indexer_free(idx);
@@ -102,7 +102,7 @@ void test_pack_indexer__fix_thin(void)
102102
int fd;
103103
ssize_t read;
104104
struct stat st;
105-
const char *name = "pack-11f0f69b334728fdd8bc86b80499f22f29d85b15.pack";
105+
const char *name = "pack-fefdb2d740a3a6b6c03a0c7d6ce431c6d5810e13.pack";
106106

107107
fd = p_open(name, O_RDONLY);
108108
cl_assert(fd != -1);

tests/pack/packbuilder.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void test_pack_packbuilder__create_pack(void)
113113
* $ cd tests/resources/testrepo.git
114114
* $ git rev-list --objects HEAD | \
115115
* git pack-objects -q --no-reuse-delta --threads=1 pack
116-
* $ sha1sum git-80e61eb315239ef3c53033e37fee43b744d57122.pack
116+
* $ sha1sum pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack
117117
* 5d410bdf97cf896f9007681b92868471d636954b
118118
*
119119
*/
@@ -142,7 +142,7 @@ void test_pack_packbuilder__get_hash(void)
142142
git_packbuilder_write(_packbuilder, ".", 0, NULL, NULL);
143143
git_oid_fmt(hex, git_packbuilder_hash(_packbuilder));
144144

145-
cl_assert_equal_s(hex, "80e61eb315239ef3c53033e37fee43b744d57122");
145+
cl_assert_equal_s(hex, "7f5fa362c664d68ba7221259be1cbd187434b2f0");
146146
}
147147

148148
static void test_write_pack_permission(mode_t given, mode_t expected)
@@ -166,10 +166,10 @@ static void test_write_pack_permission(mode_t given, mode_t expected)
166166
mask = p_umask(0);
167167
p_umask(mask);
168168

169-
cl_git_pass(p_stat("pack-80e61eb315239ef3c53033e37fee43b744d57122.idx", &statbuf));
169+
cl_git_pass(p_stat("pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx", &statbuf));
170170
cl_assert_equal_i(statbuf.st_mode & os_mask, (expected & ~mask) & os_mask);
171171

172-
cl_git_pass(p_stat("pack-80e61eb315239ef3c53033e37fee43b744d57122.pack", &statbuf));
172+
cl_git_pass(p_stat("pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack", &statbuf));
173173
cl_assert_equal_i(statbuf.st_mode & os_mask, (expected & ~mask) & os_mask);
174174
}
175175

0 commit comments

Comments
 (0)