@@ -43,7 +43,7 @@ struct expire_reflog_policy_cb {
4343 } unreachable_expire_kind ;
4444 struct commit_list * mark_list ;
4545 unsigned long mark_limit ;
46- struct cmd_reflog_expire_cb * cmd ;
46+ struct cmd_reflog_expire_cb cmd ;
4747 struct commit * tip_commit ;
4848 struct commit_list * tips ;
4949};
@@ -309,22 +309,22 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
309309 struct expire_reflog_policy_cb * cb = cb_data ;
310310 struct commit * old , * new ;
311311
312- if (timestamp < cb -> cmd -> expire_total )
312+ if (timestamp < cb -> cmd . expire_total )
313313 return 1 ;
314314
315315 old = new = NULL ;
316- if (cb -> cmd -> stalefix &&
316+ if (cb -> cmd . stalefix &&
317317 (!keep_entry (& old , osha1 ) || !keep_entry (& new , nsha1 )))
318318 return 1 ;
319319
320- if (timestamp < cb -> cmd -> expire_unreachable ) {
320+ if (timestamp < cb -> cmd . expire_unreachable ) {
321321 if (cb -> unreachable_expire_kind == UE_ALWAYS )
322322 return 1 ;
323323 if (unreachable (cb , old , osha1 ) || unreachable (cb , new , nsha1 ))
324324 return 1 ;
325325 }
326326
327- if (cb -> cmd -> recno && -- (cb -> cmd -> recno ) == 0 )
327+ if (cb -> cmd . recno && -- (cb -> cmd . recno ) == 0 )
328328 return 1 ;
329329
330330 return 0 ;
@@ -378,9 +378,11 @@ static int push_tip_to_list(const char *refname, const unsigned char *sha1,
378378
379379static void reflog_expiry_prepare (const char * refname ,
380380 const unsigned char * sha1 ,
381- struct expire_reflog_policy_cb * cb )
381+ void * cb_data )
382382{
383- if (!cb -> cmd -> expire_unreachable || !strcmp (refname , "HEAD" )) {
383+ struct expire_reflog_policy_cb * cb = cb_data ;
384+
385+ if (!cb -> cmd .expire_unreachable || !strcmp (refname , "HEAD" )) {
384386 cb -> tip_commit = NULL ;
385387 cb -> unreachable_expire_kind = UE_HEAD ;
386388 } else {
@@ -391,7 +393,7 @@ static void reflog_expiry_prepare(const char *refname,
391393 cb -> unreachable_expire_kind = UE_NORMAL ;
392394 }
393395
394- if (cb -> cmd -> expire_unreachable <= cb -> cmd -> expire_total )
396+ if (cb -> cmd . expire_unreachable <= cb -> cmd . expire_total )
395397 cb -> unreachable_expire_kind = UE_ALWAYS ;
396398
397399 cb -> mark_list = NULL ;
@@ -405,13 +407,15 @@ static void reflog_expiry_prepare(const char *refname,
405407 } else {
406408 commit_list_insert (cb -> tip_commit , & cb -> mark_list );
407409 }
408- cb -> mark_limit = cb -> cmd -> expire_total ;
410+ cb -> mark_limit = cb -> cmd . expire_total ;
409411 mark_reachable (cb );
410412 }
411413}
412414
413- static void reflog_expiry_cleanup (struct expire_reflog_policy_cb * cb )
415+ static void reflog_expiry_cleanup (void * cb_data )
414416{
417+ struct expire_reflog_policy_cb * cb = cb_data ;
418+
415419 if (cb -> unreachable_expire_kind != UE_ALWAYS ) {
416420 if (cb -> unreachable_expire_kind == UE_HEAD ) {
417421 struct commit_list * elem ;
@@ -425,19 +429,17 @@ static void reflog_expiry_cleanup(struct expire_reflog_policy_cb *cb)
425429}
426430
427431static int expire_reflog (const char * refname , const unsigned char * sha1 ,
428- unsigned int flags , struct cmd_reflog_expire_cb * cmd )
432+ unsigned int flags , void * policy_cb_data )
429433{
430434 static struct lock_file reflog_lock ;
431435 struct expire_reflog_cb cb ;
432- struct expire_reflog_policy_cb policy_cb ;
433436 struct ref_lock * lock ;
434437 char * log_file ;
435438 int status = 0 ;
436439
437440 memset (& cb , 0 , sizeof (cb ));
438- memset (& policy_cb , 0 , sizeof (policy_cb ));
439441 cb .flags = flags ;
440- cb .policy_cb = & policy_cb ;
442+ cb .policy_cb = policy_cb_data ;
441443
442444 /*
443445 * The reflog file is locked by holding the lock on the
@@ -476,11 +478,9 @@ static int expire_reflog(const char *refname, const unsigned char *sha1,
476478 }
477479 }
478480
479- policy_cb .cmd = cmd ;
480-
481- reflog_expiry_prepare (refname , sha1 , & policy_cb );
481+ reflog_expiry_prepare (refname , sha1 , cb .policy_cb );
482482 for_each_reflog_ent (refname , expire_reflog_ent , & cb );
483- reflog_expiry_cleanup (& policy_cb );
483+ reflog_expiry_cleanup (cb . policy_cb );
484484
485485 if (!(flags & EXPIRE_REFLOGS_DRY_RUN )) {
486486 if (close_lock_file (& reflog_lock )) {
@@ -653,7 +653,7 @@ static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, c
653653
654654static int cmd_reflog_expire (int argc , const char * * argv , const char * prefix )
655655{
656- struct cmd_reflog_expire_cb cb ;
656+ struct expire_reflog_policy_cb cb ;
657657 unsigned long now = time (NULL );
658658 int i , status , do_all ;
659659 int explicit_expiry = 0 ;
@@ -667,25 +667,25 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
667667 do_all = status = 0 ;
668668 memset (& cb , 0 , sizeof (cb ));
669669
670- cb .expire_total = default_reflog_expire ;
671- cb .expire_unreachable = default_reflog_expire_unreachable ;
670+ cb .cmd . expire_total = default_reflog_expire ;
671+ cb .cmd . expire_unreachable = default_reflog_expire_unreachable ;
672672
673673 for (i = 1 ; i < argc ; i ++ ) {
674674 const char * arg = argv [i ];
675675 if (!strcmp (arg , "--dry-run" ) || !strcmp (arg , "-n" ))
676676 flags |= EXPIRE_REFLOGS_DRY_RUN ;
677677 else if (starts_with (arg , "--expire=" )) {
678- if (parse_expiry_date (arg + 9 , & cb .expire_total ))
678+ if (parse_expiry_date (arg + 9 , & cb .cmd . expire_total ))
679679 die (_ ("'%s' is not a valid timestamp" ), arg );
680680 explicit_expiry |= EXPIRE_TOTAL ;
681681 }
682682 else if (starts_with (arg , "--expire-unreachable=" )) {
683- if (parse_expiry_date (arg + 21 , & cb .expire_unreachable ))
683+ if (parse_expiry_date (arg + 21 , & cb .cmd . expire_unreachable ))
684684 die (_ ("'%s' is not a valid timestamp" ), arg );
685685 explicit_expiry |= EXPIRE_UNREACH ;
686686 }
687687 else if (!strcmp (arg , "--stale-fix" ))
688- cb .stalefix = 1 ;
688+ cb .cmd . stalefix = 1 ;
689689 else if (!strcmp (arg , "--rewrite" ))
690690 flags |= EXPIRE_REFLOGS_REWRITE ;
691691 else if (!strcmp (arg , "--updateref" ))
@@ -709,11 +709,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
709709 * even in older repository. We cannot trust what's reachable
710710 * from reflog if the repository was pruned with older git.
711711 */
712- if (cb .stalefix ) {
713- init_revisions (& cb .revs , prefix );
712+ if (cb .cmd . stalefix ) {
713+ init_revisions (& cb .cmd . revs , prefix );
714714 if (flags & EXPIRE_REFLOGS_VERBOSE )
715715 printf ("Marking reachable objects..." );
716- mark_reachable_objects (& cb .revs , 0 , 0 , NULL );
716+ mark_reachable_objects (& cb .cmd . revs , 0 , 0 , NULL );
717717 if (flags & EXPIRE_REFLOGS_VERBOSE )
718718 putchar ('\n' );
719719 }
@@ -726,7 +726,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
726726 for_each_reflog (collect_reflog , & collected );
727727 for (i = 0 ; i < collected .nr ; i ++ ) {
728728 struct collected_reflog * e = collected .e [i ];
729- set_reflog_expiry_param (& cb , explicit_expiry , e -> reflog );
729+ set_reflog_expiry_param (& cb . cmd , explicit_expiry , e -> reflog );
730730 status |= expire_reflog (e -> reflog , e -> sha1 , flags , & cb );
731731 free (e );
732732 }
@@ -740,7 +740,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
740740 status |= error ("%s points nowhere!" , argv [i ]);
741741 continue ;
742742 }
743- set_reflog_expiry_param (& cb , explicit_expiry , ref );
743+ set_reflog_expiry_param (& cb . cmd , explicit_expiry , ref );
744744 status |= expire_reflog (ref , sha1 , flags , & cb );
745745 }
746746 return status ;
@@ -750,15 +750,15 @@ static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
750750 const char * email , unsigned long timestamp , int tz ,
751751 const char * message , void * cb_data )
752752{
753- struct cmd_reflog_expire_cb * cb = cb_data ;
754- if (!cb -> expire_total || timestamp < cb -> expire_total )
755- cb -> recno ++ ;
753+ struct expire_reflog_policy_cb * cb = cb_data ;
754+ if (!cb -> cmd . expire_total || timestamp < cb -> cmd . expire_total )
755+ cb -> cmd . recno ++ ;
756756 return 0 ;
757757}
758758
759759static int cmd_reflog_delete (int argc , const char * * argv , const char * prefix )
760760{
761- struct cmd_reflog_expire_cb cb ;
761+ struct expire_reflog_policy_cb cb ;
762762 int i , status = 0 ;
763763 unsigned int flags = 0 ;
764764
@@ -805,12 +805,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
805805
806806 recno = strtoul (spec + 2 , & ep , 10 );
807807 if (* ep == '}' ) {
808- cb .recno = - recno ;
808+ cb .cmd . recno = - recno ;
809809 for_each_reflog_ent (ref , count_reflog_ent , & cb );
810810 } else {
811- cb .expire_total = approxidate (spec + 2 );
811+ cb .cmd . expire_total = approxidate (spec + 2 );
812812 for_each_reflog_ent (ref , count_reflog_ent , & cb );
813- cb .expire_total = 0 ;
813+ cb .cmd . expire_total = 0 ;
814814 }
815815
816816 status |= expire_reflog (ref , sha1 , flags , & cb );
0 commit comments