git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Elijah Newren <newren@gmail.com>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>,
	Justin Tobler <jltobler@gmail.com>
Subject: Re: [PATCH v3 12/12] hash: stop depending on `the_repository` in `null_oid()`
Date: Mon, 10 Mar 2025 08:11:03 +0100	[thread overview]
Message-ID: <Z86Qh1yLUC7aIaG9@pks.im> (raw)
In-Reply-To: <CABPp-BG0AtKdUH2g8+_f0J0ViWs5xZKM9kCcbWYZ=uEu6bswdQ@mail.gmail.com>

On Sat, Mar 08, 2025 at 08:05:09AM -0800, Elijah Newren wrote:
> 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!

> > @@ -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

  reply	other threads:[~2025-03-10  7:11 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03  8:47 [PATCH 00/12] Stop depending on `the_repository` in object-related subsystems Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 10:37   ` Karthik Nayak
2025-03-03  8:47 ` [PATCH 02/12] object: " Patrick Steinhardt
2025-03-06 11:07   ` Karthik Nayak
2025-03-06 14:55     ` Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-04 18:46   ` Justin Tobler
2025-03-03  8:47 ` [PATCH 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-04 19:32   ` Justin Tobler
2025-03-06 14:54     ` Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 11:14   ` Karthik Nayak
2025-03-03  8:47 ` [PATCH 06/12] pack-revindex: " Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 08/12] object-file-convert: " Patrick Steinhardt
2025-03-04 19:45   ` Justin Tobler
2025-03-03  8:47 ` [PATCH 09/12] delta-islands: " Patrick Steinhardt
2025-03-04 19:48   ` Justin Tobler
2025-03-03  8:47 ` [PATCH 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-03  8:47 ` [PATCH 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-04 20:16   ` Justin Tobler
2025-03-06 11:20 ` [PATCH 00/12] Stop depending on `the_repository` in object-related subsystems Karthik Nayak
2025-03-06 15:10 ` [PATCH v2 " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 02/12] object: " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 06/12] pack-revindex: " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 08/12] object-file-convert: " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 09/12] delta-islands: " Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-06 15:10   ` [PATCH v2 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-06 19:14     ` Junio C Hamano
2025-03-07  9:08       ` Patrick Steinhardt
2025-03-07 16:53         ` Junio C Hamano
2025-03-06 15:29   ` [PATCH v2 00/12] Stop depending on `the_repository` in object-related subsystems Karthik Nayak
2025-03-07 14:18 ` [PATCH v3 " Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 02/12] object: " Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-07 14:18   ` [PATCH v3 06/12] pack-revindex: " Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 08/12] object-file-convert: " Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 09/12] delta-islands: " Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-07 14:19   ` [PATCH v3 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-08 16:05     ` Elijah Newren
2025-03-10  7:11       ` Patrick Steinhardt [this message]
2025-03-10 22:37         ` Elijah Newren
2025-03-10 15:38       ` Junio C Hamano
2025-03-08 16:11   ` [PATCH v3 00/12] Stop depending on `the_repository` in object-related subsystems Elijah Newren
2025-03-10  7:13 ` [PATCH v4 " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 02/12] object: " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 06/12] pack-revindex: " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 08/12] object-file-convert: " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 09/12] delta-islands: " Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-10  7:13   ` [PATCH v4 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-10 22:39   ` [PATCH v4 00/12] Stop depending on `the_repository` in object-related subsystems Elijah Newren

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=Z86Qh1yLUC7aIaG9@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    --cc=karthik.188@gmail.com \
    --cc=newren@gmail.com \
    /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).