@@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure)
209
209
return 0 ;
210
210
}
211
211
212
+ /**
213
+ * Enable or disable the maintenance mode for the current repository:
214
+ *
215
+ * * If 'enable' is nonzero, run 'git maintenance start'.
216
+ * * If 'enable' is zero, run 'git maintenance unregister --force'.
217
+ */
212
218
static int toggle_maintenance (int enable )
213
219
{
214
220
return run_git ("maintenance" ,
@@ -259,16 +265,25 @@ static int stop_fsmonitor_daemon(void)
259
265
return 0 ;
260
266
}
261
267
262
- static int register_dir (void )
268
+ /**
269
+ * Register the current directory as a Scalar enlistment, and set the
270
+ * recommended configuration.
271
+ *
272
+ * * If 'maintenance' is non-zero, then enable background maintenance.
273
+ * * If 'maintenance' is zero, then leave background maintenance as it is
274
+ * currently configured.
275
+ */
276
+ static int register_dir (int maintenance )
263
277
{
264
278
if (add_or_remove_enlistment (1 ))
265
279
return error (_ ("could not add enlistment" ));
266
280
267
281
if (set_recommended_config (0 ))
268
282
return error (_ ("could not set recommended config" ));
269
283
270
- if (toggle_maintenance (1 ))
271
- warning (_ ("could not turn on maintenance" ));
284
+ if (maintenance &&
285
+ toggle_maintenance (maintenance ))
286
+ warning (_ ("could not toggle maintenance" ));
272
287
273
288
if (have_fsmonitor_support () && start_fsmonitor_daemon ()) {
274
289
return error (_ ("could not start the FSMonitor daemon" ));
@@ -411,7 +426,7 @@ static int cmd_clone(int argc, const char **argv)
411
426
const char * branch = NULL ;
412
427
char * branch_to_free = NULL ;
413
428
int full_clone = 0 , single_branch = 0 , show_progress = isatty (2 );
414
- int src = 1 , tags = 1 ;
429
+ int src = 1 , tags = 1 , maintenance = 1 ;
415
430
struct option clone_options [] = {
416
431
OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
417
432
N_ ("branch to checkout after clone" )),
@@ -424,11 +439,13 @@ static int cmd_clone(int argc, const char **argv)
424
439
N_ ("create repository within 'src' directory" )),
425
440
OPT_BOOL (0 , "tags" , & tags ,
426
441
N_ ("specify if tags should be fetched during clone" )),
442
+ OPT_BOOL (0 , "maintenance" , & maintenance ,
443
+ N_ ("specify if background maintenance should be enabled" )),
427
444
OPT_END (),
428
445
};
429
446
const char * const clone_usage [] = {
430
447
N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
431
- "\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]" ),
448
+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
432
449
NULL
433
450
};
434
451
const char * url ;
@@ -550,7 +567,8 @@ static int cmd_clone(int argc, const char **argv)
550
567
if (res )
551
568
goto cleanup ;
552
569
553
- res = register_dir ();
570
+ /* If --no-maintenance, then skip maintenance command entirely. */
571
+ res = register_dir (maintenance );
554
572
555
573
cleanup :
556
574
free (branch_to_free );
@@ -597,11 +615,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
597
615
598
616
static int cmd_register (int argc , const char * * argv )
599
617
{
618
+ int maintenance = 1 ;
600
619
struct option options [] = {
620
+ OPT_BOOL (0 , "maintenance" , & maintenance ,
621
+ N_ ("specify if background maintenance should be enabled" )),
601
622
OPT_END (),
602
623
};
603
624
const char * const usage [] = {
604
- N_ ("scalar register [<enlistment>]" ),
625
+ N_ ("scalar register [--[no-]maintenance] [ <enlistment>]" ),
605
626
NULL
606
627
};
607
628
@@ -610,7 +631,8 @@ static int cmd_register(int argc, const char **argv)
610
631
611
632
setup_enlistment_directory (argc , argv , usage , options , NULL );
612
633
613
- return register_dir ();
634
+ /* If --no-maintenance, then leave maintenance as-is. */
635
+ return register_dir (maintenance );
614
636
}
615
637
616
638
static int get_scalar_repos (const char * key , const char * value ,
@@ -646,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
646
668
static int cmd_reconfigure (int argc , const char * * argv )
647
669
{
648
670
int all = 0 ;
671
+ const char * maintenance_str = NULL ;
672
+ int maintenance = 1 ; /* Enable maintenance by default. */
673
+
649
674
struct option options [] = {
650
675
OPT_BOOL ('a' , "all" , & all ,
651
676
N_ ("reconfigure all registered enlistments" )),
677
+ OPT_STRING (0 , "maintenance" , & maintenance_str ,
678
+ N_ ("(enable|disable|keep)" ),
679
+ N_ ("signal how to adjust background maintenance" )),
652
680
OPT_END (),
653
681
};
654
682
const char * const usage [] = {
655
- N_ ("scalar reconfigure [--all | <enlistment>]" ),
683
+ N_ ("scalar reconfigure [--maintenance=(enable|disable|keep)] [-- all | <enlistment>]" ),
656
684
NULL
657
685
};
658
686
struct string_list scalar_repos = STRING_LIST_INIT_DUP ;
@@ -672,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
672
700
usage_msg_opt (_ ("--all or <enlistment>, but not both" ),
673
701
usage , options );
674
702
703
+ if (maintenance_str ) {
704
+ if (!strcmp (maintenance_str , "enable" ))
705
+ maintenance = 1 ;
706
+ else if (!strcmp (maintenance_str , "disable" ))
707
+ maintenance = 0 ;
708
+ else if (!strcmp (maintenance_str , "keep" ))
709
+ maintenance = -1 ;
710
+ else
711
+ die (_ ("unknown mode for --maintenance option: %s" ),
712
+ maintenance_str );
713
+ }
714
+
675
715
git_config (get_scalar_repos , & scalar_repos );
676
716
677
717
for (size_t i = 0 ; i < scalar_repos .nr ; i ++ ) {
@@ -736,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv)
736
776
the_repository = old_repo ;
737
777
repo_clear (& r );
738
778
739
- if (toggle_maintenance (1 ) >= 0 )
779
+ if (maintenance >= 0 &&
780
+ toggle_maintenance (maintenance ) >= 0 )
740
781
succeeded = 1 ;
741
782
742
783
loop_end :
@@ -803,13 +844,13 @@ static int cmd_run(int argc, const char **argv)
803
844
strbuf_release (& buf );
804
845
805
846
if (i == 0 )
806
- return register_dir ();
847
+ return register_dir (1 );
807
848
808
849
if (i > 0 )
809
850
return run_git ("maintenance" , "run" ,
810
851
"--task" , tasks [i ].task , NULL );
811
852
812
- if (register_dir ())
853
+ if (register_dir (1 ))
813
854
return -1 ;
814
855
for (i = 1 ; tasks [i ].arg ; i ++ )
815
856
if (run_git ("maintenance" , "run" ,
0 commit comments