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

Re: [PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 1, 2026, 10:58 UTC
Message-ID
<aw6oO92LKQJM9TwS@pks.im>
In-Reply-To
<c381afb0da593080ae8fc96a6187b579da829658.1796075503.git.jltobler@gmail.com>
On Mon, Nov 30, 2026 at 03:54:57PM -0600, Justin Tobler wrote:
Show 13 quoted lines
> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
> index c48212290cf8..1a27d523c7ab 100644
> --- a/builtin/multi-pack-index.c
> +++ b/builtin/multi-pack-index.c
> @@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,
>  	char **value = opt->value;
>  	free(*value);
>  	if (unset)
> -		*value = xstrdup(the_repository->objects->source->path);
> +		*value = NULL;
>  	else
>  		*value = real_pathdup(arg, 1);
>  	return 0;

Makes me wonder whether we could avoid allocating the value altogether and just assign the static string?

Show 18 quoted lines
> @@ -88,10 +88,16 @@ static int parse_object_dir(const struct option *opt, const char *arg,
>  
>  static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
>  {
> -	struct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);
> +	const char *object_dir = opts.object_dir;
> +	struct odb_files_dir *dir;
> +
> +	if (!object_dir)
> +		object_dir = repo->objects->source->path;
> +
> +	dir = odb_source_files_find_dir(repo->objects, object_dir);
>  	if (!dir)
>  		die(_("object directory is not an alternate of the current repository: '%s'"),
> -		    opts.object_dir);
> +		    object_dir);
>  	return dir->packed;
>  }

Okay, so instead of handling the default value in `parse_object_dir()` we set it up here. Makes sense.

Show 8 quoted lines
> @@ -424,11 +430,6 @@ int cmd_multi_pack_index(int argc,
>  
>  	repo_config(the_repository, git_default_config, NULL);
>  
> -	if (the_repository &&
> -	    the_repository->objects &&
> -	    the_repository->objects->source)
> -		opts.object_dir = xstrdup(the_repository->objects->source->path);

We previously handled the case where there is no repository, but we don't do that in `handle_object_dir_option()`. But this command does not run without a repository anyway, so that looks like a sensible change to me.

Patrick
Previous: Justin ToblerNext: Justin Tobler
Message 3 of 25 in “builtin/multi-pack-index: remove global state”
  1. 0/5 builtin/multi-pack-index: remove global stateJustin Tobler, Nov 30, 2026
  2. 1/5 builtin/multi-pack-index: resolve default object directory lazilyJustin Tobler, Nov 30, 2026
  3. Patrick SteinhardtDec 1, 2026
  4. Justin ToblerDec 1, 2026
  5. 2/5 builtin/multi-pack-index: get rid of `the_repository`Justin Tobler, Nov 30, 2026
  6. Patrick SteinhardtDec 1, 2026
  7. Justin ToblerDec 1, 2026
  8. 3/5 builtin/multi-pack-index: drop top-level optionsJustin Tobler, Nov 30, 2026
  9. Patrick SteinhardtDec 1, 2026
  10. Justin ToblerDec 1, 2026
  11. 4/5 builtin/multi-pack-index: simplify how common options are wired upJustin Tobler, Nov 30, 2026
  12. Patrick SteinhardtDec 1, 2026
  13. Justin ToblerDec 1, 2026
  14. 5/5 builtin/multi-pack-index: de-globalize options handlingJustin Tobler, Nov 30, 2026
  15. Patrick SteinhardtDec 1, 2026
  16. Justin ToblerDec 1, 2026
  17. 0/5 builtin/multi-pack-index: remove global stateJustin Tobler, Dec 1, 2026
  18. 1/5 builtin/multi-pack-index: resolve default object directory lazilyJustin Tobler, Dec 1, 2026
  19. Patrick SteinhardtDec 2, 2026
  20. 2/5 builtin/multi-pack-index: get rid of `the_repository`Justin Tobler, Dec 1, 2026
  21. 3/5 builtin/multi-pack-index: drop top-level optionsJustin Tobler, Dec 1, 2026
  22. 4/5 builtin/multi-pack-index: simplify how common options are wired upJustin Tobler, Dec 1, 2026
  23. 5/5 builtin/multi-pack-index: de-globalize options handlingJustin Tobler, Dec 1, 2026
  24. Patrick SteinhardtDec 2, 2026
  25. Patrick SteinhardtDec 2, 2026

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.