Skip to content

Commit 7020c88

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4368e40 commit 7020c88

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

contrib/scalar/scalar.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,69 @@ static int cmd_register(int argc, const char **argv)
484484
return register_dir();
485485
}
486486

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+
487550
static int remove_deleted_enlistment(struct strbuf *path)
488551
{
489552
int res = 0;
@@ -556,6 +619,7 @@ static struct {
556619
{ "list", cmd_list },
557620
{ "register", cmd_register },
558621
{ "unregister", cmd_unregister },
622+
{ "run", cmd_run },
559623
{ NULL, NULL},
560624
};
561625

contrib/scalar/scalar.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<e
1212
scalar list
1313
scalar register [<enlistment>]
1414
scalar unregister [<enlistment>]
15+
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
1516

1617
DESCRIPTION
1718
-----------
@@ -98,6 +99,24 @@ unregister [<enlistment>]::
9899
Remove the specified repository from the list of repositories
99100
registered with Scalar and stop the scheduled background maintenance.
100101

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+
101120
SEE ALSO
102121
--------
103122
linkgit:git-clone[1], linkgit:git-maintenance[1].

0 commit comments

Comments
 (0)