diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2017-06-11 10:37:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-11 10:37:46 +0100 |
| commit | 6f960b553b5392db0bf7435f1567b3b1cff71af1 (patch) | |
| tree | 378001e4835c5d4f49bbf387102197d46524655e /src/indexer.c | |
| parent | d2c4f7645cab7d9ce0261d03cd7b5226cab90b63 (diff) | |
| parent | c0e541556600d825779c950ab1a4ce93b6782b09 (diff) | |
| download | libgit2-6f960b553b5392db0bf7435f1567b3b1cff71af1.tar.gz | |
Merge pull request #4088 from chescock/packfile-name-using-complete-hash
Ensure packfiles with different contents have different names
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 68cd205e0..15f6cc2c4 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -937,7 +937,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; @@ -946,9 +945,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"); @@ -992,6 +988,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"); @@ -1018,9 +1018,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) { @@ -1106,14 +1104,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; } |
