From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Christian Couder <christian.couder@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>,
Jeff King <peff@peff.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2 06/13] pack-write: add support for pack index v3
Date: Mon, 30 Nov 2026 21:35:29 +0530 [thread overview]
Message-ID: <54a6e8aa-e112-4686-b34b-5857f5060e27@gmail.com> (raw)
In-Reply-To: <20261023072559.3204273-7-christian.couder@gmail.com>
With the caveat that I'm not an expert in index formats, I thought I'll
leave some comments to the best of my understanding.
On 10/23/26 12:55, Christian Couder wrote:
>
> We choose to always write the main hash algorithm first in the pack.
> This optimizes for the case when we're interacting natively with the
> remote side by permitting us to use the CRC32 entries.
>
> Note that we never write index v3, since we cannot read it yet, and
> doing so will break the tests. In a future commit, once we can read it,
> we'll enable it by default when a compatibility algorithm is enabled.
>
Could we be more explicit about when we polan to enable v3 by default?
For instance, do we plan to do it in this series or in a later series?
> diff --git a/pack-write.c b/pack-write.c
> index 85674e4b72..1834394a77 100644
> --- a/pack-write.c
> +++ b/pack-write.c
> @@ -22,13 +22,20 @@ void reset_pack_idx_option(struct pack_idx_option *opts)
> opts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;
> }
>
> -static int sha1_compare(const void *_a, const void *_b)
> +static int oid_compare(const void *_a, const void *_b)
> {
> struct pack_idx_entry *a = *(struct pack_idx_entry **)_a;
> struct pack_idx_entry *b = *(struct pack_idx_entry **)_b;
> return oidcmp(&a->oid, &b->oid);
> }
>
> +static int oid_compare_compat(const void *_a, const void *_b)
> +{
> + struct pack_idx_entry *a = *(struct pack_idx_entry **)_a;
> + struct pack_idx_entry *b = *(struct pack_idx_entry **)_b;
> + return oidcmp(&a->compat_oid, &b->compat_oid);
> +}
> +
I wonder if we could've split the rename and the introduction of the
helper function into its own commit for the sake of better readability.
I don't feel strongly, though. I'm just suggesting it as a way to
possibly simplify this otherwise dense patch.
> static int cmp_uint32(const void *a_, const void *b_)
> {
> uint32_t a = *((uint32_t *)a_);
> @@ -50,30 +57,156 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
> sizeof(ofsval), cmp_uint32);
> }
>
> +static inline int last_matching_offset(const struct object_id *a, const struct object_id *b,
> + const struct git_hash_algo *algop)
> +{
> + size_t i;
> + for (i = 0; i < algop->rawsz; i++)
> + if (a->hash[i] != b->hash[i])
> + return i;
> + /* We should never hit this case. */
> + return i;
> +}
This returns the index of the first byte that *differs*, so the name
says the opposite of what it does. Something like first_differing_byte()
would read better at the call site. It also returns an int computed from
a size_t, and the caller stores it back in a size_t.
> +
> +struct pack_idx_format_header {
> + uint32_t id;
> + uint32_t short_name_len;
> + uint64_t offset;
> +};
> +
> [ ... snip ...]
>
> + hdr.hdr_len = htonl(hdrlen);
> + hdr.nr_objects = htonl(nr_objects);
> + hdr.nr_formats = htonl(nformats);
> + hashwrite(f, &hdr, sizeof(hdr));
> +
Given the struct is essentially a set of uint32_t and uint64_t, is there
a specific reason that we prefer packing data into a struct and writing
it using hashwrite rather than just writing them directly using
hashwrite_be32() / hashwrite_be64()?
+static void write_v3_header(struct repository *repo,
+ int nr_objects, int nr_large_offset,
+ uint32_t short_name_len[2], int padding[2],
+ struct hashfile *f)
+{
Shall we define nr_large_offset as an unsigned int to be consistent with
the caller?
> + uint64_t short_table = short_name_len[0] * nr_objects;
Can we cast to uint64_t before doing the arithmetic similar to how it is
done below?
> + /* padding */
> + if (short_table & 3) {
> + padding[0] = 4 - (short_table & 3);
> + offset += padding[0];
> + }
> +
> + format[0].id = htonl(repo->hash_algo->format_id);
> + format[0].offset = htonll(offset);
> + format[0].short_name_len = htonl(short_name_len[0]);
> + hashwrite(f, &format[0], sizeof(format[0]));
> + offset += (uint64_t)(short_name_len[0] + repo->hash_algo->rawsz + 4 + 4 + 4) * nr_objects +
> + 8 * nr_large_offset;
> +
"8 * nr_large_offset" is int arithmetic, Can we make it "(uint64_t)8 *
nr_large_offset" to keep the arithmetic uint64_t?
> + if (compat) {
> + short_table = short_name_len[1] * nr_objects;
> + /* padding */
> + if (short_table & 3) {
> + padding[1] = 4 - (short_table & 3);
> + offset += padding[1];
> + }
> +
> + format[1].id = htonl(compat->format_id);
> + format[1].offset = htonll(offset);
> + format[1].short_name_len = htonl(short_name_len[1]);
> + hashwrite(f, &format[1], sizeof(format[1]));
> + offset += (uint64_t)(short_name_len[1] + compat->rawsz + 4) * nr_objects;
> + }
> +
> + offset = htonll(offset);
> + hashwrite(f, &offset, sizeof(offset));
> +}
> +
> /*
> - * The *sha1 contains the pack content SHA1 hash.
> - * The objects array passed in will be sorted by SHA1 on exit.
> + * The *hash contains the pack content hash.
> + * The objects array passed in should be in pack order and will be sorted by
> + * object ID on return.
> */
"Should be in pack order" is a new requirement on existing callers. Have
we verified that all callers give us the array in pack order? Shall we
try to enforce the order in write_idx_file rather than expecting that
callers would've already verified it?
>
> if (nr_objects) {
> sorted_by_sha = objects;
> list = sorted_by_sha;
> last = sorted_by_sha + nr_objects;
> for (i = 0; i < nr_objects; ++i) {
> - if (objects[i]->offset > last_obj_offset)
> - last_obj_offset = objects[i]->offset;
> + objects[i]->idx = i;
> + if (need_large_offset(objects[i]->offset, opts))
> + nr_large_offset++;
> }
> [... snip ...]
>
> @@ -95,7 +228,8 @@ const char *write_idx_file(struct repository *repo,
> }
>
> /* if last object's offset is >= 2^31 we should use index V2 */
> - index_version = need_large_offset(last_obj_offset, opts) ? 2 : opts->version;
> + if (index_version == 1 && nr_large_offset)
> + index_version = 2;
It seems like we're changing the specific object in which we were
calling needs_large_offset. I'm not very sure why. I suppose it may be
worth a mention in the commit message, though.
Also, I suppose the comment above became stale.
> + if (index_version >= 3) {
> + /* write the sorted-to-pack index */
> + list = sorted_by_sha;
> + for (i = 0; i < nr_objects; i++) {
> + struct pack_idx_entry *obj = *list++;
> + uint32_t index = htonl(obj->idx);
> + hashwrite(f, &index, 4);
> + }
> + }
> +
> if (index_version >= 2) {
> unsigned int nr_large_offset = 0;
>
Can we avoiding redefining nr_large_offset here now that it is defined
at the function level?
>
> diff --git a/pack.h b/pack.h
> index ada506b5c5..86b2a8ba7b 100644
> --- a/pack.h
> +++ b/pack.h
> @@ -79,7 +79,9 @@ struct pack_idx_header {
> */
> struct pack_idx_entry {
> struct object_id oid;
> + struct object_id compat_oid;
> uint32_t crc32;
> + uint32_t idx;
> off_t offset;
> };
>
I suppose this would increase the pack_idx_entry size by roughly 40
bytes even for those users who don't use the compat algo. Is this
additional memory increase acceptable? Or shall we think of a better
alternative where only users who use a compat algo pay with additional
memory?
--
Sivaraam
next prev parent reply other threads:[~2026-11-30 16:05 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 7:25 [PATCH v2 00/13] SHA-1/SHA-256 interoperability, part 3: pack index v3 Christian Couder
2026-10-23 7:25 ` [PATCH v2 01/13] loose: allow looking up in object map with source Christian Couder
2026-11-26 13:28 ` Kaartic Sivaraam
2026-10-23 7:25 ` [PATCH v2 02/13] loose: rename repo_add_loose_object_map Christian Couder
2026-11-26 13:35 ` Kaartic Sivaraam
2026-10-23 7:25 ` [PATCH v2 03/13] loose: add a flag to control whether we write mapped OIDs Christian Couder
2026-11-26 13:57 ` Kaartic Sivaraam
2026-11-26 22:18 ` brian m. carlson
2026-10-23 7:25 ` [PATCH v2 04/13] odb: implement interoperability functions Christian Couder
2026-11-26 15:30 ` Kaartic Sivaraam
2026-10-23 7:25 ` [PATCH v2 05/13] object-file-convert: implement mapping in terms of object DB Christian Couder
2026-11-26 15:37 ` Kaartic Sivaraam
2026-10-23 7:25 ` [PATCH v2 06/13] pack-write: add support for pack index v3 Christian Couder
2026-11-30 16:05 ` Kaartic Sivaraam [this message]
2026-10-23 7:25 ` [PATCH v2 07/13] builtin: populate pack index v3 fields when indexing Christian Couder
2026-11-26 21:47 ` Junio C Hamano
2026-11-26 22:27 ` brian m. carlson
2026-11-26 22:58 ` Junio C Hamano
2026-10-23 7:25 ` [PATCH v2 08/13] object-file: handle compatibility algorithm Christian Couder
2026-10-23 7:25 ` [PATCH v2 09/13] packfile: add support for reading pack index v3 Christian Couder
2026-10-23 7:25 ` [PATCH v2 10/13] packfile: validate pack index v3 tables Christian Couder
2026-10-23 7:25 ` [PATCH v2 11/13] loose: map object IDs using pack index v3 Christian Couder
2026-10-23 7:25 ` [PATCH v2 12/13] packfile: allow looking up compat object IDs in packs Christian Couder
2026-10-23 7:25 ` [PATCH v2 13/13] doc: move pack index v3 documentation Christian Couder
2026-10-23 12:43 ` [PATCH v2 00/13] SHA-1/SHA-256 interoperability, part 3: pack index v3 Ben Knoble
2026-10-23 15:00 ` Junio C Hamano
2026-10-27 12:53 ` Christian Couder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54a6e8aa-e112-4686-b34b-5857f5060e27@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.