@@ -212,6 +212,9 @@ static int maintenance_task_pack_refs(MAYBE_UNUSED struct maintenance_run_opts *
212
212
213
213
cmd .git_cmd = 1 ;
214
214
strvec_pushl (& cmd .args , "pack-refs" , "--all" , "--prune" , NULL );
215
+ if (opts -> auto_flag )
216
+ strvec_push (& cmd .args , "--auto" );
217
+
215
218
return run_command (& cmd );
216
219
}
217
220
@@ -572,7 +575,7 @@ static int report_last_gc_error(void)
572
575
return ret ;
573
576
}
574
577
575
- static void gc_before_repack (void )
578
+ static void gc_before_repack (struct maintenance_run_opts * opts )
576
579
{
577
580
/*
578
581
* We may be called twice, as both the pre- and
@@ -583,7 +586,7 @@ static void gc_before_repack(void)
583
586
if (done ++ )
584
587
return ;
585
588
586
- if (pack_refs && maintenance_task_pack_refs (NULL ))
589
+ if (pack_refs && maintenance_task_pack_refs (opts ))
587
590
die (FAILED_RUN , "pack-refs" );
588
591
589
592
if (prune_reflogs ) {
@@ -599,7 +602,6 @@ static void gc_before_repack(void)
599
602
int cmd_gc (int argc , const char * * argv , const char * prefix )
600
603
{
601
604
int aggressive = 0 ;
602
- int auto_gc = 0 ;
603
605
int quiet = 0 ;
604
606
int force = 0 ;
605
607
const char * name ;
@@ -608,6 +610,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
608
610
int keep_largest_pack = -1 ;
609
611
timestamp_t dummy ;
610
612
struct child_process rerere_cmd = CHILD_PROCESS_INIT ;
613
+ struct maintenance_run_opts opts = {0 };
611
614
612
615
struct option builtin_gc_options [] = {
613
616
OPT__QUIET (& quiet , N_ ("suppress progress reporting" )),
@@ -618,7 +621,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
618
621
OPT_MAGNITUDE (0 , "max-cruft-size" , & max_cruft_size ,
619
622
N_ ("with --cruft, limit the size of new cruft packs" )),
620
623
OPT_BOOL (0 , "aggressive" , & aggressive , N_ ("be more thorough (increased runtime)" )),
621
- OPT_BOOL_F (0 , "auto" , & auto_gc , N_ ("enable auto-gc mode" ),
624
+ OPT_BOOL_F (0 , "auto" , & opts . auto_flag , N_ ("enable auto-gc mode" ),
622
625
PARSE_OPT_NOCOMPLETE ),
623
626
OPT_BOOL_F (0 , "force" , & force ,
624
627
N_ ("force running gc even if there may be another gc running" ),
@@ -663,7 +666,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
663
666
if (quiet )
664
667
strvec_push (& repack , "-q" );
665
668
666
- if (auto_gc ) {
669
+ if (opts . auto_flag ) {
667
670
/*
668
671
* Auto-gc should be least intrusive as possible.
669
672
*/
@@ -688,7 +691,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
688
691
689
692
if (lock_repo_for_gc (force , & pid ))
690
693
return 0 ;
691
- gc_before_repack (); /* dies on failure */
694
+ gc_before_repack (& opts ); /* dies on failure */
692
695
delete_tempfile (& pidfile );
693
696
694
697
/*
@@ -713,7 +716,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
713
716
714
717
name = lock_repo_for_gc (force , & pid );
715
718
if (name ) {
716
- if (auto_gc )
719
+ if (opts . auto_flag )
717
720
return 0 ; /* be quiet on --auto */
718
721
die (_ ("gc is already running on machine '%s' pid %" PRIuMAX " (use --force if not)" ),
719
722
name , (uintmax_t )pid );
@@ -728,7 +731,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
728
731
atexit (process_log_file_at_exit );
729
732
}
730
733
731
- gc_before_repack ();
734
+ gc_before_repack (& opts );
732
735
733
736
if (!repository_format_precious_objects ) {
734
737
struct child_process repack_cmd = CHILD_PROCESS_INIT ;
@@ -783,7 +786,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
783
786
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0 ,
784
787
NULL );
785
788
786
- if (auto_gc && too_many_loose_objects ())
789
+ if (opts . auto_flag && too_many_loose_objects ())
787
790
warning (_ ("There are too many unreachable loose objects; "
788
791
"run 'git prune' to remove them." ));
789
792
0 commit comments