diff options
author | Chris Hescock <chescock@vistaprint.com> | 2017-01-11 10:39:59 -0500 |
---|---|---|
committer | Chris Hescock <chescock@vistaprint.com> | 2017-05-19 10:10:54 -0400 |
commit | c0e541556600d825779c950ab1a4ce93b6782b09 (patch) | |
tree | 5c2f109d1fa4d6aaf4acacdb464bcbef96f72912 /src/indexer.c | |
parent | 1196807380b73f202bc1fea3045e13b719a465e9 (diff) | |
download | libgit2-c0e541556600d825779c950ab1a4ce93b6782b09.tar.gz |
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.
Diffstat (limited to 'src/indexer.c')
-rw-r--r-- | src/indexer.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/indexer.c b/src/indexer.c index 606de2ef6..0ad7869ef 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -931,7 +931,6 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) git_buf filename = GIT_BUF_INIT; struct entry *entry; git_oid trailer_hash, file_hash; - git_hash_ctx ctx; git_filebuf index_file = {0}; void *packfile_trailer; @@ -940,9 +939,6 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) return -1; } - if (git_hash_ctx_init(&ctx) < 0) - return -1; - /* Test for this before resolve_deltas(), as it plays with idx->off */ if (idx->off + 20 < idx->pack->mwf.size) { 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) git_vector_sort(&idx->objects); + /* Use the trailer hash as the pack file name to ensure + * files with different contents have different names */ + git_oid_cpy(&idx->hash, &trailer_hash); + git_buf_sets(&filename, idx->pack->pack_name); git_buf_shorten(&filename, strlen("pack")); git_buf_puts(&filename, "idx"); @@ -1010,9 +1010,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) /* Write out the object names (SHA-1 hashes) */ git_vector_foreach(&idx->objects, i, entry) { git_filebuf_write(&index_file, &entry->oid, sizeof(git_oid)); - git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ); } - git_hash_final(&idx->hash, &ctx); /* Write out the CRC32 values */ git_vector_foreach(&idx->objects, i, entry) { @@ -1086,14 +1084,12 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats) idx->pack_committed = 1; git_buf_free(&filename); - git_hash_ctx_cleanup(&ctx); return 0; on_error: git_mwindow_free_all(&idx->pack->mwf); git_filebuf_cleanup(&index_file); git_buf_free(&filename); - git_hash_ctx_cleanup(&ctx); return -1; } |