scalar: implement the `run` command
Note: this subcommand is provided primarily for backwards-compatibility, for existing Scalar uses. It is mostly just a shim for `git maintenance`, mapping task names from the way Scalar called them to the way Git calls them. The reason why those names differ? The background maintenance was first implemented in Scalar, and when it was contributed as a patch series implementing the `git maintenance` command, reviewers suggested better names, those suggestions were accepted before the patches were integrated into core Git. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Dec 3, 2021 at 13:34 UTC
7020c88c3003560d797cd7b5c0c95a9d35f9a4b9
2 files changed
+83
contrib/scalar/scalar.c
+64
@@ -484,6 +484,69 @@ static int cmd_register(int argc, const char **argv)
484
return register_dir();
485
}
486
487
+static int cmd_run(int argc, const char **argv)
488
+{
489
+ struct option options[] = {
490
+ OPT_END(),
491
+ };
492
+ struct {
493
+ const char *arg, *task;
494
+ } tasks[] = {
495
+ { "config", NULL },
496
+ { "commit-graph", "commit-graph" },
497
+ { "fetch", "prefetch" },
498
+ { "loose-objects", "loose-objects" },
499
+ { "pack-files", "incremental-repack" },
500
+ { NULL, NULL }
501
+ };
502
+ struct strbuf buf = STRBUF_INIT;
503
+ const char *usagestr[] = { NULL, NULL };
504
+ int i;
505
+
506
+ strbuf_addstr(&buf, N_("scalar run <task> [<enlistment>]\nTasks:\n"));
507
+ for (i = 0; tasks[i].arg; i++)
508
+ strbuf_addf(&buf, "\t%s\n", tasks[i].arg);
509
+ usagestr[0] = buf.buf;
510
+
511
+ argc = parse_options(argc, argv, NULL, options,
512
+ usagestr, 0);
513
+
514
+ if (!argc)
515
+ usage_with_options(usagestr, options);
516
+
517
+ if (!strcmp("all", argv[0])) {
518
+ i = -1;
519
+ } else {
520
+ for (i = 0; tasks[i].arg && strcmp(tasks[i].arg, argv[0]); i++)
521
+ ; /* keep looking for the task */
522
+
523
+ if (i > 0 && !tasks[i].arg) {
524
+ error(_("no such task: '%s'"), argv[0]);
525
+ usage_with_options(usagestr, options);
526
+ }
527
+ }
528
+
529
+ argc--;
530
+ argv++;
531
+ setup_enlistment_directory(argc, argv, usagestr, options, NULL);
532
+ strbuf_release(&buf);
533
+
534
+ if (i == 0)
535
+ return register_dir();
536
+
537
+ if (i > 0)
538
+ return run_git("maintenance", "run",
539
+ "--task", tasks[i].task, NULL);
540
+
541
+ if (register_dir())
542
+ return -1;
543
+ for (i = 1; tasks[i].arg; i++)
544
+ if (run_git("maintenance", "run",
545
+ "--task", tasks[i].task, NULL))
546
+ return -1;
547
+ return 0;
548
+}
549
+
550
static int remove_deleted_enlistment(struct strbuf *path)
551
{
552
int res = 0;
@@ -556,6 +619,7 @@ static struct {
619
{ "list", cmd_list },
620
{ "register", cmd_register },
621
{ "unregister", cmd_unregister },
622
+ { "run", cmd_run },
623
{ NULL, NULL},
624
};
625
contrib/scalar/scalar.txt
+19
@@ -12,6 +12,7 @@ scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<e
12
scalar list
13
scalar register [<enlistment>]
14
scalar unregister [<enlistment>]
15
+scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
16
17
DESCRIPTION
18
-----------
@@ -98,6 +99,24 @@ unregister [<enlistment>]::
99
Remove the specified repository from the list of repositories
100
registered with Scalar and stop the scheduled background maintenance.
101
102
+Run
103
+~~~
104
+
105
+scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]::
106
+ Run the given maintenance task (or all tasks, if `all` was specified).
107
+ Except for `all` and `config`, this subcommand simply hands off to
108
+ linkgit:git-maintenance[1] (mapping `fetch` to `prefetch` and
109
+ `pack-files` to `incremental-repack`).
110
++
111
+These tasks are run automatically as part of the scheduled maintenance,
112
+as soon as the repository is registered with Scalar. It should therefore
113
+not be necessary to run this subcommand manually.
114
++
115
+The `config` task is specific to Scalar and configures all those
116
+opinionated default settings that make Git work more efficiently with
117
+large repositories. As this task is run as part of `scalar clone`
118
+automatically, explicit invocations of this task are rarely needed.
119
+
120
SEE ALSO
121
--------
122
linkgit:git-clone[1], linkgit:git-maintenance[1].