git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 5/5] maintenance: add 'is-needed' subcommand

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 6, 2025, 12:02 UTC
Message-ID
<aQyOZ0e6HO0_77Au@pks.im>
In-Reply-To
<20251106-562-add-sub-command-to-check-if-maintenance-is-needed-v3-5-d611a2a95cf5@gmail.com>
On Thu, Nov 06, 2025 at 09:22:34AM +0100, Karthik Nayak wrote:
Show 14 quoted lines
> diff --git a/Documentation/git-maintenance.adoc b/Documentation/git-maintenance.adoc
> index 540b5cf68b..37939510d4 100644
> --- a/Documentation/git-maintenance.adoc
> +++ b/Documentation/git-maintenance.adoc
> @@ -84,6 +85,16 @@ The `unregister` subcommand will report an error if the current repository
>  is not already registered. Use the `--force` option to return success even
>  when the current repository is not registered.
>  
> +is-needed::
> +    Check whether maintenance needs to be run without actually running it.
> +    Exits with a 0 status code if maintenance needs to be run, 1 otherwise.
> +    Ideally used with the '--auto' flag.
> ++
> +If one or more `--task` options	are specified, then those tasks are checked
I spoke too soon, forgot that there's one more patch :) s/\t/ /
> +in that order. Otherwise, the tasks are determined by which
> +`maintenance.<task>.enabled` config options are true. By default, only
> +`maintenance.gc.enabled` is true.

This could use a pointer to "maintenance.strategy", but I see that you took this explanation from the "run" subcommand. I think this is good enough for now.

Show 49 quoted lines
> diff --git a/builtin/gc.c b/builtin/gc.c
> index c3e7a84ec2..e5ba2a2e72 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -3253,7 +3253,59 @@ static int maintenance_stop(int argc, const char **argv, const char *prefix,
>  	return update_background_schedule(NULL, 0);
>  }
>  
> -static const char * const builtin_maintenance_usage[] = {
> +static const char *const builtin_maintenance_is_needed_usage[] = {
> +	"git maintenance is-needed [--task=<task>] [--schedule]",
> +	NULL
> +};
> +
> +static int maintenance_is_needed(int argc, const char **argv, const char *prefix,
> +				 struct repository *repo UNUSED)
> +{
> +	struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
> +	struct string_list selected_tasks = STRING_LIST_INIT_DUP;
> +	struct gc_config cfg = GC_CONFIG_INIT;
> +	struct option options[] = {
> +		OPT_BOOL(0, "auto", &opts.auto_flag,
> +			 N_("run tasks based on the state of the repository")),
> +		OPT_CALLBACK_F(0, "task", &selected_tasks, N_("task"),
> +			       N_("check a specific task"),
> +			       PARSE_OPT_NONEG, task_option_parse),
> +		OPT_END()
> +	};
> +	bool is_needed = false;
> +
> +	argc = parse_options(argc, argv, prefix, options,
> +			     builtin_maintenance_is_needed_usage,
> +			     PARSE_OPT_STOP_AT_NON_OPTION);
> +	if (argc)
> +		usage_with_options(builtin_maintenance_is_needed_usage, options);
> +
> +	gc_config(&cfg);
> +	initialize_task_config(&opts, &selected_tasks);
> +
> +	if (opts.auto_flag) {
> +		for (size_t i = 0; i < opts.tasks_nr; i++) {
> +			if (tasks[opts.tasks[i]].auto_condition &&
> +			    tasks[opts.tasks[i]].auto_condition(&cfg)) {
> +				is_needed = true;
> +				break;
> +			}
> +		}
> +	} else {
> +		/* When not using --auto, we should always require maintenance. */
Nit: we might add a TODO comment here.
    /*
     * When not using --auto we always require maintenance right now.
     *
     * TODO: this certainly is too eager, as some maintenance tasks may
     * decide to not do anything because the data structures are already
     * fully optimized. We may eventually want to extend the auto
     * condition to also cover non-auto runs so that we can detect such
     * cases.
     /
Patrick
Previous: Karthik NayakNext: Karthik Nayak
Message 49 of 57 in “maintenance: add an 'is-needed' subcommand”
  1. 0/5 maintenance: add an 'is-needed' subcommandKarthik Nayak, Oct 31, 2025
  2. 1/5 reftable/stack: return stack segments directlyKarthik Nayak, Oct 31, 2025
  3. Justin ToblerOct 31, 2025
  4. Karthik NayakNov 3, 2025
  5. Justin ToblerNov 3, 2025
  6. 2/5 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Oct 31, 2025
  7. Justin ToblerOct 31, 2025
  8. Junio C HamanoOct 31, 2025
  9. Karthik NayakNov 3, 2025
  10. Karthik NayakNov 3, 2025
  11. Justin ToblerNov 3, 2025
  12. Patrick SteinhardtNov 3, 2025
  13. Karthik NayakNov 3, 2025
  14. 3/5 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Oct 31, 2025
  15. 4/5 maintenance: add checking logic in `pack_refs_condition()`Karthik Nayak, Oct 31, 2025
  16. Patrick SteinhardtNov 3, 2025
  17. Karthik NayakNov 3, 2025
  18. 5/5 maintenance: add 'is-needed' subcommandKarthik Nayak, Oct 31, 2025
  19. Patrick SteinhardtNov 3, 2025
  20. Karthik NayakNov 3, 2025
  21. Patrick SteinhardtNov 4, 2025
  22. Karthik NayakNov 4, 2025
  23. 0/5 maintenance: add an 'is-needed' subcommandKarthik Nayak, Nov 4, 2025
  24. 1/5 reftable/stack: return stack segments directlyKarthik Nayak, Nov 4, 2025
  25. 3/5 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Nov 4, 2025
  26. 2/5 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Nov 4, 2025
  27. Junio C HamanoNov 4, 2025
  28. Karthik NayakNov 5, 2025
  29. Junio C HamanoNov 5, 2025
  30. Karthik NayakNov 6, 2025
  31. 4/5 maintenance: add checking logic in `pack_refs_condition()`Karthik Nayak, Nov 4, 2025
  32. 5/5 maintenance: add 'is-needed' subcommandKarthik Nayak, Nov 4, 2025
  33. Junio C HamanoNov 4, 2025
  34. Karthik NayakNov 5, 2025
  35. 0/5 maintenance: add an 'is-needed' subcommandKarthik Nayak, Nov 6, 2025
  36. 1/5 reftable/stack: return stack segments directlyKarthik Nayak, Nov 6, 2025
  37. 2/5 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Nov 6, 2025
  38. Junio C HamanoNov 6, 2025
  39. Patrick SteinhardtNov 7, 2025
  40. 3/5 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Nov 6, 2025
  41. 4/5 maintenance: add checking logic in `pack_refs_condition()`Karthik Nayak, Nov 6, 2025
  42. Patrick SteinhardtNov 6, 2025
  43. Karthik NayakNov 6, 2025
  44. Junio C HamanoNov 6, 2025
  45. Karthik NayakNov 7, 2025
  46. Junio C HamanoNov 7, 2025
  47. Karthik NayakNov 7, 2025
  48. 5/5 maintenance: add 'is-needed' subcommandKarthik Nayak, Nov 6, 2025
  49. Patrick SteinhardtNov 6, 2025
  50. Karthik NayakNov 6, 2025
  51. 0/5 maintenance: add an 'is-needed' subcommandKarthik Nayak, Nov 8, 2025
  52. 1/5 reftable/stack: return stack segments directlyKarthik Nayak, Nov 8, 2025
  53. 2/5 reftable/stack: add function to check if optimization is requiredKarthik Nayak, Nov 8, 2025
  54. 3/5 refs: add a `optimize_required` field to `struct ref_storage_be`Karthik Nayak, Nov 8, 2025
  55. 4/5 maintenance: add checking logic in `pack_refs_condition()`Karthik Nayak, Nov 8, 2025
  56. 5/5 maintenance: add 'is-needed' subcommandKarthik Nayak, Nov 8, 2025
  57. Patrick SteinhardtNov 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.