]> Kevux Git Server - rit/commit
builtin/maintenance: stop modifying global array of tasks
authorPatrick Steinhardt <ps@pks.im>
Tue, 3 Jun 2025 14:01:13 +0000 (16:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2025 15:30:49 +0000 (08:30 -0700)
commit38a8fa5a9a3a74dd606ba37702689a8b07c084bf
treee057168f47b0367a96c11c58171db1e0a89b7083
parenta7c86d328ffe2d93cb1bfaf557dba7a2034ec17b
builtin/maintenance: stop modifying global array of tasks

When configuring maintenance tasks run by git-maintenance(1) we do so by
modifying the global array of tasks directly. This is already quite bad
on its own, as global state makes for logic that is hard to follow.

Even more importantly though we use multiple different fields to track
whether or not a task should be run:

  - "enabled" tracks the "maintenance.*.enabled" config key. This field
    disables execution of a task, unless the user has explicitly asked
    for the task.

  - "selected_order" tracks the order in which jobs have been asked for
    by the user via the "--task=" command line option. It overrides
    everything else, but only has an effect if at least one job has been
    selected.

  - "schedule" tracks the schedule priority for a job, that is how often
    it should run. This field only plays a role when the user has passed
    the "--schedule=" command line option.

All of this makes it non-trivial to figure out which job really should
be running right now. The logic to configure these fields and the logic
that interprets them is distributed across multiple functions, making it
even harder to follow it.

Refactor the logic so that we stop modifying global state. Instead, we
now compute which jobs should be run in `initialize_task_config()`,
represented as an array of jobs to run that is stored in the options
structure. Like this, all logic becomes self-contained and any users of
this array only need to iterate through the tasks and execute them one
by one.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c