@@ -2414,42 +2414,57 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
2414
2414
return 0 ;
2415
2415
}
2416
2416
2417
- static int repack_without_ref (const char * refname )
2417
+ static int repack_without_refs (const char * * refnames , int n )
2418
2418
{
2419
2419
struct ref_dir * packed ;
2420
2420
struct string_list refs_to_delete = STRING_LIST_INIT_DUP ;
2421
2421
struct string_list_item * ref_to_delete ;
2422
+ int i , removed = 0 ;
2423
+
2424
+ /* Look for a packed ref */
2425
+ for (i = 0 ; i < n ; i ++ )
2426
+ if (get_packed_ref (refnames [i ]))
2427
+ break ;
2422
2428
2423
- if (!get_packed_ref (refname ))
2424
- return 0 ; /* refname does not exist in packed refs */
2429
+ /* Avoid locking if we have nothing to do */
2430
+ if (i == n )
2431
+ return 0 ; /* no refname exists in packed refs */
2425
2432
2426
2433
if (lock_packed_refs (0 )) {
2427
2434
unable_to_lock_error (git_path ("packed-refs" ), errno );
2428
- return error ("cannot delete '%s' from packed refs" , refname );
2435
+ return error ("cannot delete '%s' from packed refs" , refnames [ i ] );
2429
2436
}
2430
2437
packed = get_packed_refs (& ref_cache );
2431
2438
2432
- /* Remove refname from the cache: */
2433
- if (remove_entry (packed , refname ) == -1 ) {
2439
+ /* Remove refnames from the cache */
2440
+ for (i = 0 ; i < n ; i ++ )
2441
+ if (remove_entry (packed , refnames [i ]) != -1 )
2442
+ removed = 1 ;
2443
+ if (!removed ) {
2434
2444
/*
2435
- * The packed entry disappeared while we were
2445
+ * All packed entries disappeared while we were
2436
2446
* acquiring the lock.
2437
2447
*/
2438
2448
rollback_packed_refs ();
2439
2449
return 0 ;
2440
2450
}
2441
2451
2442
- /* Remove any other accumulated cruft: */
2452
+ /* Remove any other accumulated cruft */
2443
2453
do_for_each_entry_in_dir (packed , 0 , curate_packed_ref_fn , & refs_to_delete );
2444
2454
for_each_string_list_item (ref_to_delete , & refs_to_delete ) {
2445
2455
if (remove_entry (packed , ref_to_delete -> string ) == -1 )
2446
2456
die ("internal error" );
2447
2457
}
2448
2458
2449
- /* Write what remains: */
2459
+ /* Write what remains */
2450
2460
return commit_packed_refs ();
2451
2461
}
2452
2462
2463
+ static int repack_without_ref (const char * refname )
2464
+ {
2465
+ return repack_without_refs (& refname , 1 );
2466
+ }
2467
+
2453
2468
static int delete_ref_loose (struct ref_lock * lock , int flag )
2454
2469
{
2455
2470
if (!(flag & REF_ISPACKED ) || flag & REF_ISSYMREF ) {
0 commit comments