@@ -180,13 +180,51 @@ static void gc_config(void)
180180 git_config (git_default_config , NULL );
181181}
182182
183- struct maintenance_run_opts ;
183+ enum schedule_priority {
184+ SCHEDULE_NONE = 0 ,
185+ SCHEDULE_WEEKLY = 1 ,
186+ SCHEDULE_DAILY = 2 ,
187+ SCHEDULE_HOURLY = 3 ,
188+ };
189+
190+ static enum schedule_priority parse_schedule (const char * value )
191+ {
192+ if (!value )
193+ return SCHEDULE_NONE ;
194+ if (!strcasecmp (value , "hourly" ))
195+ return SCHEDULE_HOURLY ;
196+ if (!strcasecmp (value , "daily" ))
197+ return SCHEDULE_DAILY ;
198+ if (!strcasecmp (value , "weekly" ))
199+ return SCHEDULE_WEEKLY ;
200+ return SCHEDULE_NONE ;
201+ }
202+
203+ struct maintenance_run_opts {
204+ int auto_flag ;
205+ int quiet ;
206+ enum schedule_priority schedule ;
207+ };
208+
209+ static int pack_refs_condition (void )
210+ {
211+ /*
212+ * The auto-repacking logic for refs is handled by the ref backends and
213+ * exposed via `git pack-refs --auto`. We thus always return truish
214+ * here and let the backend decide for us.
215+ */
216+ return 1 ;
217+ }
218+
184219static int maintenance_task_pack_refs (MAYBE_UNUSED struct maintenance_run_opts * opts )
185220{
186221 struct child_process cmd = CHILD_PROCESS_INIT ;
187222
188223 cmd .git_cmd = 1 ;
189224 strvec_pushl (& cmd .args , "pack-refs" , "--all" , "--prune" , NULL );
225+ if (opts -> auto_flag )
226+ strvec_push (& cmd .args , "--auto" );
227+
190228 return run_command (& cmd );
191229}
192230
@@ -547,7 +585,7 @@ static int report_last_gc_error(void)
547585 return ret ;
548586}
549587
550- static void gc_before_repack (void )
588+ static void gc_before_repack (struct maintenance_run_opts * opts )
551589{
552590 /*
553591 * We may be called twice, as both the pre- and
@@ -558,7 +596,7 @@ static void gc_before_repack(void)
558596 if (done ++ )
559597 return ;
560598
561- if (pack_refs && maintenance_task_pack_refs (NULL ))
599+ if (pack_refs && maintenance_task_pack_refs (opts ))
562600 die (FAILED_RUN , "pack-refs" );
563601
564602 if (prune_reflogs ) {
@@ -574,7 +612,6 @@ static void gc_before_repack(void)
574612int cmd_gc (int argc , const char * * argv , const char * prefix )
575613{
576614 int aggressive = 0 ;
577- int auto_gc = 0 ;
578615 int quiet = 0 ;
579616 int force = 0 ;
580617 const char * name ;
@@ -583,6 +620,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
583620 int keep_largest_pack = -1 ;
584621 timestamp_t dummy ;
585622 struct child_process rerere_cmd = CHILD_PROCESS_INIT ;
623+ struct maintenance_run_opts opts = {0 };
586624
587625 struct option builtin_gc_options [] = {
588626 OPT__QUIET (& quiet , N_ ("suppress progress reporting" )),
@@ -593,7 +631,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
593631 OPT_MAGNITUDE (0 , "max-cruft-size" , & max_cruft_size ,
594632 N_ ("with --cruft, limit the size of new cruft packs" )),
595633 OPT_BOOL (0 , "aggressive" , & aggressive , N_ ("be more thorough (increased runtime)" )),
596- OPT_BOOL_F (0 , "auto" , & auto_gc , N_ ("enable auto-gc mode" ),
634+ OPT_BOOL_F (0 , "auto" , & opts . auto_flag , N_ ("enable auto-gc mode" ),
597635 PARSE_OPT_NOCOMPLETE ),
598636 OPT_BOOL_F (0 , "force" , & force ,
599637 N_ ("force running gc even if there may be another gc running" ),
@@ -638,7 +676,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
638676 if (quiet )
639677 strvec_push (& repack , "-q" );
640678
641- if (auto_gc ) {
679+ if (opts . auto_flag ) {
642680 /*
643681 * Auto-gc should be least intrusive as possible.
644682 */
@@ -663,7 +701,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
663701
664702 if (lock_repo_for_gc (force , & pid ))
665703 return 0 ;
666- gc_before_repack (); /* dies on failure */
704+ gc_before_repack (& opts ); /* dies on failure */
667705 delete_tempfile (& pidfile );
668706
669707 /*
@@ -688,7 +726,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
688726
689727 name = lock_repo_for_gc (force , & pid );
690728 if (name ) {
691- if (auto_gc )
729+ if (opts . auto_flag )
692730 return 0 ; /* be quiet on --auto */
693731 die (_ ("gc is already running on machine '%s' pid %" PRIuMAX " (use --force if not)" ),
694732 name , (uintmax_t )pid );
@@ -703,7 +741,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
703741 atexit (process_log_file_at_exit );
704742 }
705743
706- gc_before_repack ();
744+ gc_before_repack (& opts );
707745
708746 if (!repository_format_precious_objects ) {
709747 struct child_process repack_cmd = CHILD_PROCESS_INIT ;
@@ -758,7 +796,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
758796 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0 ,
759797 NULL );
760798
761- if (auto_gc && too_many_loose_objects ())
799+ if (opts . auto_flag && too_many_loose_objects ())
762800 warning (_ ("There are too many unreachable loose objects; "
763801 "run 'git prune' to remove them." ));
764802
@@ -773,26 +811,6 @@ static const char *const builtin_maintenance_run_usage[] = {
773811 NULL
774812};
775813
776- enum schedule_priority {
777- SCHEDULE_NONE = 0 ,
778- SCHEDULE_WEEKLY = 1 ,
779- SCHEDULE_DAILY = 2 ,
780- SCHEDULE_HOURLY = 3 ,
781- };
782-
783- static enum schedule_priority parse_schedule (const char * value )
784- {
785- if (!value )
786- return SCHEDULE_NONE ;
787- if (!strcasecmp (value , "hourly" ))
788- return SCHEDULE_HOURLY ;
789- if (!strcasecmp (value , "daily" ))
790- return SCHEDULE_DAILY ;
791- if (!strcasecmp (value , "weekly" ))
792- return SCHEDULE_WEEKLY ;
793- return SCHEDULE_NONE ;
794- }
795-
796814static int maintenance_opt_schedule (const struct option * opt , const char * arg ,
797815 int unset )
798816{
@@ -809,12 +827,6 @@ static int maintenance_opt_schedule(const struct option *opt, const char *arg,
809827 return 0 ;
810828}
811829
812- struct maintenance_run_opts {
813- int auto_flag ;
814- int quiet ;
815- enum schedule_priority schedule ;
816- };
817-
818830/* Remember to update object flag allocation in object.h */
819831#define SEEN (1u<<0)
820832
@@ -1296,7 +1308,7 @@ static struct maintenance_task tasks[] = {
12961308 [TASK_PACK_REFS ] = {
12971309 "pack-refs" ,
12981310 maintenance_task_pack_refs ,
1299- NULL ,
1311+ pack_refs_condition ,
13001312 },
13011313};
13021314
0 commit comments