@@ -2903,6 +2903,16 @@ static int record_ieot(void)
2903
2903
return !git_config_get_index_threads (& val ) && val != 1 ;
2904
2904
}
2905
2905
2906
+ enum write_extensions {
2907
+ WRITE_NO_EXTENSION = 0 ,
2908
+ WRITE_SPLIT_INDEX_EXTENSION = 1 <<0 ,
2909
+ WRITE_CACHE_TREE_EXTENSION = 1 <<1 ,
2910
+ WRITE_RESOLVE_UNDO_EXTENSION = 1 <<2 ,
2911
+ WRITE_UNTRACKED_CACHE_EXTENSION = 1 <<3 ,
2912
+ WRITE_FSMONITOR_EXTENSION = 1 <<4 ,
2913
+ };
2914
+ #define WRITE_ALL_EXTENSIONS ((enum write_extensions)-1)
2915
+
2906
2916
/*
2907
2917
* On success, `tempfile` is closed. If it is the temporary file
2908
2918
* of a `struct lock_file`, we will therefore effectively perform
@@ -2911,7 +2921,7 @@ static int record_ieot(void)
2911
2921
* rely on it.
2912
2922
*/
2913
2923
static int do_write_index (struct index_state * istate , struct tempfile * tempfile ,
2914
- int strip_extensions , unsigned flags )
2924
+ enum write_extensions write_extensions , unsigned flags )
2915
2925
{
2916
2926
uint64_t start = getnanotime ();
2917
2927
struct hashfile * f ;
@@ -3084,8 +3094,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3084
3094
return -1 ;
3085
3095
}
3086
3096
3087
- if (! strip_extensions && istate -> split_index &&
3088
- ! is_null_oid ( & istate -> split_index -> base_oid ) ) {
3097
+ if (write_extensions & WRITE_SPLIT_INDEX_EXTENSION &&
3098
+ istate -> split_index ) {
3089
3099
struct strbuf sb = STRBUF_INIT ;
3090
3100
3091
3101
if (istate -> sparse_index )
@@ -3099,7 +3109,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3099
3109
if (err )
3100
3110
return -1 ;
3101
3111
}
3102
- if (!strip_extensions && !drop_cache_tree && istate -> cache_tree ) {
3112
+ if (write_extensions & WRITE_CACHE_TREE_EXTENSION &&
3113
+ !drop_cache_tree && istate -> cache_tree ) {
3103
3114
struct strbuf sb = STRBUF_INIT ;
3104
3115
3105
3116
cache_tree_write (& sb , istate -> cache_tree );
@@ -3109,7 +3120,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3109
3120
if (err )
3110
3121
return -1 ;
3111
3122
}
3112
- if (!strip_extensions && istate -> resolve_undo ) {
3123
+ if (write_extensions & WRITE_RESOLVE_UNDO_EXTENSION &&
3124
+ istate -> resolve_undo ) {
3113
3125
struct strbuf sb = STRBUF_INIT ;
3114
3126
3115
3127
resolve_undo_write (& sb , istate -> resolve_undo );
@@ -3120,7 +3132,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3120
3132
if (err )
3121
3133
return -1 ;
3122
3134
}
3123
- if (!strip_extensions && istate -> untracked ) {
3135
+ if (write_extensions & WRITE_UNTRACKED_CACHE_EXTENSION &&
3136
+ istate -> untracked ) {
3124
3137
struct strbuf sb = STRBUF_INIT ;
3125
3138
3126
3139
write_untracked_extension (& sb , istate -> untracked );
@@ -3131,7 +3144,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
3131
3144
if (err )
3132
3145
return -1 ;
3133
3146
}
3134
- if (!strip_extensions && istate -> fsmonitor_last_update ) {
3147
+ if (write_extensions & WRITE_FSMONITOR_EXTENSION &&
3148
+ istate -> fsmonitor_last_update ) {
3135
3149
struct strbuf sb = STRBUF_INIT ;
3136
3150
3137
3151
write_fsmonitor_extension (& sb , istate );
@@ -3205,8 +3219,10 @@ static int commit_locked_index(struct lock_file *lk)
3205
3219
return commit_lock_file (lk );
3206
3220
}
3207
3221
3208
- static int do_write_locked_index (struct index_state * istate , struct lock_file * lock ,
3209
- unsigned flags )
3222
+ static int do_write_locked_index (struct index_state * istate ,
3223
+ struct lock_file * lock ,
3224
+ unsigned flags ,
3225
+ enum write_extensions write_extensions )
3210
3226
{
3211
3227
int ret ;
3212
3228
int was_full = istate -> sparse_index == INDEX_EXPANDED ;
@@ -3224,7 +3240,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
3224
3240
*/
3225
3241
trace2_region_enter_printf ("index" , "do_write_index" , the_repository ,
3226
3242
"%s" , get_lock_file_path (lock ));
3227
- ret = do_write_index (istate , lock -> tempfile , 0 , flags );
3243
+ ret = do_write_index (istate , lock -> tempfile , write_extensions , flags );
3228
3244
trace2_region_leave_printf ("index" , "do_write_index" , the_repository ,
3229
3245
"%s" , get_lock_file_path (lock ));
3230
3246
@@ -3253,7 +3269,7 @@ static int write_split_index(struct index_state *istate,
3253
3269
{
3254
3270
int ret ;
3255
3271
prepare_to_write_split_index (istate );
3256
- ret = do_write_locked_index (istate , lock , flags );
3272
+ ret = do_write_locked_index (istate , lock , flags , WRITE_ALL_EXTENSIONS );
3257
3273
finish_writing_split_index (istate );
3258
3274
return ret ;
3259
3275
}
@@ -3328,7 +3344,7 @@ static int write_shared_index(struct index_state *istate,
3328
3344
3329
3345
trace2_region_enter_printf ("index" , "shared/do_write_index" ,
3330
3346
the_repository , "%s" , get_tempfile_path (* temp ));
3331
- ret = do_write_index (si -> base , * temp , 1 , flags );
3347
+ ret = do_write_index (si -> base , * temp , WRITE_NO_EXTENSION , flags );
3332
3348
trace2_region_leave_printf ("index" , "shared/do_write_index" ,
3333
3349
the_repository , "%s" , get_tempfile_path (* temp ));
3334
3350
@@ -3405,9 +3421,8 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
3405
3421
if ((!si && !test_split_index_env ) ||
3406
3422
alternate_index_output ||
3407
3423
(istate -> cache_changed & ~EXTMASK )) {
3408
- if (si )
3409
- oidclr (& si -> base_oid );
3410
- ret = do_write_locked_index (istate , lock , flags );
3424
+ ret = do_write_locked_index (istate , lock , flags ,
3425
+ ~WRITE_SPLIT_INDEX_EXTENSION );
3411
3426
goto out ;
3412
3427
}
3413
3428
@@ -3433,8 +3448,8 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
3433
3448
/* Same initial permissions as the main .git/index file */
3434
3449
temp = mks_tempfile_sm (git_path ("sharedindex_XXXXXX" ), 0 , 0666 );
3435
3450
if (!temp ) {
3436
- oidclr ( & si -> base_oid );
3437
- ret = do_write_locked_index ( istate , lock , flags );
3451
+ ret = do_write_locked_index ( istate , lock , flags ,
3452
+ ~ WRITE_SPLIT_INDEX_EXTENSION );
3438
3453
goto out ;
3439
3454
}
3440
3455
ret = write_shared_index (istate , & temp , flags );
0 commit comments