19
19
#include "object-file.h"
20
20
#include "odb.h"
21
21
22
- static int odb_transaction_nesting ;
23
-
24
- static struct tmp_objdir * bulk_fsync_objdir ;
25
-
26
- static struct bulk_checkin_packfile {
22
+ struct bulk_checkin_packfile {
27
23
char * pack_tmp_name ;
28
24
struct hashfile * f ;
29
25
off_t offset ;
@@ -32,7 +28,13 @@ static struct bulk_checkin_packfile {
32
28
struct pack_idx_entry * * written ;
33
29
uint32_t alloc_written ;
34
30
uint32_t nr_written ;
35
- } bulk_checkin_packfile ;
31
+ };
32
+
33
+ static struct odb_transaction {
34
+ int nesting ;
35
+ struct tmp_objdir * objdir ;
36
+ struct bulk_checkin_packfile packfile ;
37
+ } transaction ;
36
38
37
39
static void finish_tmp_packfile (struct strbuf * basename ,
38
40
const char * pack_tmp_name ,
@@ -101,7 +103,7 @@ static void flush_batch_fsync(void)
101
103
struct strbuf temp_path = STRBUF_INIT ;
102
104
struct tempfile * temp ;
103
105
104
- if (!bulk_fsync_objdir )
106
+ if (!transaction . objdir )
105
107
return ;
106
108
107
109
/*
@@ -123,8 +125,8 @@ static void flush_batch_fsync(void)
123
125
* Make the object files visible in the primary ODB after their data is
124
126
* fully durable.
125
127
*/
126
- tmp_objdir_migrate (bulk_fsync_objdir );
127
- bulk_fsync_objdir = NULL ;
128
+ tmp_objdir_migrate (transaction . objdir );
129
+ transaction . objdir = NULL ;
128
130
}
129
131
130
132
static int already_written (struct bulk_checkin_packfile * state , struct object_id * oid )
@@ -331,12 +333,12 @@ void prepare_loose_object_bulk_checkin(void)
331
333
* callers may not know whether any objects will be
332
334
* added at the time they call begin_odb_transaction.
333
335
*/
334
- if (!odb_transaction_nesting || bulk_fsync_objdir )
336
+ if (!transaction . nesting || transaction . objdir )
335
337
return ;
336
338
337
- bulk_fsync_objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
338
- if (bulk_fsync_objdir )
339
- tmp_objdir_replace_primary_odb (bulk_fsync_objdir , 0 );
339
+ transaction . objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
340
+ if (transaction . objdir )
341
+ tmp_objdir_replace_primary_odb (transaction . objdir , 0 );
340
342
}
341
343
342
344
void fsync_loose_object_bulk_checkin (int fd , const char * filename )
@@ -348,7 +350,7 @@ void fsync_loose_object_bulk_checkin(int fd, const char *filename)
348
350
* before renaming the objects to their final names as part of
349
351
* flush_batch_fsync.
350
352
*/
351
- if (!bulk_fsync_objdir ||
353
+ if (!transaction . objdir ||
352
354
git_fsync (fd , FSYNC_WRITEOUT_ONLY ) < 0 ) {
353
355
if (errno == ENOSYS )
354
356
warning (_ ("core.fsyncMethod = batch is unsupported on this platform" ));
@@ -360,31 +362,31 @@ int index_blob_bulk_checkin(struct object_id *oid,
360
362
int fd , size_t size ,
361
363
const char * path , unsigned flags )
362
364
{
363
- int status = deflate_blob_to_pack (& bulk_checkin_packfile , oid , fd , size ,
365
+ int status = deflate_blob_to_pack (& transaction . packfile , oid , fd , size ,
364
366
path , flags );
365
- if (!odb_transaction_nesting )
366
- flush_bulk_checkin_packfile (& bulk_checkin_packfile );
367
+ if (!transaction . nesting )
368
+ flush_bulk_checkin_packfile (& transaction . packfile );
367
369
return status ;
368
370
}
369
371
370
372
void begin_odb_transaction (void )
371
373
{
372
- odb_transaction_nesting += 1 ;
374
+ transaction . nesting += 1 ;
373
375
}
374
376
375
377
void flush_odb_transaction (void )
376
378
{
377
379
flush_batch_fsync ();
378
- flush_bulk_checkin_packfile (& bulk_checkin_packfile );
380
+ flush_bulk_checkin_packfile (& transaction . packfile );
379
381
}
380
382
381
383
void end_odb_transaction (void )
382
384
{
383
- odb_transaction_nesting -= 1 ;
384
- if (odb_transaction_nesting < 0 )
385
+ transaction . nesting -= 1 ;
386
+ if (transaction . nesting < 0 )
385
387
BUG ("Unbalanced ODB transaction nesting" );
386
388
387
- if (odb_transaction_nesting )
389
+ if (transaction . nesting )
388
390
return ;
389
391
390
392
flush_odb_transaction ();
0 commit comments