@@ -45,6 +45,7 @@ struct expire_reflog_policy_cb {
45
45
struct cmd_reflog_expire_cb cmd ;
46
46
struct commit * tip_commit ;
47
47
struct commit_list * tips ;
48
+ unsigned int dry_run :1 ;
48
49
};
49
50
50
51
struct worktree_reflogs {
@@ -319,6 +320,28 @@ static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *no
319
320
return 0 ;
320
321
}
321
322
323
+ static int should_expire_reflog_ent_verbose (struct object_id * ooid ,
324
+ struct object_id * noid ,
325
+ const char * email ,
326
+ timestamp_t timestamp , int tz ,
327
+ const char * message , void * cb_data )
328
+ {
329
+ struct expire_reflog_policy_cb * cb = cb_data ;
330
+ int expire ;
331
+
332
+ expire = should_expire_reflog_ent (ooid , noid , email , timestamp , tz ,
333
+ message , cb );
334
+
335
+ if (!expire )
336
+ printf ("keep %s" , message );
337
+ else if (cb -> dry_run )
338
+ printf ("would prune %s" , message );
339
+ else
340
+ printf ("prune %s" , message );
341
+
342
+ return expire ;
343
+ }
344
+
322
345
static int push_tip_to_list (const char * refname , const struct object_id * oid ,
323
346
int flags , void * cb_data )
324
347
{
@@ -539,6 +562,8 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
539
562
int i , status , do_all , all_worktrees = 1 ;
540
563
int explicit_expiry = 0 ;
541
564
unsigned int flags = 0 ;
565
+ int verbose = 0 ;
566
+ reflog_expiry_should_prune_fn * should_prune_fn = should_expire_reflog_ent ;
542
567
543
568
default_reflog_expire_unreachable = now - 30 * 24 * 3600 ;
544
569
default_reflog_expire = now - 90 * 24 * 3600 ;
@@ -576,7 +601,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
576
601
else if (!strcmp (arg , "--single-worktree" ))
577
602
all_worktrees = 0 ;
578
603
else if (!strcmp (arg , "--verbose" ))
579
- flags |= EXPIRE_REFLOGS_VERBOSE ;
604
+ verbose = 1 ;
580
605
else if (!strcmp (arg , "--" )) {
581
606
i ++ ;
582
607
break ;
@@ -587,6 +612,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
587
612
break ;
588
613
}
589
614
615
+ if (verbose )
616
+ should_prune_fn = should_expire_reflog_ent_verbose ;
617
+
590
618
/*
591
619
* We can trust the commits and objects reachable from refs
592
620
* even in older repository. We cannot trust what's reachable
@@ -599,10 +627,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
599
627
revs .do_not_die_on_missing_tree = 1 ;
600
628
revs .ignore_missing = 1 ;
601
629
revs .ignore_missing_links = 1 ;
602
- if (flags & EXPIRE_REFLOGS_VERBOSE )
630
+ if (verbose )
603
631
printf (_ ("Marking reachable objects..." ));
604
632
mark_reachable_objects (& revs , 0 , 0 , NULL );
605
- if (flags & EXPIRE_REFLOGS_VERBOSE )
633
+ if (verbose )
606
634
putchar ('\n' );
607
635
}
608
636
@@ -624,12 +652,15 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
624
652
free_worktrees (worktrees );
625
653
626
654
for_each_string_list_item (item , & collected .reflogs ) {
627
- struct expire_reflog_policy_cb cb = { .cmd = cmd };
655
+ struct expire_reflog_policy_cb cb = {
656
+ .cmd = cmd ,
657
+ .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN ),
658
+ };
628
659
629
660
set_reflog_expiry_param (& cb .cmd , explicit_expiry , item -> string );
630
661
status |= reflog_expire (item -> string , flags ,
631
662
reflog_expiry_prepare ,
632
- should_expire_reflog_ent ,
663
+ should_prune_fn ,
633
664
reflog_expiry_cleanup ,
634
665
& cb );
635
666
}
@@ -647,7 +678,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
647
678
set_reflog_expiry_param (& cb .cmd , explicit_expiry , ref );
648
679
status |= reflog_expire (ref , flags ,
649
680
reflog_expiry_prepare ,
650
- should_expire_reflog_ent ,
681
+ should_prune_fn ,
651
682
reflog_expiry_cleanup ,
652
683
& cb );
653
684
free (ref );
@@ -670,6 +701,8 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
670
701
struct cmd_reflog_expire_cb cmd = { 0 };
671
702
int i , status = 0 ;
672
703
unsigned int flags = 0 ;
704
+ int verbose = 0 ;
705
+ reflog_expiry_should_prune_fn * should_prune_fn = should_expire_reflog_ent ;
673
706
674
707
for (i = 1 ; i < argc ; i ++ ) {
675
708
const char * arg = argv [i ];
@@ -680,7 +713,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
680
713
else if (!strcmp (arg , "--updateref" ))
681
714
flags |= EXPIRE_REFLOGS_UPDATE_REF ;
682
715
else if (!strcmp (arg , "--verbose" ))
683
- flags |= EXPIRE_REFLOGS_VERBOSE ;
716
+ verbose = 1 ;
684
717
else if (!strcmp (arg , "--" )) {
685
718
i ++ ;
686
719
break ;
@@ -691,14 +724,19 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
691
724
break ;
692
725
}
693
726
727
+ if (verbose )
728
+ should_prune_fn = should_expire_reflog_ent_verbose ;
729
+
694
730
if (argc - i < 1 )
695
731
return error (_ ("no reflog specified to delete" ));
696
732
697
733
for ( ; i < argc ; i ++ ) {
698
734
const char * spec = strstr (argv [i ], "@{" );
699
735
char * ep , * ref ;
700
736
int recno ;
701
- struct expire_reflog_policy_cb cb = { 0 };
737
+ struct expire_reflog_policy_cb cb = {
738
+ .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN ),
739
+ };
702
740
703
741
if (!spec ) {
704
742
status |= error (_ ("not a reflog: %s" ), argv [i ]);
@@ -723,7 +761,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
723
761
cb .cmd = cmd ;
724
762
status |= reflog_expire (ref , flags ,
725
763
reflog_expiry_prepare ,
726
- should_expire_reflog_ent ,
764
+ should_prune_fn ,
727
765
reflog_expiry_cleanup ,
728
766
& cb );
729
767
free (ref );
0 commit comments