Subject: Re: [PATCH 02/17] odb: introduce "files" source

From: Justin Tobler <[email-masked]>
Date: Wed, 4 Mar 2026 10:57:26 -0600

On 26/02/23 05:17PM, Patrick Steinhardt wrote:
> Introduce a new "files" object database source. This source encapsulates
> access to both loose object files and the packfile store, similar to how
> the "files" backend for refs encapsulates access to loose refs and the
> packed-refs file.

Makes sense.

> Note that for now the "files" source is still a direct member of a
> `struct odb_source`. This architecture will be reversed in the next
> commit so that the files source contains a `struct odb_source`.

Ok so for now all ODB operations are going to reach directly into the
contained "files" source.

> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
[snip]
> diff --git a/odb/source-files.h b/odb/source-files.h
> new file mode 100644
> index 0000000000..0b8bf773ca
> --- /dev/null
> +++ b/odb/source-files.h
> @@ -0,0 +1,24 @@
> +#ifndef ODB_SOURCE_FILES_H
> +#define ODB_SOURCE_FILES_H
> +
> +struct odb_source_loose;
> +struct odb_source;
> +struct packfile_store;
> +
> +/*
> + * The files object database source uses a combination of loose objects and
> + * packfiles. It is the default backend used by Git to store objects.
> + */
> +struct odb_source_files {
> +	struct odb_source *source;

I don't think we use this anywhere yet, but I suspect this is the
placeholder for the "base" ODB source.

> +	struct odb_source_loose *loose;
> +	struct packfile_store *packed;

So with this patch we are really just moving odb_source_loose and
packfile_store into `struct odb_source_files`. Most of the other changes
are just fallout from this structural change.

> +};
> +
> +/* Allocate and initialize a new object source. */
> +struct odb_source_files *odb_source_files_new(struct odb_source *source);
> +
> +/* Free the object source and release all associated resources. */
> +void odb_source_files_free(struct odb_source_files *files);
> +
> +#endif
[snip]
> diff --git a/odb/source.h b/odb/source.h
> index 391d6d1e38..1c34265189 100644
> --- a/odb/source.h
> +++ b/odb/source.h
> @@ -1,6 +1,8 @@
>  #ifndef ODB_SOURCE_H
>  #define ODB_SOURCE_H
>  
> +#include "odb/source-files.h"
> +
>  /*
>   * The source is the part of the object database that stores the actual
>   * objects. It thus encapsulates the logic to read and write the specific
> @@ -19,11 +21,8 @@ struct odb_source {
>  	/* Object database that owns this object source. */
>  	struct object_database *odb;
>  
> -	/* Private state for loose objects. */
> -	struct odb_source_loose *loose;
> -
> -	/* Should only be accessed directly by packfile.c and midx.c. */

Is there any value to keeping this comment around?

> -	struct packfile_store *packfiles;
> +	/* The backend used to store objects. */
> +	struct odb_source_files *files;

For now we store a direct reference to the "files" ODB source, but I
assume in the future this won't be the case and instead will cast the
"base" ODB source into its concrete type as needed.

-Justin