@@ -38,25 +38,26 @@ struct odb_transaction {
38
38
struct bulk_checkin_packfile packfile ;
39
39
};
40
40
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 ,
46
43
unsigned char hash [])
47
44
{
45
+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
46
+ struct repository * repo = transaction -> odb -> repo ;
48
47
char * idx_tmp_name = NULL ;
49
48
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 );
54
53
55
54
free (idx_tmp_name );
56
55
}
57
56
58
- static void flush_bulk_checkin_packfile (struct bulk_checkin_packfile * state )
57
+ static void flush_bulk_checkin_packfile (struct odb_transaction * transaction )
59
58
{
59
+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
60
+ struct repository * repo = transaction -> odb -> repo ;
60
61
unsigned char hash [GIT_MAX_RAWSZ ];
61
62
struct strbuf packname = STRBUF_INIT ;
62
63
@@ -73,17 +74,17 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
73
74
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE );
74
75
} else {
75
76
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 ,
77
78
state -> nr_written , hash ,
78
79
state -> offset );
79
80
close (fd );
80
81
}
81
82
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 );
87
88
for (uint32_t i = 0 ; i < state -> nr_written ; i ++ )
88
89
free (state -> written [i ]);
89
90
@@ -94,7 +95,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
94
95
95
96
strbuf_release (& packname );
96
97
/* Make objects we just wrote available to ourselves */
97
- reprepare_packed_git (the_repository );
98
+ reprepare_packed_git (repo );
98
99
}
99
100
100
101
/*
@@ -117,7 +118,8 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
117
118
* to ensure that the data in each new object file is durable before
118
119
* the final name is visible.
119
120
*/
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 ));
121
123
temp = xmks_tempfile (temp_path .buf );
122
124
fsync_or_die (get_tempfile_fd (temp ), get_tempfile_path (temp ));
123
125
delete_tempfile (& temp );
@@ -131,16 +133,17 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
131
133
transaction -> objdir = NULL ;
132
134
}
133
135
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 )
135
138
{
136
139
/* 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 ,
138
141
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR ))
139
142
return 1 ;
140
143
141
144
/* 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 ))
144
147
return 1 ;
145
148
146
149
/* This is a new object we need to keep */
@@ -239,13 +242,15 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
239
242
}
240
243
241
244
/* 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 ,
243
246
unsigned flags )
244
247
{
248
+ struct bulk_checkin_packfile * state = & transaction -> packfile ;
245
249
if (!(flags & INDEX_WRITE_OBJECT ) || state -> f )
246
250
return ;
247
251
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 );
249
254
reset_pack_idx_option (& state -> pack_idx_opts );
250
255
251
256
/* Pretend we are going to write only one object */
@@ -272,21 +277,21 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
272
277
273
278
header_len = format_object_header ((char * )obuf , sizeof (obuf ),
274
279
OBJ_BLOB , size );
275
- the_hash_algo -> init_fn (& ctx );
280
+ transaction -> odb -> repo -> hash_algo -> init_fn (& ctx );
276
281
git_hash_update (& ctx , obuf , header_len );
277
282
278
283
/* Note: idx is non-NULL when we are writing */
279
284
if ((flags & INDEX_WRITE_OBJECT ) != 0 ) {
280
285
CALLOC_ARRAY (idx , 1 );
281
286
282
- prepare_to_stream (state , flags );
287
+ prepare_to_stream (transaction , flags );
283
288
hashfile_checkpoint_init (state -> f , & checkpoint );
284
289
}
285
290
286
291
already_hashed_to = 0 ;
287
292
288
293
while (1 ) {
289
- prepare_to_stream (state , flags );
294
+ prepare_to_stream (transaction , flags );
290
295
if (idx ) {
291
296
hashfile_checkpoint (state -> f , & checkpoint );
292
297
idx -> offset = state -> offset ;
@@ -304,7 +309,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
304
309
BUG ("should not happen" );
305
310
hashfile_truncate (state -> f , & checkpoint );
306
311
state -> offset = checkpoint .offset ;
307
- flush_bulk_checkin_packfile (state );
312
+ flush_bulk_checkin_packfile (transaction );
308
313
if (lseek (fd , seekback , SEEK_SET ) == (off_t ) - 1 )
309
314
return error ("cannot seek back" );
310
315
}
@@ -313,7 +318,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
313
318
return 0 ;
314
319
315
320
idx -> crc32 = crc32_end (state -> f );
316
- if (already_written (state , result_oid )) {
321
+ if (already_written (transaction , result_oid )) {
317
322
hashfile_truncate (state -> f , & checkpoint );
318
323
state -> offset = checkpoint .offset ;
319
324
free (idx );
@@ -338,7 +343,7 @@ void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
338
343
if (!transaction || transaction -> objdir )
339
344
return ;
340
345
341
- transaction -> objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
346
+ transaction -> objdir = tmp_objdir_create (transaction -> odb -> repo , "bulk-fsync" );
342
347
if (transaction -> objdir )
343
348
tmp_objdir_replace_primary_odb (transaction -> objdir , 0 );
344
349
}
@@ -379,7 +384,7 @@ void flush_odb_transaction(struct odb_transaction *transaction)
379
384
return ;
380
385
381
386
flush_batch_fsync (transaction );
382
- flush_bulk_checkin_packfile (& transaction -> packfile );
387
+ flush_bulk_checkin_packfile (transaction );
383
388
}
384
389
385
390
void end_odb_transaction (struct odb_transaction * transaction )
0 commit comments