@@ -3278,6 +3278,7 @@ struct ref_update {
32783278 unsigned char old_sha1 [20 ];
32793279 int flags ; /* REF_NODEREF? */
32803280 int have_old ; /* 1 if old_sha1 is valid, 0 otherwise */
3281+ struct ref_lock * lock ;
32813282 const char refname [FLEX_ARRAY ];
32823283};
32833284
@@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34133414 int ret = 0 , delnum = 0 , i ;
34143415 struct ref_update * * updates ;
34153416 int * types ;
3416- struct ref_lock * * locks ;
34173417 const char * * delnames ;
34183418 int n = transaction -> nr ;
34193419
@@ -3423,7 +3423,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34233423 /* Allocate work space */
34243424 updates = xmalloc (sizeof (* updates ) * n );
34253425 types = xmalloc (sizeof (* types ) * n );
3426- locks = xcalloc (n , sizeof (* locks ));
34273426 delnames = xmalloc (sizeof (* delnames ) * n );
34283427
34293428 /* Copy, sort, and reject duplicate refs */
@@ -3437,12 +3436,12 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34373436 for (i = 0 ; i < n ; i ++ ) {
34383437 struct ref_update * update = updates [i ];
34393438
3440- locks [ i ] = update_ref_lock (update -> refname ,
3441- (update -> have_old ?
3442- update -> old_sha1 : NULL ),
3443- update -> flags ,
3444- & types [i ], onerr );
3445- if (!locks [ i ] ) {
3439+ update -> lock = update_ref_lock (update -> refname ,
3440+ (update -> have_old ?
3441+ update -> old_sha1 : NULL ),
3442+ update -> flags ,
3443+ & types [i ], onerr );
3444+ if (!update -> lock ) {
34463445 ret = 1 ;
34473446 goto cleanup ;
34483447 }
@@ -3456,31 +3455,34 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34563455 ret = update_ref_write (msg ,
34573456 update -> refname ,
34583457 update -> new_sha1 ,
3459- locks [ i ] , onerr );
3460- locks [ i ] = NULL ; /* freed by update_ref_write */
3458+ update -> lock , onerr );
3459+ update -> lock = NULL ; /* freed by update_ref_write */
34613460 if (ret )
34623461 goto cleanup ;
34633462 }
34643463 }
34653464
34663465 /* Perform deletes now that updates are safely completed */
3467- for (i = 0 ; i < n ; i ++ )
3468- if (locks [i ]) {
3469- delnames [delnum ++ ] = locks [i ]-> ref_name ;
3470- ret |= delete_ref_loose (locks [i ], types [i ]);
3466+ for (i = 0 ; i < n ; i ++ ) {
3467+ struct ref_update * update = updates [i ];
3468+
3469+ if (update -> lock ) {
3470+ delnames [delnum ++ ] = update -> lock -> ref_name ;
3471+ ret |= delete_ref_loose (update -> lock , types [i ]);
34713472 }
3473+ }
3474+
34723475 ret |= repack_without_refs (delnames , delnum );
34733476 for (i = 0 ; i < delnum ; i ++ )
34743477 unlink_or_warn (git_path ("logs/%s" , delnames [i ]));
34753478 clear_loose_ref_cache (& ref_cache );
34763479
34773480cleanup :
34783481 for (i = 0 ; i < n ; i ++ )
3479- if (locks [i ])
3480- unlock_ref (locks [i ]);
3482+ if (updates [i ]-> lock )
3483+ unlock_ref (updates [i ]-> lock );
34813484 free (updates );
34823485 free (types );
3483- free (locks );
34843486 free (delnames );
34853487 ref_transaction_free (transaction );
34863488 return ret ;
0 commit comments