From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org,
"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 07/13] builtin: populate pack index v3 fields when indexing
Date: Thu, 26 Nov 2026 13:47:38 -0800 [thread overview]
Message-ID: <xmqq1p87i7t1.fsf@gitster.g> (raw)
In-Reply-To: <20261023072559.3204273-8-christian.couder@gmail.com> (Christian Couder's message of "Fri, 23 Oct 2026 09:25:52 +0200")
Christian Couder <christian.couder@gmail.com> writes:
> Right now, we have support for writing pack index v3. However, we need
> to populate the compatibility object ID in order to write it into the
> repository. Let's do so by converting the objects from SHA-256 to SHA-1
> as part of our indexing process.
Small wording note. The code handles both hash_algo-to-compat_hash_algo
directions symmetrically, not only SHA-256 to SHA-1.
> @@ -483,8 +493,15 @@ static void *unpack_entry_data(off_t offset, size_t size,
> hdrlen = format_object_header(hdr, sizeof(hdr), type, size);
> git_hash_init(&c, the_hash_algo);
> git_hash_update(&c, hdr, hdrlen);
> - } else
> + if (compat && compat_oid) {
> + git_hash_init(&c_compat, compat);
Doesn't this regress indexing using v2, though?
Here in unpack_entry_data() (called with &obj->idx.compat_oid from
parse_pack_objects()), and similarly in resolve_delta() when checking
'if (the_repository->compat_hash_algo)', the conversion runs even when
opts.version < 3. Because index-pack cannot yet convert commits or
trees whose referenced objects appear later in the pack, running an
ordinary 'git index-pack' writing a v2 index in a compat repository will
now fail on packs that previously succeeded, even though '.compat_oid'
is discarded for v2. Gating compat calculation on 'opts.version >= 3'
(for example, passing NULL for compat_oid from parse_pack_objects() when
opts.version < 3, and checking opts.version >= 3 in resolve_delta())
would avoid regressing v2 indexing.
> @@ -514,13 +533,43 @@ static void *unpack_entry_data(off_t offset, size_t size,
> ...
> + repo_unlock();
> + if (ret < 0)
> + bad_object(offset, _("could not convert object"));
> + hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX,
> + type_name(type),(uintmax_t)outbuf.len) + 1;
A space is missing after a comma, but earlier in unpack_entry_data() we
already use format_object_header(), which avoids spelling out the
xsnprintf() format string. Should this code do the same?
When running 'git index-pack --stdin --fix-thin --index-version=3',
fix_unresolved_deltas() would append local base objects via
append_obj_to_pack(), and that helper only populates obj->idx.oid:
obj = &objects[nr_objects++];
...
oidcpy(&obj->idx.oid, oid);
but not the .compat_oid member.
Leaving obj->idx.compat_oid zero-initialized writes null OIDs into the
v3 index for every appended local base, and with '--strict' two or more
appended bases collide as duplicate zero OIDs in write_idx_file(), no?
Looking up the local base's compat OID with repo_oid_to_algop() (and
recording it in the in-memory OID map so subsequent deltas against that
base can convert) may close this gap, but I am not sure.
> @@ -1847,6 +1850,9 @@ static struct object_entry *create_object_entry(const struct object_id *oid,
>
> entry = packlist_alloc(&to_pack, oid);
> entry->hash = hash;
> + if (repo_oid_to_algop(the_repository, &entry->idx.oid,
> + the_repository->compat_hash_algo, &entry->idx.compat_oid) < 0)
> + die(_("can't map object %s while writing pack"), oid_to_hex(oid));
In builtin/pack-objects.c:create_object_entry(), this unconditionally
looks up compat OIDs and dies on failure even when pack_to_stdout is set
(in other words, no '.idx' file is written), pack_idx_opts.version < 3,
or 'exclude' is non-zero (for preferred_base objects that are never
written to the pack or index).
In a compat repository where an object still lacks a mapping (such as a
v2 pack without loose-object-idx, or a thin pack sent over stdout), 'git
pack-objects --stdout' or v2 repacks will die unnecessarily. Limiting
this lookup to 'the_repository->compat_hash_algo && !pack_to_stdout &&
pack_idx_opts.version >= 3 && !exclude' may avoid that failure, but I am
not sure if that is sufficient.
Thanks.
next prev parent reply other threads:[~2026-11-26 21:47 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
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 [this message]
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=xmqq1p87i7t1.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--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.