@@ -43,7 +43,7 @@ struct expire_reflog_policy_cb {
43
43
} unreachable_expire_kind ;
44
44
struct commit_list * mark_list ;
45
45
unsigned long mark_limit ;
46
- struct cmd_reflog_expire_cb * cmd ;
46
+ struct cmd_reflog_expire_cb cmd ;
47
47
struct commit * tip_commit ;
48
48
struct commit_list * tips ;
49
49
};
@@ -309,22 +309,22 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
309
309
struct expire_reflog_policy_cb * cb = cb_data ;
310
310
struct commit * old , * new ;
311
311
312
- if (timestamp < cb -> cmd -> expire_total )
312
+ if (timestamp < cb -> cmd . expire_total )
313
313
return 1 ;
314
314
315
315
old = new = NULL ;
316
- if (cb -> cmd -> stalefix &&
316
+ if (cb -> cmd . stalefix &&
317
317
(!keep_entry (& old , osha1 ) || !keep_entry (& new , nsha1 )))
318
318
return 1 ;
319
319
320
- if (timestamp < cb -> cmd -> expire_unreachable ) {
320
+ if (timestamp < cb -> cmd . expire_unreachable ) {
321
321
if (cb -> unreachable_expire_kind == UE_ALWAYS )
322
322
return 1 ;
323
323
if (unreachable (cb , old , osha1 ) || unreachable (cb , new , nsha1 ))
324
324
return 1 ;
325
325
}
326
326
327
- if (cb -> cmd -> recno && -- (cb -> cmd -> recno ) == 0 )
327
+ if (cb -> cmd . recno && -- (cb -> cmd . recno ) == 0 )
328
328
return 1 ;
329
329
330
330
return 0 ;
@@ -378,9 +378,11 @@ static int push_tip_to_list(const char *refname, const unsigned char *sha1,
378
378
379
379
static void reflog_expiry_prepare (const char * refname ,
380
380
const unsigned char * sha1 ,
381
- struct expire_reflog_policy_cb * cb )
381
+ void * cb_data )
382
382
{
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" )) {
384
386
cb -> tip_commit = NULL ;
385
387
cb -> unreachable_expire_kind = UE_HEAD ;
386
388
} else {
@@ -391,7 +393,7 @@ static void reflog_expiry_prepare(const char *refname,
391
393
cb -> unreachable_expire_kind = UE_NORMAL ;
392
394
}
393
395
394
- if (cb -> cmd -> expire_unreachable <= cb -> cmd -> expire_total )
396
+ if (cb -> cmd . expire_unreachable <= cb -> cmd . expire_total )
395
397
cb -> unreachable_expire_kind = UE_ALWAYS ;
396
398
397
399
cb -> mark_list = NULL ;
@@ -405,13 +407,15 @@ static void reflog_expiry_prepare(const char *refname,
405
407
} else {
406
408
commit_list_insert (cb -> tip_commit , & cb -> mark_list );
407
409
}
408
- cb -> mark_limit = cb -> cmd -> expire_total ;
410
+ cb -> mark_limit = cb -> cmd . expire_total ;
409
411
mark_reachable (cb );
410
412
}
411
413
}
412
414
413
- static void reflog_expiry_cleanup (struct expire_reflog_policy_cb * cb )
415
+ static void reflog_expiry_cleanup (void * cb_data )
414
416
{
417
+ struct expire_reflog_policy_cb * cb = cb_data ;
418
+
415
419
if (cb -> unreachable_expire_kind != UE_ALWAYS ) {
416
420
if (cb -> unreachable_expire_kind == UE_HEAD ) {
417
421
struct commit_list * elem ;
@@ -425,19 +429,17 @@ static void reflog_expiry_cleanup(struct expire_reflog_policy_cb *cb)
425
429
}
426
430
427
431
static 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 )
429
433
{
430
434
static struct lock_file reflog_lock ;
431
435
struct expire_reflog_cb cb ;
432
- struct expire_reflog_policy_cb policy_cb ;
433
436
struct ref_lock * lock ;
434
437
char * log_file ;
435
438
int status = 0 ;
436
439
437
440
memset (& cb , 0 , sizeof (cb ));
438
- memset (& policy_cb , 0 , sizeof (policy_cb ));
439
441
cb .flags = flags ;
440
- cb .policy_cb = & policy_cb ;
442
+ cb .policy_cb = policy_cb_data ;
441
443
442
444
/*
443
445
* 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,
476
478
}
477
479
}
478
480
479
- policy_cb .cmd = cmd ;
480
-
481
- reflog_expiry_prepare (refname , sha1 , & policy_cb );
481
+ reflog_expiry_prepare (refname , sha1 , cb .policy_cb );
482
482
for_each_reflog_ent (refname , expire_reflog_ent , & cb );
483
- reflog_expiry_cleanup (& policy_cb );
483
+ reflog_expiry_cleanup (cb . policy_cb );
484
484
485
485
if (!(flags & EXPIRE_REFLOGS_DRY_RUN )) {
486
486
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
653
653
654
654
static int cmd_reflog_expire (int argc , const char * * argv , const char * prefix )
655
655
{
656
- struct cmd_reflog_expire_cb cb ;
656
+ struct expire_reflog_policy_cb cb ;
657
657
unsigned long now = time (NULL );
658
658
int i , status , do_all ;
659
659
int explicit_expiry = 0 ;
@@ -667,25 +667,25 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
667
667
do_all = status = 0 ;
668
668
memset (& cb , 0 , sizeof (cb ));
669
669
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 ;
672
672
673
673
for (i = 1 ; i < argc ; i ++ ) {
674
674
const char * arg = argv [i ];
675
675
if (!strcmp (arg , "--dry-run" ) || !strcmp (arg , "-n" ))
676
676
flags |= EXPIRE_REFLOGS_DRY_RUN ;
677
677
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 ))
679
679
die (_ ("'%s' is not a valid timestamp" ), arg );
680
680
explicit_expiry |= EXPIRE_TOTAL ;
681
681
}
682
682
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 ))
684
684
die (_ ("'%s' is not a valid timestamp" ), arg );
685
685
explicit_expiry |= EXPIRE_UNREACH ;
686
686
}
687
687
else if (!strcmp (arg , "--stale-fix" ))
688
- cb .stalefix = 1 ;
688
+ cb .cmd . stalefix = 1 ;
689
689
else if (!strcmp (arg , "--rewrite" ))
690
690
flags |= EXPIRE_REFLOGS_REWRITE ;
691
691
else if (!strcmp (arg , "--updateref" ))
@@ -709,11 +709,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
709
709
* even in older repository. We cannot trust what's reachable
710
710
* from reflog if the repository was pruned with older git.
711
711
*/
712
- if (cb .stalefix ) {
713
- init_revisions (& cb .revs , prefix );
712
+ if (cb .cmd . stalefix ) {
713
+ init_revisions (& cb .cmd . revs , prefix );
714
714
if (flags & EXPIRE_REFLOGS_VERBOSE )
715
715
printf ("Marking reachable objects..." );
716
- mark_reachable_objects (& cb .revs , 0 , 0 , NULL );
716
+ mark_reachable_objects (& cb .cmd . revs , 0 , 0 , NULL );
717
717
if (flags & EXPIRE_REFLOGS_VERBOSE )
718
718
putchar ('\n' );
719
719
}
@@ -726,7 +726,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
726
726
for_each_reflog (collect_reflog , & collected );
727
727
for (i = 0 ; i < collected .nr ; i ++ ) {
728
728
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 );
730
730
status |= expire_reflog (e -> reflog , e -> sha1 , flags , & cb );
731
731
free (e );
732
732
}
@@ -740,7 +740,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
740
740
status |= error ("%s points nowhere!" , argv [i ]);
741
741
continue ;
742
742
}
743
- set_reflog_expiry_param (& cb , explicit_expiry , ref );
743
+ set_reflog_expiry_param (& cb . cmd , explicit_expiry , ref );
744
744
status |= expire_reflog (ref , sha1 , flags , & cb );
745
745
}
746
746
return status ;
@@ -750,15 +750,15 @@ static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
750
750
const char * email , unsigned long timestamp , int tz ,
751
751
const char * message , void * cb_data )
752
752
{
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 ++ ;
756
756
return 0 ;
757
757
}
758
758
759
759
static int cmd_reflog_delete (int argc , const char * * argv , const char * prefix )
760
760
{
761
- struct cmd_reflog_expire_cb cb ;
761
+ struct expire_reflog_policy_cb cb ;
762
762
int i , status = 0 ;
763
763
unsigned int flags = 0 ;
764
764
@@ -805,12 +805,12 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
805
805
806
806
recno = strtoul (spec + 2 , & ep , 10 );
807
807
if (* ep == '}' ) {
808
- cb .recno = - recno ;
808
+ cb .cmd . recno = - recno ;
809
809
for_each_reflog_ent (ref , count_reflog_ent , & cb );
810
810
} else {
811
- cb .expire_total = approxidate (spec + 2 );
811
+ cb .cmd . expire_total = approxidate (spec + 2 );
812
812
for_each_reflog_ent (ref , count_reflog_ent , & cb );
813
- cb .expire_total = 0 ;
813
+ cb .cmd . expire_total = 0 ;
814
814
}
815
815
816
816
status |= expire_reflog (ref , sha1 , flags , & cb );
0 commit comments