Message ID | 732a28c22fcecafa308cd9444efe9158800b94e5.1630359290.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Upstreaming the Scalar command | expand |
On Mon, Aug 30, 2021 at 5:35 PM Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote: > 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> > --- > diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt > @@ -121,6 +121,10 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment > +With the `--all` option, all enlistments currently registered with Scalar > +will be reconfigured. This option is meant to to be run every time Scalar > +was upgraded. s/was/is/
Hi Eric, On Tue, 31 Aug 2021, Eric Sunshine wrote: > On Mon, Aug 30, 2021 at 5:35 PM Johannes Schindelin via GitGitGadget > <gitgitgadget@gmail.com> wrote: > > 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> > > --- > > diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt > > @@ -121,6 +121,10 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment > > +With the `--all` option, all enlistments currently registered with Scalar > > +will be reconfigured. This option is meant to to be run every time Scalar > > +was upgraded. > > s/was/is/ I wanted to convey a temporal order, so I changed it to "every time after Scalar is upgraded". Okay? Ciao, Dscho
On Fri, Sep 3, 2021 at 11:23 AM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote: > On Tue, 31 Aug 2021, Eric Sunshine wrote: > > On Mon, Aug 30, 2021 at 5:35 PM Johannes Schindelin via GitGitGadget > > > +With the `--all` option, all enlistments currently registered with Scalar > > > +will be reconfigured. This option is meant to to be run every time Scalar > > > +was upgraded. > > > > s/was/is/ > > I wanted to convey a temporal order, so I changed it to "every time after > Scalar is upgraded". Okay? I think I understood the intent of the original, but it causes a grammatical hiccup. Your revised version can work, although I might write it this way: This option is meant to be run each time Scalar is upgraded. However, perhaps that is too ambiguous and some users may think that the process of upgrading Scalar will automatically run this command, and you'd like to make it clear that it is the user's responsibility. So, perhaps: Use this option after each Scalar upgrade. or something.
Hi Eric, On Fri, 3 Sep 2021, Eric Sunshine wrote: > On Fri, Sep 3, 2021 at 11:23 AM Johannes Schindelin > <Johannes.Schindelin@gmx.de> wrote: > > On Tue, 31 Aug 2021, Eric Sunshine wrote: > > > On Mon, Aug 30, 2021 at 5:35 PM Johannes Schindelin via GitGitGadget > > > > +With the `--all` option, all enlistments currently registered with Scalar > > > > +will be reconfigured. This option is meant to to be run every time Scalar > > > > +was upgraded. > > > > > > s/was/is/ > > > > I wanted to convey a temporal order, so I changed it to "every time after > > Scalar is upgraded". Okay? > > I think I understood the intent of the original, but it causes a > grammatical hiccup. Your revised version can work, although I might > write it this way: > > This option is meant to be run each time Scalar is upgraded. > > However, perhaps that is too ambiguous and some users may think that > the process of upgrading Scalar will automatically run this command, > and you'd like to make it clear that it is the user's responsibility. > So, perhaps: > > Use this option after each Scalar upgrade. > > or something. I like the last one best, too. Thank you, Dscho
diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index 4eff3464a13..1f8778cbb39 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -494,22 +494,77 @@ static int cmd_register(int argc, const char **argv) return register_dir(); } +static int get_scalar_repos(const char *key, const char *value, void *data) +{ + struct string_list *list = data; + + if (!strcmp(key, "scalar.repo")) + string_list_append(list, value); + + return 0; +} + static int cmd_reconfigure(int argc, const char **argv) { + int all = 0; struct option options[] = { + OPT_BOOL('a', "all", &all, + N_("reconfigure all registered enlistments")), OPT_END(), }; const char * const usage[] = { - N_("scalar reconfigure [<enlistment>]"), + N_("scalar reconfigure [--all | <enlistment>]"), NULL }; + struct string_list scalar_repos = STRING_LIST_INIT_DUP; + int i, res = 0; + struct repository r = { NULL }; + struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT; argc = parse_options(argc, argv, NULL, options, usage, 0); - setup_enlistment_directory(argc, argv, usage, options, NULL); + if (!all) { + setup_enlistment_directory(argc, argv, usage, options, NULL); + + return set_recommended_config(1); + } + + if (argc > 0) + usage_msg_opt(_("--all or <enlistment>, but not both"), + usage, options); + + git_config(get_scalar_repos, &scalar_repos); - return set_recommended_config(1); + for (i = 0; i < scalar_repos.nr; i++) { + const char *dir = scalar_repos.items[i].string; + + strbuf_reset(&commondir); + strbuf_reset(&gitdir); + + if (chdir(dir) < 0) { + warning_errno(_("could not switch to '%s'"), dir); + res = -1; + } else if (discover_git_directory(&commondir, &gitdir) < 0) { + warning_errno(_("git repository gone in '%s'"), dir); + res = -1; + } else { + git_config_clear(); + + the_repository = &r; + r.commondir = commondir.buf; + r.gitdir = gitdir.buf; + + if (set_recommended_config(1) < 0) + res = -1; + } + } + + string_list_clear(&scalar_repos, 1); + strbuf_release(&commondir); + strbuf_release(&gitdir); + + return res; } static int cmd_run(int argc, const char **argv) diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 227e3542a07..2a1a0695b4d 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -13,7 +13,7 @@ scalar list scalar register [<enlistment>] scalar unregister [<enlistment>] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>] -scalar reconfigure <enlistment> +scalar reconfigure [ --all | <enlistment> ] DESCRIPTION ----------- @@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment will be identical to the worktree. The `scalar` command implements various subcommands, and different options -depending on the subcommand. With the exception of `clone` and `list`, all -subcommands expect to be run in an enlistment. +depending on the subcommand. With the exception of `clone`, `list` and +`reconfigure --all`, all subcommands expect to be run in an enlistment. COMMANDS -------- @@ -121,6 +121,10 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment was somehow corrupted or changed by mistake, this subcommand allows to reconfigure the enlistment. +With the `--all` option, all enlistments currently registered with Scalar +will be reconfigured. This option is meant to to be run every time Scalar +was upgraded. + SEE ALSO -------- linkgit:git-clone[1], linkgit:git-maintenance[1]. diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh index e6d74a06ca0..5fe7fabd0e5 100755 --- a/contrib/scalar/t/t9099-scalar.sh +++ b/contrib/scalar/t/t9099-scalar.sh @@ -70,6 +70,9 @@ test_expect_success 'scalar reconfigure' ' scalar register one && git -C one/src config core.preloadIndex false && scalar reconfigure one && + test true = "$(git -C one/src config core.preloadIndex)" && + git -C one/src config core.preloadIndex false && + scalar reconfigure -a && test true = "$(git -C one/src config core.preloadIndex)" '