@@ -55,7 +55,8 @@ struct git_indexer {
5555 git_vector deltas ;
5656 unsigned int fanout [256 ];
5757 git_hash_ctx hash_ctx ;
58- git_oid hash ;
58+ unsigned char checksum [GIT_HASH_SHA1_SIZE ];
59+ char name [(GIT_HASH_SHA1_SIZE * 2 ) + 1 ];
5960 git_indexer_progress_cb progress_cb ;
6061 void * progress_payload ;
6162 char objbuf [8 * 1024 ];
@@ -76,9 +77,16 @@ struct delta_info {
7677 off64_t delta_off ;
7778};
7879
80+ #ifndef GIT_DEPRECATE_HARD
7981const git_oid * git_indexer_hash (const git_indexer * idx )
8082{
81- return & idx -> hash ;
83+ return (git_oid * )idx -> checksum ;
84+ }
85+ #endif
86+
87+ const char * git_indexer_name (const git_indexer * idx )
88+ {
89+ return idx -> name ;
8290}
8391
8492static int parse_header (struct git_pack_header * hdr , struct git_pack_file * pack )
@@ -897,8 +905,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix)
897905
898906 git_str_truncate (path , slash );
899907 git_str_puts (path , prefix );
900- git_oid_fmt (path -> ptr + git_str_len (path ), & idx -> hash );
901- path -> size += GIT_OID_HEXSZ ;
908+ git_str_puts (path , idx -> name );
902909 git_str_puts (path , suffix );
903910
904911 return git_str_oom (path ) ? -1 : 0 ;
@@ -919,12 +926,13 @@ static int inject_object(git_indexer *idx, git_oid *id)
919926 git_odb_object * obj = NULL ;
920927 struct entry * entry = NULL ;
921928 struct git_pack_entry * pentry = NULL ;
922- git_oid foo = {{ 0 } };
929+ unsigned char empty_checksum [ GIT_HASH_SHA1_SIZE ] = {0 };
923930 unsigned char hdr [64 ];
924931 git_str buf = GIT_STR_INIT ;
925932 off64_t entry_start ;
926933 const void * data ;
927934 size_t len , hdr_len ;
935+ size_t checksum_size = GIT_HASH_SHA1_SIZE ;
928936 int error ;
929937
930938 if ((error = seek_back_trailer (idx )) < 0 )
@@ -966,7 +974,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
966974
967975 /* Write a fake trailer so the pack functions play ball */
968976
969- if ((error = append_to_pack (idx , & foo , GIT_OID_RAWSZ )) < 0 )
977+ if ((error = append_to_pack (idx , empty_checksum , checksum_size )) < 0 )
970978 goto cleanup ;
971979
972980 idx -> pack -> mwf .size += GIT_OID_RAWSZ ;
@@ -1160,37 +1168,39 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
11601168 struct git_pack_idx_header hdr ;
11611169 git_str filename = GIT_STR_INIT ;
11621170 struct entry * entry ;
1163- git_oid trailer_hash , file_hash ;
1171+ unsigned char checksum [ GIT_HASH_SHA1_SIZE ] ;
11641172 git_filebuf index_file = {0 };
11651173 void * packfile_trailer ;
1174+ size_t checksum_size = GIT_HASH_SHA1_SIZE ;
1175+ bool mismatch ;
11661176
11671177 if (!idx -> parsed_header ) {
11681178 git_error_set (GIT_ERROR_INDEXER , "incomplete pack header" );
11691179 return -1 ;
11701180 }
11711181
11721182 /* Test for this before resolve_deltas(), as it plays with idx->off */
1173- if (idx -> off + 20 < idx -> pack -> mwf .size ) {
1183+ if (idx -> off + ( ssize_t ) checksum_size < idx -> pack -> mwf .size ) {
11741184 git_error_set (GIT_ERROR_INDEXER , "unexpected data at the end of the pack" );
11751185 return -1 ;
11761186 }
1177- if (idx -> off + 20 > idx -> pack -> mwf .size ) {
1187+ if (idx -> off + ( ssize_t ) checksum_size > idx -> pack -> mwf .size ) {
11781188 git_error_set (GIT_ERROR_INDEXER , "missing trailer at the end of the pack" );
11791189 return -1 ;
11801190 }
11811191
1182- packfile_trailer = git_mwindow_open (& idx -> pack -> mwf , & w , idx -> pack -> mwf .size - GIT_OID_RAWSZ , GIT_OID_RAWSZ , & left );
1192+ packfile_trailer = git_mwindow_open (& idx -> pack -> mwf , & w , idx -> pack -> mwf .size - checksum_size , checksum_size , & left );
11831193 if (packfile_trailer == NULL ) {
11841194 git_mwindow_close (& w );
11851195 goto on_error ;
11861196 }
11871197
11881198 /* Compare the packfile trailer as it was sent to us and what we calculated */
1189- git_oid_fromraw (& file_hash , packfile_trailer );
1199+ git_hash_final (checksum , & idx -> trailer );
1200+ mismatch = !!memcmp (checksum , packfile_trailer , checksum_size );
11901201 git_mwindow_close (& w );
11911202
1192- git_hash_final (trailer_hash .id , & idx -> trailer );
1193- if (git_oid_cmp (& file_hash , & trailer_hash )) {
1203+ if (mismatch ) {
11941204 git_error_set (GIT_ERROR_INDEXER , "packfile trailer mismatch" );
11951205 return -1 ;
11961206 }
@@ -1210,8 +1220,8 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
12101220 if (update_header_and_rehash (idx , stats ) < 0 )
12111221 return -1 ;
12121222
1213- git_hash_final (trailer_hash . id , & idx -> trailer );
1214- write_at (idx , & trailer_hash , idx -> pack -> mwf .size - GIT_OID_RAWSZ , GIT_OID_RAWSZ );
1223+ git_hash_final (checksum , & idx -> trailer );
1224+ write_at (idx , checksum , idx -> pack -> mwf .size - checksum_size , checksum_size );
12151225 }
12161226
12171227 /*
@@ -1230,7 +1240,9 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
12301240
12311241 /* Use the trailer hash as the pack file name to ensure
12321242 * files with different contents have different names */
1233- git_oid_cpy (& idx -> hash , & trailer_hash );
1243+ memcpy (idx -> checksum , checksum , checksum_size );
1244+ if (git_hash_fmt (idx -> name , checksum , checksum_size ) < 0 )
1245+ return -1 ;
12341246
12351247 git_str_sets (& filename , idx -> pack -> pack_name );
12361248 git_str_shorten (& filename , strlen ("pack" ));
@@ -1291,14 +1303,14 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats)
12911303 }
12921304
12931305 /* Write out the packfile trailer to the index */
1294- if (git_filebuf_write (& index_file , & trailer_hash , GIT_OID_RAWSZ ) < 0 )
1306+ if (git_filebuf_write (& index_file , checksum , checksum_size ) < 0 )
12951307 goto on_error ;
12961308
12971309 /* Write out the hash of the idx */
1298- if (git_filebuf_hash (trailer_hash . id , & index_file ) < 0 )
1310+ if (git_filebuf_hash (checksum , & index_file ) < 0 )
12991311 goto on_error ;
13001312
1301- git_filebuf_write (& index_file , & trailer_hash , sizeof ( git_oid ) );
1313+ git_filebuf_write (& index_file , checksum , checksum_size );
13021314
13031315 /* Figure out what the final name should be */
13041316 if (index_path (& filename , idx , ".idx" ) < 0 )
0 commit comments