@@ -43,6 +43,8 @@ struct expire_reflog_cb {
43
43
unsigned long mark_limit ;
44
44
struct cmd_reflog_expire_cb * cmd ;
45
45
unsigned char last_kept_sha1 [20 ];
46
+ struct commit * tip_commit ;
47
+ struct commit_list * tips ;
46
48
};
47
49
48
50
struct collected_reflog {
@@ -363,15 +365,61 @@ static int push_tip_to_list(const char *refname, const unsigned char *sha1, int
363
365
return 0 ;
364
366
}
365
367
368
+ static void reflog_expiry_prepare (const char * refname ,
369
+ const unsigned char * sha1 ,
370
+ struct expire_reflog_cb * cb )
371
+ {
372
+ if (!cb -> cmd -> expire_unreachable || !strcmp (refname , "HEAD" )) {
373
+ cb -> tip_commit = NULL ;
374
+ cb -> unreachable_expire_kind = UE_HEAD ;
375
+ } else {
376
+ cb -> tip_commit = lookup_commit_reference_gently (sha1 , 1 );
377
+ if (!cb -> tip_commit )
378
+ cb -> unreachable_expire_kind = UE_ALWAYS ;
379
+ else
380
+ cb -> unreachable_expire_kind = UE_NORMAL ;
381
+ }
382
+
383
+ if (cb -> cmd -> expire_unreachable <= cb -> cmd -> expire_total )
384
+ cb -> unreachable_expire_kind = UE_ALWAYS ;
385
+
386
+ cb -> mark_list = NULL ;
387
+ cb -> tips = NULL ;
388
+ if (cb -> unreachable_expire_kind != UE_ALWAYS ) {
389
+ if (cb -> unreachable_expire_kind == UE_HEAD ) {
390
+ struct commit_list * elem ;
391
+ for_each_ref (push_tip_to_list , & cb -> tips );
392
+ for (elem = cb -> tips ; elem ; elem = elem -> next )
393
+ commit_list_insert (elem -> item , & cb -> mark_list );
394
+ } else {
395
+ commit_list_insert (cb -> tip_commit , & cb -> mark_list );
396
+ }
397
+ cb -> mark_limit = cb -> cmd -> expire_total ;
398
+ mark_reachable (cb );
399
+ }
400
+ }
401
+
402
+ static void reflog_expiry_cleanup (struct expire_reflog_cb * cb )
403
+ {
404
+ if (cb -> unreachable_expire_kind != UE_ALWAYS ) {
405
+ if (cb -> unreachable_expire_kind == UE_HEAD ) {
406
+ struct commit_list * elem ;
407
+ for (elem = cb -> tips ; elem ; elem = elem -> next )
408
+ clear_commit_marks (elem -> item , REACHABLE );
409
+ free_commit_list (cb -> tips );
410
+ } else {
411
+ clear_commit_marks (cb -> tip_commit , REACHABLE );
412
+ }
413
+ }
414
+ }
415
+
366
416
static int expire_reflog (const char * refname , const unsigned char * sha1 ,
367
417
struct cmd_reflog_expire_cb * cmd )
368
418
{
369
419
static struct lock_file reflog_lock ;
370
420
struct expire_reflog_cb cb ;
371
421
struct ref_lock * lock ;
372
422
char * log_file ;
373
- struct commit * tip_commit ;
374
- struct commit_list * tips ;
375
423
int status = 0 ;
376
424
377
425
memset (& cb , 0 , sizeof (cb ));
@@ -415,47 +463,9 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
415
463
416
464
cb .cmd = cmd ;
417
465
418
- if (!cmd -> expire_unreachable || !strcmp (refname , "HEAD" )) {
419
- tip_commit = NULL ;
420
- cb .unreachable_expire_kind = UE_HEAD ;
421
- } else {
422
- tip_commit = lookup_commit_reference_gently (sha1 , 1 );
423
- if (!tip_commit )
424
- cb .unreachable_expire_kind = UE_ALWAYS ;
425
- else
426
- cb .unreachable_expire_kind = UE_NORMAL ;
427
- }
428
-
429
- if (cmd -> expire_unreachable <= cmd -> expire_total )
430
- cb .unreachable_expire_kind = UE_ALWAYS ;
431
-
432
- cb .mark_list = NULL ;
433
- tips = NULL ;
434
- if (cb .unreachable_expire_kind != UE_ALWAYS ) {
435
- if (cb .unreachable_expire_kind == UE_HEAD ) {
436
- struct commit_list * elem ;
437
- for_each_ref (push_tip_to_list , & tips );
438
- for (elem = tips ; elem ; elem = elem -> next )
439
- commit_list_insert (elem -> item , & cb .mark_list );
440
- } else {
441
- commit_list_insert (tip_commit , & cb .mark_list );
442
- }
443
- cb .mark_limit = cmd -> expire_total ;
444
- mark_reachable (& cb );
445
- }
446
-
466
+ reflog_expiry_prepare (refname , sha1 , & cb );
447
467
for_each_reflog_ent (refname , expire_reflog_ent , & cb );
448
-
449
- if (cb .unreachable_expire_kind != UE_ALWAYS ) {
450
- if (cb .unreachable_expire_kind == UE_HEAD ) {
451
- struct commit_list * elem ;
452
- for (elem = tips ; elem ; elem = elem -> next )
453
- clear_commit_marks (elem -> item , REACHABLE );
454
- free_commit_list (tips );
455
- } else {
456
- clear_commit_marks (tip_commit , REACHABLE );
457
- }
458
- }
468
+ reflog_expiry_cleanup (& cb );
459
469
460
470
if (cb .newlog ) {
461
471
if (close_lock_file (& reflog_lock )) {
0 commit comments