git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Schroeder <mls@suse.de>
To: "brian m. carlson" <sandals@crustytoothpaste.net>,
	git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH] submodule: truncate the oid when fetchig commits
Date: Mon, 18 Aug 2025 11:30:51 +0200	[thread overview]
Message-ID: <aKLyy8nwGQCT-jvB@suse.de> (raw)
In-Reply-To: <aJ5gOPQ9oologqj-@fruit.crustytoothpaste.net>

On Thu, Aug 14, 2025 at 10:16:24PM +0000, brian m. carlson wrote:
> On 2025-08-14 at 15:06:32, Michael Schroeder wrote:
> > If a submodule uses a different hash algorithm than used in
> > the main repository, the recorded submodule commit is padded
> > with zeros. This is usually not a problem as the default is to
> > do submodule clones non-shallow and the commit can be found
> > in the local objects.
> 
> This should not even work at all.  It may currently behave as you
> suggest when the main repository is SHA-256 and the submodule is SHA-1,
> but it will corrupt the data if the submodule is SHA-256 and the main
> repository is SHA-1, since then the data will be truncated.

But it works, and I'm pretty sure people already use it. If you
have a sha1 main repo and a sha256 submodule, git will truncate
the commit when recording the gitlink. The checkout done by
git submodule update will work as it does the normal prefix matching.

If you have a sha256 main repo and a sha submodule, the recorded
commit is padded with zero. The checkout will also work as git
ignores the extra data since commit 52fca06db2 (object-names: support
input of oids in any supported hash, 2023-10-01).

What doesn't work is if a shallow clone is done for the submodule.
In that case the commit is not reachable and git tries a direct
fetch. This fetch can be made to work if the commit was padded with
zeros. If the commit was truncated, we would probably need some
protocol extension to make the server do a prefix match for a
"want" request.

> The proper way for this to work is that the SHA-1 version of the
> repository stores submodules in their SHA-1 states and the SHA-256
> version of the repository stores submodules in their SHA-256 states.

You mean by using "compatObjectFormat"? I couldn't make that work,
but maybe I missed something. Anyway, I think this also will not
work for shallow clones.

Cheers,
  Michael.

-- 
Michael Schroeder          SUSE Software Solutions Germany GmbH
mls@suse.de               GF: Ivo Totev HRB 36809, AG Nuernberg
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}

  reply	other threads:[~2025-08-18  9:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14 15:06 [PATCH] submodule: truncate the oid when fetchig commits Michael Schroeder
2025-08-14 15:42 ` Junio C Hamano
2025-08-18  9:15   ` [PATCH v2] " Michael Schroeder
2025-08-14 22:16 ` [PATCH] " brian m. carlson
2025-08-18  9:30   ` Michael Schroeder [this message]
2025-08-19  0:45     ` brian m. carlson

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=aKLyy8nwGQCT-jvB@suse.de \
    --to=mls@suse.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).