@@ -30,11 +30,13 @@ struct bulk_checkin_packfile {
30
30
uint32_t nr_written ;
31
31
};
32
32
33
- static struct odb_transaction {
33
+ struct odb_transaction {
34
+ struct object_database * odb ;
35
+
34
36
int nesting ;
35
37
struct tmp_objdir * objdir ;
36
38
struct bulk_checkin_packfile packfile ;
37
- } transaction ;
39
+ };
38
40
39
41
static void finish_tmp_packfile (struct strbuf * basename ,
40
42
const char * pack_tmp_name ,
@@ -98,12 +100,12 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
98
100
/*
99
101
* Cleanup after batch-mode fsync_object_files.
100
102
*/
101
- static void flush_batch_fsync (void )
103
+ static void flush_batch_fsync (struct odb_transaction * transaction )
102
104
{
103
105
struct strbuf temp_path = STRBUF_INIT ;
104
106
struct tempfile * temp ;
105
107
106
- if (!transaction . objdir )
108
+ if (!transaction -> objdir )
107
109
return ;
108
110
109
111
/*
@@ -125,8 +127,8 @@ static void flush_batch_fsync(void)
125
127
* Make the object files visible in the primary ODB after their data is
126
128
* fully durable.
127
129
*/
128
- tmp_objdir_migrate (transaction . objdir );
129
- transaction . objdir = NULL ;
130
+ tmp_objdir_migrate (transaction -> objdir );
131
+ transaction -> objdir = NULL ;
130
132
}
131
133
132
134
static int already_written (struct bulk_checkin_packfile * state , struct object_id * oid )
@@ -325,23 +327,24 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
325
327
return 0 ;
326
328
}
327
329
328
- void prepare_loose_object_bulk_checkin (void )
330
+ void prepare_loose_object_bulk_checkin (struct odb_transaction * transaction )
329
331
{
330
332
/*
331
333
* We lazily create the temporary object directory
332
334
* the first time an object might be added, since
333
335
* callers may not know whether any objects will be
334
336
* added at the time they call begin_odb_transaction.
335
337
*/
336
- if (!transaction . nesting || transaction . objdir )
338
+ if (!transaction || transaction -> objdir )
337
339
return ;
338
340
339
- transaction . objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
340
- if (transaction . objdir )
341
- tmp_objdir_replace_primary_odb (transaction . objdir , 0 );
341
+ transaction -> objdir = tmp_objdir_create (the_repository , "bulk-fsync" );
342
+ if (transaction -> objdir )
343
+ tmp_objdir_replace_primary_odb (transaction -> objdir , 0 );
342
344
}
343
345
344
- void fsync_loose_object_bulk_checkin (int fd , const char * filename )
346
+ void fsync_loose_object_bulk_checkin (struct odb_transaction * transaction ,
347
+ int fd , const char * filename )
345
348
{
346
349
/*
347
350
* If we have an active ODB transaction, we issue a call that
@@ -350,44 +353,65 @@ void fsync_loose_object_bulk_checkin(int fd, const char *filename)
350
353
* before renaming the objects to their final names as part of
351
354
* flush_batch_fsync.
352
355
*/
353
- if (!transaction . objdir ||
356
+ if (!transaction || ! transaction -> objdir ||
354
357
git_fsync (fd , FSYNC_WRITEOUT_ONLY ) < 0 ) {
355
358
if (errno == ENOSYS )
356
359
warning (_ ("core.fsyncMethod = batch is unsupported on this platform" ));
357
360
fsync_or_die (fd , filename );
358
361
}
359
362
}
360
363
361
- int index_blob_bulk_checkin (struct object_id * oid ,
362
- int fd , size_t size ,
364
+ int index_blob_bulk_checkin (struct odb_transaction * transaction ,
365
+ struct object_id * oid , int fd , size_t size ,
363
366
const char * path , unsigned flags )
364
367
{
365
- int status = deflate_blob_to_pack (& transaction .packfile , oid , fd , size ,
366
- path , flags );
367
- if (!transaction .nesting )
368
- flush_bulk_checkin_packfile (& transaction .packfile );
368
+ int status ;
369
+
370
+ if (transaction ) {
371
+ status = deflate_blob_to_pack (& transaction -> packfile , oid , fd ,
372
+ size , path , flags );
373
+ } else {
374
+ struct bulk_checkin_packfile state = { 0 };
375
+
376
+ status = deflate_blob_to_pack (& state , oid , fd , size , path , flags );
377
+ flush_bulk_checkin_packfile (& state );
378
+ }
379
+
369
380
return status ;
370
381
}
371
382
372
- void begin_odb_transaction (void )
383
+ struct odb_transaction * begin_odb_transaction (struct object_database * odb )
373
384
{
374
- transaction .nesting += 1 ;
385
+ if (!odb -> transaction ) {
386
+ CALLOC_ARRAY (odb -> transaction , 1 );
387
+ odb -> transaction -> odb = odb ;
388
+ }
389
+
390
+ odb -> transaction -> nesting += 1 ;
391
+
392
+ return odb -> transaction ;
375
393
}
376
394
377
- void flush_odb_transaction (void )
395
+ void flush_odb_transaction (struct odb_transaction * transaction )
378
396
{
379
- flush_batch_fsync ();
380
- flush_bulk_checkin_packfile (& transaction .packfile );
397
+ if (!transaction )
398
+ return ;
399
+
400
+ flush_batch_fsync (transaction );
401
+ flush_bulk_checkin_packfile (& transaction -> packfile );
381
402
}
382
403
383
- void end_odb_transaction (void )
404
+ void end_odb_transaction (struct odb_transaction * transaction )
384
405
{
385
- transaction .nesting -= 1 ;
386
- if (transaction .nesting < 0 )
406
+ if (!transaction || transaction -> nesting == 0 )
387
407
BUG ("Unbalanced ODB transaction nesting" );
388
408
389
- if (transaction .nesting )
409
+ transaction -> nesting -= 1 ;
410
+
411
+ if (transaction -> nesting )
390
412
return ;
391
413
392
- flush_odb_transaction ();
414
+ flush_odb_transaction (transaction );
415
+ transaction -> odb -> transaction = NULL ;
416
+ free (transaction );
393
417
}
0 commit comments