Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-09-17 21:11:45 +0300
committerJunio C Hamano <gitster@pobox.com>2020-09-17 21:30:05 +0300
commit3103e9848f7b7534eac14c0521d7b49b32466b70 (patch)
treeaf0802555d35d05d41cbf69b53b9a9871cac8704 /builtin/gc.c
parenta95ce124305adcc4980241b8877e06db1d6ed411 (diff)
maintenance: initialize task array
In anticipation of implementing multiple maintenance tasks inside the 'maintenance' builtin, use a list of structs to describe the work to be done. The struct maintenance_task stores the name of the task (as given by a future command-line argument) along with a function pointer to its implementation and a boolean for whether the step is enabled. A list these structs are initialized with the full list of implemented tasks along with a default order. For now, this list only contains the "gc" task. This task is also the only task enabled by default. The run subcommand will return a nonzero exit code if any task fails. However, it will attempt all tasks in its loop before returning with the failure. Also each failed task will print an error message. Helped-by: Taylor Blau <me@ttaylorr.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index bacce0c7476..904fb2d9aa3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -728,6 +728,47 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
return run_command(&child);
}
+typedef int maintenance_task_fn(struct maintenance_run_opts *opts);
+
+struct maintenance_task {
+ const char *name;
+ maintenance_task_fn *fn;
+ unsigned enabled:1;
+};
+
+enum maintenance_task_label {
+ TASK_GC,
+
+ /* Leave as final value */
+ TASK__COUNT
+};
+
+static struct maintenance_task tasks[] = {
+ [TASK_GC] = {
+ "gc",
+ maintenance_task_gc,
+ 1,
+ },
+};
+
+static int maintenance_run_tasks(struct maintenance_run_opts *opts)
+{
+ int i;
+ int result = 0;
+
+ for (i = 0; i < TASK__COUNT; i++) {
+ if (!tasks[i].enabled)
+ continue;
+
+ if (tasks[i].fn(opts)) {
+ error(_("task '%s' failed"), tasks[i].name);
+ result = 1;
+ }
+ }
+
+ return result;
+}
+
static int maintenance_run(int argc, const char **argv, const char *prefix)
{
struct maintenance_run_opts opts;
@@ -750,7 +791,7 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
if (argc != 0)
usage_with_options(builtin_maintenance_run_usage,
builtin_maintenance_run_options);
- return maintenance_task_gc(&opts);
+ return maintenance_run_tasks(&opts);
}
static const char builtin_maintenance_usage[] = N_("git maintenance run [<options>]");