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

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

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 10, 2025, 07:11 UTC
Message-ID
<Z86Qh1yLUC7aIaG9@pks.im>
In-Reply-To
<CABPp-BG0AtKdUH2g8+_f0J0ViWs5xZKM9kCcbWYZ=uEu6bswdQ@mail.gmail.com>
On Sat, Mar 08, 2025 at 08:05:09AM -0800, Elijah Newren wrote:
Show 47 quoted lines
> On Fri, Mar 7, 2025 at 6:20 AM Patrick Steinhardt <ps@pks.im> wrote:
> >
> > The `null_oid()` function returns the object ID that only consists of
> > zeroes. Naturally, this ID also depends on the hash algorithm used, as
> > the number of zeroes is different between SHA1 and SHA256. Consequently,
> > the function returns the hash-algorithm-specific null object ID.
> >
> > This is currently done by depending on `the_hash_algo`, which implicitly
> > makes us depend on `the_repository`. Refactor the function to instead
> > pass in the hash algorithm for which we want to retrieve the null object
> > ID. Adapt callsites accordingly by passing in `the_repository`, thus
> > bubbling up the dependency on that global variable by one layer.
> >
> > There are a couple of trivial exceptions for subsystems that already got
> > rid of `the_repository`. These subsystems instead use the repository
> > that is available via the calling context:
> >
> >   - "builtin/grep.c"
> >   - "grep.c"
> >   - "refs/debug.c"
> >
> > There are also two non-trivial exceptions:
> >
> >   - "diff-no-index.c": Here we know that we may not have a repository
> >     initialized at all, so we cannot rely on `the_repository`. Instead,
> >     we adapt `diff_no_index()` to get a `struct git_hash_algo` as
> >     parameter. The only caller is located in "builtin/diff.c", where we
> >     know to call `repo_set_hash_algo()` in case we're running outside of
> >     a Git repository. Consequently, it is fine to continue passing
> >     `the_repository->hash_algo` even in this case.
> >
> >   - "builtin/ls-files.c": There is an in-flight patch series that drops
> >     `USE_THE_REPOSITORY_VARIABLE` in this file, which causes a semantic
> >     conflict because we use `null_oid()` in `show_submodule()`. The
> >     value is passed to `repo_submodule_init()`, which may use the object
> >     ID to resolve a tree-ish in the superproject from which we want to
> >     read the submodule config. As such, the object ID should refer to an
> >     object in the superproject, and consequently we need to use its hash
> >     algorithm.
> >
> > This means that we could in theory just not bother about this edge case
> > at all and just use `the_repository` in "diff-no-index.c". But doing so
> > would feel misdesigned.
> 
> Very minor, but this was a bit jarring to me -- shouldn't this
> paragraph be indented over since it is a continuation of the second
> bullet above?
Yes, you're right!
Show 12 quoted lines
> > @@ -4304,7 +4304,7 @@ static int process_entry(struct merge_options *opt,
> >                 /* Deleted on both sides */
> >                 ci->merged.is_null = 1;
> >                 ci->merged.result.mode = 0;
> > -               oidcpy(&ci->merged.result.oid, null_oid());
> > +               oidcpy(&ci->merged.result.oid, null_oid(the_hash_algo));
> >                 assert(!ci->df_conflict);
> >                 ci->merged.clean = !ci->path_conflict;
> >         }
> 
> What you have is an improvement since it's at least making things
> explicit, but these should really be opt->repo->hash_algo.

Oh, yeah, I suspect that we'll have a bunch of places where we can already plug in a repository as available via the context. I typically refrain from doing though unless really necessary (e.g. when the file at hand doesn't declare `USE_THE_REPOSITORY_VARIABLE` anymore). This is so that neither I nor reviewers have to carefully vet every callsite, but to make this a mechanical change that is obviously correct because it is identical to the old state. So I'm basically leaving it to the next patch series that gets rid of `USE_THE_REPOSITORY_VARIABLE` to think more carefully about those callsites.

Thanks!
Patrick
Previous: Elijah NewrenNext: Elijah Newren
Message 56 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.