scalar: teach 'reconfigure' to optionally handle all registered enlistments
After a Scalar upgrade, it can come in really handy if there is an easy way to reconfigure all Scalar enlistments. This new option offers this functionality. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 3, 2021 at 13:34 UTC
45826760758ef09626d941c19993144b6fbd6440
3 files changed
+67
-6
contrib/scalar/scalar.c
+58
-3
@@ -488,22 +488,77 @@ static int cmd_register(int argc, const char **argv)
488
return register_dir();
489
}
490
491
+static int get_scalar_repos(const char *key, const char *value, void *data)
492
+{
493
+ struct string_list *list = data;
494
+
495
+ if (!strcmp(key, "scalar.repo"))
496
+ string_list_append(list, value);
497
+
498
+ return 0;
499
+}
500
+
501
static int cmd_reconfigure(int argc, const char **argv)
502
{
503
+ int all = 0;
504
struct option options[] = {
505
+ OPT_BOOL('a', "all", &all,
506
+ N_("reconfigure all registered enlistments")),
507
OPT_END(),
508
};
509
const char * const usage[] = {
497
- N_("scalar reconfigure [<enlistment>]"),
510
+ N_("scalar reconfigure [--all | <enlistment>]"),
511
NULL
512
};
513
+ struct string_list scalar_repos = STRING_LIST_INIT_DUP;
514
+ int i, res = 0;
515
+ struct repository r = { NULL };
516
+ struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT;
517
518
argc = parse_options(argc, argv, NULL, options,
519
usage, 0);
520
504
- setup_enlistment_directory(argc, argv, usage, options, NULL);
521
+ if (!all) {
522
+ setup_enlistment_directory(argc, argv, usage, options, NULL);
523
+
524
+ return set_recommended_config(1);
525
+ }
526
+
527
+ if (argc > 0)
528
+ usage_msg_opt(_("--all or <enlistment>, but not both"),
529
+ usage, options);
530
+
531
+ git_config(get_scalar_repos, &scalar_repos);
532
506
- return set_recommended_config(1);
533
+ for (i = 0; i < scalar_repos.nr; i++) {
534
+ const char *dir = scalar_repos.items[i].string;
535
+
536
+ strbuf_reset(&commondir);
537
+ strbuf_reset(&gitdir);
538
+
539
+ if (chdir(dir) < 0) {
540
+ warning_errno(_("could not switch to '%s'"), dir);
541
+ res = -1;
542
+ } else if (discover_git_directory(&commondir, &gitdir) < 0) {
543
+ warning_errno(_("git repository gone in '%s'"), dir);
544
+ res = -1;
545
+ } else {
546
+ git_config_clear();
547
+
548
+ the_repository = &r;
549
+ r.commondir = commondir.buf;
550
+ r.gitdir = gitdir.buf;
551
+
552
+ if (set_recommended_config(1) < 0)
553
+ res = -1;
554
+ }
555
+ }
556
+
557
+ string_list_clear(&scalar_repos, 1);
558
+ strbuf_release(&commondir);
559
+ strbuf_release(&gitdir);
560
+
561
+ return res;
562
}
563
564
static int cmd_run(int argc, const char **argv)
contrib/scalar/scalar.txt
+6
-3
@@ -13,7 +13,7 @@ scalar list
13
scalar register [<enlistment>]
14
scalar unregister [<enlistment>]
15
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
16
-scalar reconfigure <enlistment>
16
+scalar reconfigure [ --all | <enlistment> ]
17
18
DESCRIPTION
19
-----------
@@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment
32
will be identical to the worktree.
33
34
The `scalar` command implements various subcommands, and different options
35
-depending on the subcommand. With the exception of `clone` and `list`, all
36
-subcommands expect to be run in an enlistment.
35
+depending on the subcommand. With the exception of `clone`, `list` and
36
+`reconfigure --all`, all subcommands expect to be run in an enlistment.
37
38
COMMANDS
39
--------
@@ -125,6 +125,9 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment
125
was somehow corrupted or changed by mistake, this subcommand allows to
126
reconfigure the enlistment.
127
128
+With the `--all` option, all enlistments currently registered with Scalar
129
+will be reconfigured. Use this option after each Scalar upgrade.
130
+
131
SEE ALSO
132
--------
133
linkgit:git-clone[1], linkgit:git-maintenance[1].
contrib/scalar/t/t9099-scalar.sh
+3
@@ -70,6 +70,9 @@ test_expect_success 'scalar reconfigure' '
70
scalar register one &&
71
git -C one/src config core.preloadIndex false &&
72
scalar reconfigure one &&
73
+ test true = "$(git -C one/src config core.preloadIndex)" &&
74
+ git -C one/src config core.preloadIndex false &&
75
+ scalar reconfigure -a &&
76
test true = "$(git -C one/src config core.preloadIndex)"
77
'
78