@@ -242,9 +242,13 @@ static enum schedule_priority parse_schedule(const char *value)
242
242
243
243
struct maintenance_run_opts {
244
244
int auto_flag ;
245
+ int detach ;
245
246
int quiet ;
246
247
enum schedule_priority schedule ;
247
248
};
249
+ #define MAINTENANCE_RUN_OPTS_INIT { \
250
+ .detach = -1, \
251
+ }
248
252
249
253
static int pack_refs_condition (UNUSED struct gc_config * cfg )
250
254
{
@@ -664,7 +668,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
664
668
int keep_largest_pack = -1 ;
665
669
timestamp_t dummy ;
666
670
struct child_process rerere_cmd = CHILD_PROCESS_INIT ;
667
- struct maintenance_run_opts opts = { 0 } ;
671
+ struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT ;
668
672
struct gc_config cfg = GC_CONFIG_INIT ;
669
673
const char * prune_expire_sentinel = "sentinel" ;
670
674
const char * prune_expire_arg = prune_expire_sentinel ;
@@ -681,6 +685,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
681
685
OPT_BOOL (0 , "aggressive" , & aggressive , N_ ("be more thorough (increased runtime)" )),
682
686
OPT_BOOL_F (0 , "auto" , & opts .auto_flag , N_ ("enable auto-gc mode" ),
683
687
PARSE_OPT_NOCOMPLETE ),
688
+ OPT_BOOL (0 , "detach" , & opts .detach ,
689
+ N_ ("perform garbage collection in the background" )),
684
690
OPT_BOOL_F (0 , "force" , & force ,
685
691
N_ ("force running gc even if there may be another gc running" ),
686
692
PARSE_OPT_NOCOMPLETE ),
@@ -729,6 +735,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
729
735
strvec_push (& repack , "-q" );
730
736
731
737
if (opts .auto_flag ) {
738
+ if (cfg .detach_auto && opts .detach < 0 )
739
+ opts .detach = 1 ;
740
+
732
741
/*
733
742
* Auto-gc should be least intrusive as possible.
734
743
*/
@@ -738,38 +747,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
738
747
}
739
748
740
749
if (!quiet ) {
741
- if (cfg . detach_auto )
750
+ if (opts . detach > 0 )
742
751
fprintf (stderr , _ ("Auto packing the repository in background for optimum performance.\n" ));
743
752
else
744
753
fprintf (stderr , _ ("Auto packing the repository for optimum performance.\n" ));
745
754
fprintf (stderr , _ ("See \"git help gc\" for manual housekeeping.\n" ));
746
755
}
747
- if (cfg .detach_auto ) {
748
- ret = report_last_gc_error ();
749
- if (ret == 1 ) {
750
- /* Last gc --auto failed. Skip this one. */
751
- ret = 0 ;
752
- goto out ;
753
-
754
- } else if (ret ) {
755
- /* an I/O error occurred, already reported */
756
- goto out ;
757
- }
758
-
759
- if (lock_repo_for_gc (force , & pid )) {
760
- ret = 0 ;
761
- goto out ;
762
- }
763
-
764
- gc_before_repack (& opts , & cfg ); /* dies on failure */
765
- delete_tempfile (& pidfile );
766
-
767
- /*
768
- * failure to daemonize is ok, we'll continue
769
- * in foreground
770
- */
771
- daemonized = !daemonize ();
772
- }
773
756
} else {
774
757
struct string_list keep_pack = STRING_LIST_INIT_NODUP ;
775
758
@@ -784,6 +767,33 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
784
767
string_list_clear (& keep_pack , 0 );
785
768
}
786
769
770
+ if (opts .detach > 0 ) {
771
+ ret = report_last_gc_error ();
772
+ if (ret == 1 ) {
773
+ /* Last gc --auto failed. Skip this one. */
774
+ ret = 0 ;
775
+ goto out ;
776
+
777
+ } else if (ret ) {
778
+ /* an I/O error occurred, already reported */
779
+ goto out ;
780
+ }
781
+
782
+ if (lock_repo_for_gc (force , & pid )) {
783
+ ret = 0 ;
784
+ goto out ;
785
+ }
786
+
787
+ gc_before_repack (& opts , & cfg ); /* dies on failure */
788
+ delete_tempfile (& pidfile );
789
+
790
+ /*
791
+ * failure to daemonize is ok, we'll continue
792
+ * in foreground
793
+ */
794
+ daemonized = !daemonize ();
795
+ }
796
+
787
797
name = lock_repo_for_gc (force , & pid );
788
798
if (name ) {
789
799
if (opts .auto_flag ) {
@@ -1537,7 +1547,7 @@ static int task_option_parse(const struct option *opt UNUSED,
1537
1547
static int maintenance_run (int argc , const char * * argv , const char * prefix )
1538
1548
{
1539
1549
int i ;
1540
- struct maintenance_run_opts opts ;
1550
+ struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT ;
1541
1551
struct gc_config cfg = GC_CONFIG_INIT ;
1542
1552
struct option builtin_maintenance_run_options [] = {
1543
1553
OPT_BOOL (0 , "auto" , & opts .auto_flag ,
@@ -1554,8 +1564,6 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
1554
1564
};
1555
1565
int ret ;
1556
1566
1557
- memset (& opts , 0 , sizeof (opts ));
1558
-
1559
1567
opts .quiet = !isatty (2 );
1560
1568
1561
1569
for (i = 0 ; i < TASK__COUNT ; i ++ )
0 commit comments