Re: [PATCH v3 1/6] odb: introduce interface to generate packfiles

Karthik Nayak <[email protected]>
Newsgroups org.kernel.vger.git
Message-ID <CAOLa=ZSYyfOCs8Dr0Xdhv-=Q=j0z7vtfYqopDb07XuAm2PU84g@mail.gmail.com>
Patrick Steinhardt <[email protected]> writes:

> Packfiles have two primary use cases:
>
>   - They are used to store objects at rest in a Git repository.
>
>   - They are used on the transport layer to transfer objects between two
>     repositories.
>
> The first class is closely tied to a given object database backend, and
> as such this use is highly specific to how such a backend decides to
> store its data. This shows in git-pack-objects(1), which is used by
> git-repack(1) et al to optimize the object database, which supports lots
> of options that are closely coupled with how data is stored.
>
> But the second class is quite a lot more generic: we don't care about
> specifics of how the object database stores its objects, but to generate
> the packfiles we only care about the object graph itself. Still, this
> use case is also coupled with git-pack-objects(1).
>
> Unfortunately, because git-pack-objects(1) covers both classes, the
> result is that it is very hard to port the whole command to properly
> support pluggable object databases. There are simply way too many
> options that an alternative implementation will have a very hard time to
> support in the first place.
>
> And despite being hard to implement, it's also quite unnecessary to
> implement those backend-specific options. Optimizing the object database
> has already been made pluggable, and an alternative implementation is
> unlikely to care about cruft packs, unpacked objects, keep packs and the
> like. But we still need to make at least _parts_ of the packfile
> generation pluggable so that backends can generate packfiles for the
> transport layer itself.
>
> Introduce a new interface that lets backends generate a new packfile and
> implement that interface for the "files" backend. The options supported
> by the callback are exactly the set of options that are required for the
> transport layer, but nothing more.
>

Okay so we also provide the implementation for the files odb here, which
calls 'git-pack-objects(1)' to generate the packfile.

The changes look in order.

[snip]

> diff --git a/odb/source.h b/odb/source.h
> index d69f8e2d1c..e2129766fc 100644
> --- a/odb/source.h
> +++ b/odb/source.h
> @@ -278,6 +278,23 @@ struct odb_source {
>  	 */
>  	bool (*optimize_required)(struct odb_source *source,
>  				  const struct odb_optimize_options *opts);
> +
> +	/*
> +	 * This callback is expected to start generating a packfile with the
> +	 * given options. The pack shall be generated asynchronously so that
> +	 * the caller can consume the pack data and progress output while the
> +	 * pack is being generated.
> +	 *
> +	 * This callback is optional. Sources that cannot generate packfiles
> +	 * shall leave it unset.
> +	 *
> +	 * The callback is expected to return 0 on success and populate the
> +	 * `out` pointer with the pack generator, a negative error code
> +	 * otherwise.
> +	 */
> +	int (*generate_pack)(struct odb_source *source,
> +			     struct odb_pack_generator **out,
> +			     const struct odb_generate_pack_options *opts);
>  };
>

Nit: I see that `source` is unused anyways, do we need to pass it in? Or
is just for consistency?

>  /*
> @@ -520,4 +537,20 @@ static inline bool odb_source_optimize_required(struct odb_source *source,
>  	return source->optimize_required(source, opts);
>  }
>
> +/*
> + * Start generating a packfile from the given source with the given options.
> + * The pack is generated asynchronously; the caller is expected to consume the
> + * file descriptors exposed via the pack generator and to then wait for
> + * completion via `odb_pack_generator_finish()`.
> + *
> + * Returns 0 on success and populates the `out` pointer with the pack
> + * generator, a negative error code otherwise.
> + */
> +static inline int odb_source_generate_pack(struct odb_source *source,
> +					   struct odb_pack_generator **out,
> +					   const struct odb_generate_pack_options *opts)
> +{
> +	return source->generate_pack(source, out, opts);
> +}
> +
>  #endif
>
> --
> 2.55.0.822.g20453c30eb.dirty
signature.asc (application/pgp-signature, 690 B)
-----BEGIN PGP SIGNATURE-----

iQHKBAEBCgA0FiEEV85Mf2N1cQ/LZcYGPtWfJI5GjH8FAmqG1AMWHGthcnRoaWsu
MTg4QGdtYWlsLmNvbQAKCRA+1Z8kjkaMf8y1C/wNTVKx0+M+C9oVOjLiNuFSCyBG
E55u0N6EuHGvLbm+f5gVWQm74gXV36b7F0HZiNm/PXORKFH5q6zQObLQYegoI7S/
KlGx1+AupRKP+6Sv0yXmYO1CBY0HYgC24OdDfl4Cxvjf5tNAlxEohiT4F7UO8pu8
eZI/AJ2dlNQ9s2A7HRoI/CwxxrywvuF+h4escAYHidL8UbMTD39orz9C51gVAh6I
uqHWmYypuNxCIYl/6gGraqr6A7tOYi9bVosEtAAUB8QtyOKTePs9HdcJeOqhfWCu
7gs3ijJVB0wS5htk4R7culv7DBipIPf0ZlTIxHggz9zU9su0Ah1HkSes8UDm0EDn
Msml1U1WHmJG6RMf+aHJfDJjGWx1rhqe8H/3c3mvvWmfU3XGcfGn+C2JMiQF6FxO
QUuknQlliIiO3C/RnraaBXvWYkfLM1gjkd9+gcfAVQp6ff+HnHneeuHJcSlR4VFq
7qP5+qeEIyBzcfuGngcTR3zDrimXeMtqAuoFAYk=
=nHwA
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.