@@ -38,25 +38,26 @@ struct odb_transaction {
3838 struct bulk_checkin_packfile packfile ;
3939};
4040
41- static void finish_tmp_packfile (struct strbuf * basename ,
42- const char * pack_tmp_name ,
43- struct pack_idx_entry * * written_list ,
44- uint32_t nr_written ,
45- struct pack_idx_option * pack_idx_opts ,
41+ static void finish_tmp_packfile (struct odb_transaction * transaction ,
42+ struct strbuf * basename ,
4643 unsigned char hash [])
4744{
45+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
46+ struct repository * repo = transaction -> odb -> repo ;
4847 char * idx_tmp_name = NULL ;
4948
50- stage_tmp_packfiles (the_repository , basename , pack_tmp_name ,
51- written_list , nr_written , NULL , pack_idx_opts , hash ,
52- & idx_tmp_name );
53- rename_tmp_packfile_idx (the_repository , basename , & idx_tmp_name );
49+ stage_tmp_packfiles (repo , basename , state -> pack_tmp_name ,
50+ state -> written , state -> nr_written , NULL ,
51+ & state -> pack_idx_opts , hash , & idx_tmp_name );
52+ rename_tmp_packfile_idx (repo , basename , & idx_tmp_name );
5453
5554 free (idx_tmp_name );
5655}
5756
58- static void flush_bulk_checkin_packfile (struct bulk_checkin_packfile * state )
57+ static void flush_bulk_checkin_packfile (struct odb_transaction * transaction )
5958{
59+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
60+ struct repository * repo = transaction -> odb -> repo ;
6061 unsigned char hash [GIT_MAX_RAWSZ ];
6162 struct strbuf packname = STRBUF_INIT ;
6263
@@ -73,17 +74,17 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
7374 CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE );
7475 } else {
7576 int fd = finalize_hashfile (state -> f , hash , FSYNC_COMPONENT_PACK , 0 );
76- fixup_pack_header_footer (the_hash_algo , fd , hash , state -> pack_tmp_name ,
77+ fixup_pack_header_footer (repo -> hash_algo , fd , hash , state -> pack_tmp_name ,
7778 state -> nr_written , hash ,
7879 state -> offset );
7980 close (fd );
8081 }
8182
82- strbuf_addf (& packname , "%s/pack/pack-%s." , repo_get_object_directory ( the_repository ),
83- hash_to_hex ( hash ));
84- finish_tmp_packfile ( & packname , state -> pack_tmp_name ,
85- state -> written , state -> nr_written ,
86- & state -> pack_idx_opts , hash );
83+ strbuf_addf (& packname , "%s/pack/pack-%s." ,
84+ repo_get_object_directory ( transaction -> odb -> repo ),
85+ hash_to_hex_algop ( hash , repo -> hash_algo ));
86+
87+ finish_tmp_packfile ( transaction , & packname , hash );
8788 for (uint32_t i = 0 ; i < state -> nr_written ; i ++ )
8889 free (state -> written [i ]);
8990
@@ -94,7 +95,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
9495
9596 strbuf_release (& packname );
9697 /* Make objects we just wrote available to ourselves */
97- reprepare_packed_git (the_repository );
98+ reprepare_packed_git (repo );
9899}
99100
100101/*
@@ -117,7 +118,8 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
117118 * to ensure that the data in each new object file is durable before
118119 * the final name is visible.
119120 */
120- strbuf_addf (& temp_path , "%s/bulk_fsync_XXXXXX" , repo_get_object_directory (the_repository ));
121+ strbuf_addf (& temp_path , "%s/bulk_fsync_XXXXXX" ,
122+ repo_get_object_directory (transaction -> odb -> repo ));
121123 temp = xmks_tempfile (temp_path .buf );
122124 fsync_or_die (get_tempfile_fd (temp ), get_tempfile_path (temp ));
123125 delete_tempfile (& temp );
@@ -131,16 +133,17 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
131133 transaction -> objdir = NULL ;
132134}
133135
134- static int already_written (struct bulk_checkin_packfile * state , struct object_id * oid )
136+ static int already_written (struct odb_transaction * transaction ,
137+ struct object_id * oid )
135138{
136139 /* The object may already exist in the repository */
137- if (odb_has_object (the_repository -> objects , oid ,
140+ if (odb_has_object (transaction -> odb , oid ,
138141 HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR ))
139142 return 1 ;
140143
141144 /* Might want to keep the list sorted */
142- for (uint32_t i = 0 ; i < state -> nr_written ; i ++ )
143- if (oideq (& state -> written [i ]-> oid , oid ))
145+ for (uint32_t i = 0 ; i < transaction -> packfile . nr_written ; i ++ )
146+ if (oideq (& transaction -> packfile . written [i ]-> oid , oid ))
144147 return 1 ;
145148
146149 /* This is a new object we need to keep */
@@ -239,13 +242,15 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
239242}
240243
241244/* Lazily create backing packfile for the state */
242- static void prepare_to_stream (struct bulk_checkin_packfile * state ,
245+ static void prepare_to_stream (struct odb_transaction * transaction ,
243246 unsigned flags )
244247{
248+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
245249 if (!(flags & INDEX_WRITE_OBJECT ) || state -> f )
246250 return ;
247251
248- state -> f = create_tmp_packfile (the_repository , & state -> pack_tmp_name );
252+ state -> f = create_tmp_packfile (transaction -> odb -> repo ,
253+ & state -> pack_tmp_name );
249254 reset_pack_idx_option (& state -> pack_idx_opts );
250255
251256 /* Pretend we are going to write only one object */
@@ -272,21 +277,21 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
272277
273278 header_len = format_object_header ((char * )obuf , sizeof (obuf ),
274279 OBJ_BLOB , size );
275- the_hash_algo -> init_fn (& ctx );
280+ transaction -> odb -> repo -> hash_algo -> init_fn (& ctx );
276281 git_hash_update (& ctx , obuf , header_len );
277282
278283 /* Note: idx is non-NULL when we are writing */
279284 if ((flags & INDEX_WRITE_OBJECT ) != 0 ) {
280285 CALLOC_ARRAY (idx , 1 );
281286
282- prepare_to_stream (state , flags );
287+ prepare_to_stream (transaction , flags );
283288 hashfile_checkpoint_init (state -> f , & checkpoint );
284289 }
285290
286291 already_hashed_to = 0 ;
287292
288293 while (1 ) {
289- prepare_to_stream (state , flags );
294+ prepare_to_stream (transaction , flags );
290295 if (idx ) {
291296 hashfile_checkpoint (state -> f , & checkpoint );
292297 idx -> offset = state -> offset ;
@@ -304,7 +309,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
304309 BUG ("should not happen" );
305310 hashfile_truncate (state -> f , & checkpoint );
306311 state -> offset = checkpoint .offset ;
307- flush_bulk_checkin_packfile (state );
312+ flush_bulk_checkin_packfile (transaction );
308313 if (lseek (fd , seekback , SEEK_SET ) == (off_t ) - 1 )
309314 return error ("cannot seek back" );
310315 }
@@ -313,7 +318,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
313318 return 0 ;
314319
315320 idx -> crc32 = crc32_end (state -> f );
316- if (already_written (state , result_oid )) {
321+ if (already_written (transaction , result_oid )) {
317322 hashfile_truncate (state -> f , & checkpoint );
318323 state -> offset = checkpoint .offset ;
319324 free (idx );
@@ -338,7 +343,7 @@ void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
338343 if (!transaction || transaction -> objdir )
339344 return ;
340345
341- transaction -> objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
346+ transaction -> objdir = tmp_objdir_create (transaction -> odb -> repo , "bulk-fsync" );
342347 if (transaction -> objdir )
343348 tmp_objdir_replace_primary_odb (transaction -> objdir , 0 );
344349}
@@ -379,7 +384,7 @@ void flush_odb_transaction(struct odb_transaction *transaction)
379384 return ;
380385
381386 flush_batch_fsync (transaction );
382- flush_bulk_checkin_packfile (& transaction -> packfile );
387+ flush_bulk_checkin_packfile (transaction );
383388}
384389
385390void end_odb_transaction (struct odb_transaction * transaction )
0 commit comments