git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 12/12] hash: stop depending on `the_repository` in `null_oid()`

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 7, 2025, 09:08 UTC
Message-ID
<Z8q3nzhl3DHETZgf@pks.im>
In-Reply-To
<xmqqr03ageej.fsf@gitster.g>
On Thu, Mar 06, 2025 at 11:14:28AM -0800, Junio C Hamano wrote:
Show 26 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> > index a4431429b7d..2d2e90bc23a 100644
> > --- a/builtin/ls-files.c
> > +++ b/builtin/ls-files.c
> > @@ -234,7 +234,7 @@ static void show_submodule(struct repository *superproject,
> >  {
> >  	struct repository subrepo;
> >  
> > -	if (repo_submodule_init(&subrepo, superproject, path, null_oid()))
> > +	if (repo_submodule_init(&subrepo, superproject, path, null_oid(the_hash_algo)))
> >  		return;
> >  
> >  	if (repo_read_index(&subrepo) < 0)
> 
> This has an obvious semantic interaction with what is done in
> Usman's series <20250306143629.1267358-7-usmanakinyemi202@gmail.com>
> where builtin/ls-files.c claims that it got rid of its dependence on
> the_repository.
> 
> The resulting ls-files still calls null_oid() here, hence it depends
> on the_hash_algo hence indirectly on the_repository.  When these
> topics are merged together, builtin/ls-files.c again needs to be
> marked that it still needs the_repository variable in order to see
> the_hash_algo.
Ah, thanks for catching this!
> I _think_ the subrepo is not allowed to use different hash from the
> superproject, so we can pass superproject->hash_algo instead in this
> series to make it easier on the other topic?

That's actually a very good question -- I have no idea. My gut says that it probably won't work, but on a conceptual level I think it would be nice if it did. Reality lies somewhere between. The following commands work alright:

    $ git init --object-format=sha256 repo
    $ cd repo
    $ git commit --allow-empty --message initial
    $ git submodule add https://github.com/git/git.git
    $ git -C git rev-parse --show-object-info HEAD
    sha1
    a36e024e989f4d35f35987a60e3af8022cac3420

We end up with a SHA1 submodule in a SHA256 repository. So far so good. How does it look like?

    $ git diff --cached
    diff --git a/.gitmodules b/.gitmodules
    new file mode 100644
    index 0000000..3594794
    --- /dev/null
    +++ b/.gitmodules
    @@ -0,0 +1,3 @@
    +[submodule "git"]
    +	path = git
    +	url = https://github.com/git/git.git
    diff --git a/git b/git
    new file mode 160000
    index 0000000..a36e024
    --- /dev/null
    +++ b/git
    @@ -0,0 +1 @@
    +Subproject commit a36e024e989f4d35f35987a60e3af8022cac3420000000000000000000000000

Well, now it starts to become weird, as the commit hash is obviously wrong. Can we update the submodule?

    $ git -C git switch next
    $ git diff
    diff --git a/git b/git
    index a36e024..4cd3354 160000
    --- a/git
    +++ b/git
    @@ -1 +1 @@
    -Subproject commit a36e024e989f4d35f35987a60e3af8022cac3420000000000000000000000000
    +Subproject commit 4cd33545ba4fa82324b454aa5bf2748b40a572fb

Well, that diff at least looks somewhat better than expected? Let's commit it.

    $ git commit -m update
    $ git diff HEAD~
    diff --git a/git b/git
    index a36e024..4cd3354 160000
    --- a/git
    +++ b/git
    @@ -1 +1 @@
    -Subproject commit a36e024e989f4d35f35987a60e3af8022cac3420000000000000000000000000
    +Subproject commit 4cd33545ba4fa82324b454aa5bf2748b40a572fb000000000000000000000000

Oh, well... so, what happens if we ask git-log(1) to recurse into the submodule?

    $ git log --submodule=diff --patch
    Segmentation fault (core dumped)
Yeah, no, that's not really working.

So in theory, I don't really think there is anything that keeps us from mixing object formats, and I even think that this is a necessary feature to have once people start to migrate their repositories to SHA256. There are people out there who use submodules, and it may not be feasible for them to wait until all of their submodules have been converted to SHA256 to migrate their own repositories.

From my perspective, we should thus treat it as a bug that the above does not work.

> What do you think?

Anyway, that was a bit of a tangent to your initial question: which hash should we be passing in the first place? As it turns out, we should be passing the superproject's null OID indeed. The object ID we pass to `repo_submodule_init()` does not describe any object in the submodule itself, but rather indicates which tree-ish the submodule information should be parsed from in the superproject. As such, it refers to an object in the superproject itself and should thus use its object hash.

I'll include such a change in my patch series to resolve the semantic conflict.

Show 12 quoted lines
> Perhaps we should have hidden null_oid() as requiring the_repository
> just like the_hash_algo is guarded like so
> 
>         #ifdef USE_THE_REPOSITORY_VARIABLE
>         # include "repository.h"
>         # define the_hash_algo the_repository->hash_algo
>         #endif
> 
> in <hash.h>.
> 
> In other words, I wish we had the following patch already applied,
> before Usman started working on the other topic.

True. `USE_THE_REPOSITORY_VARIABLE` has always been best effort, and it was clear from the beginning that it won't catch all functions that implicitly depend on `the_repository`. The good news is that we uncover and convert more and more of those implicit dependencies, so as time progresses it becomes more accurate.

> But with this topic getting solidified, it would become a moot point
> to do that in the longer term.  This series removes null_oid() that
> had the implicit dependency anyway.
Indeed.
Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 39 of 73 in “Stop depending on `the_repository` in object-related subsystems”
  1. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 3, 2025
  2. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  3. Karthik NayakMar 6, 2025
  4. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 3, 2025
  5. Justin ToblerMar 4, 2025
  6. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  7. Karthik NayakMar 6, 2025
  8. Patrick SteinhardtMar 6, 2025
  9. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  10. Karthik NayakMar 6, 2025
  11. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 3, 2025
  12. Justin ToblerMar 4, 2025
  13. Patrick SteinhardtMar 6, 2025
  14. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  15. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  16. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  17. Justin ToblerMar 4, 2025
  18. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  19. Justin ToblerMar 4, 2025
  20. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 3, 2025
  21. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 3, 2025
  22. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 3, 2025
  23. Justin ToblerMar 4, 2025
  24. Karthik NayakMar 6, 2025
  25. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 6, 2025
  26. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  27. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  28. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 6, 2025
  29. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 6, 2025
  30. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  31. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  32. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  33. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  34. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  35. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 6, 2025
  36. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 6, 2025
  37. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 6, 2025
  38. Junio C HamanoMar 6, 2025
  39. Patrick SteinhardtMar 7, 2025
  40. Junio C HamanoMar 7, 2025
  41. Karthik NayakMar 6, 2025
  42. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 7, 2025
  43. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  44. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  45. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 7, 2025
  46. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  47. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 7, 2025
  48. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  49. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  50. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  51. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  52. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 7, 2025
  53. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 7, 2025
  54. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 7, 2025
  55. Elijah NewrenMar 8, 2025
  56. Patrick SteinhardtMar 10, 2025
  57. Elijah NewrenMar 10, 2025
  58. Junio C HamanoMar 10, 2025
  59. Elijah NewrenMar 8, 2025
  60. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 10, 2025
  61. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  62. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  63. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 10, 2025
  64. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 10, 2025
  65. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  66. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  67. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  68. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  69. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  70. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 10, 2025
  71. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 10, 2025
  72. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 10, 2025
  73. Elijah NewrenMar 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.