From: Phillip Wood <phillip.wood123@gmail.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Cc: Ghanshyam Thakkar <shyamthakkar001@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()`
Date: Thu, 13 Jun 2024 11:01:35 +0100 [thread overview]
Message-ID: <66763b5a-3ea6-481f-b4d3-5fad76f5da0c@gmail.com> (raw)
In-Reply-To: <4858cca25fe9e57c984fc3181fe8498d0b7222b0.1718259125.git.ps@pks.im>
On 13/06/2024 07:14, Patrick Steinhardt wrote:
> The `empty_tree_oid_hex()` function use `the_repository` to derive the
> hash function that shall be used. Require callers to pass in the hash
> algorithm to get rid of this implicit dependency.
Many of these call sites already have a repository instance available so
don't need to use "the_repository". I haven't checked but with these
changes it might be possible to remove some of these files from the next
patch.
I've only really looked at this patch in this series as I was just
checking for changes to the sequencer code. As for the series as a whole
I think adding USE_THE_REPOSITORY_VARIABLE is a good direction.
> While at it, remove the unused `empty_blob_oid_hex()` function.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> add-interactive.c | 2 +-
> add-patch.c | 2 +-
> builtin/merge.c | 3 ++-
> builtin/receive-pack.c | 2 +-
> hash-ll.h | 3 +--
> object-file.c | 10 ++--------
> sequencer.c | 2 +-
> submodule.c | 6 +++---
> wt-status.c | 4 ++--
> 9 files changed, 14 insertions(+), 20 deletions(-)
>
> diff --git a/add-interactive.c b/add-interactive.c
> index b5d6cd689a..a0961096cd 100644
> --- a/add-interactive.c
> +++ b/add-interactive.c
> @@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
> s.skip_unseen = filter && i;
>
> opt.def = is_initial ?
> - empty_tree_oid_hex() : oid_to_hex(&head_oid);
> + empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
The hunk fragment shows that we already have a struct repository
instance in this function which we should use instead of "the_repository"
> diff --git a/add-patch.c b/add-patch.c
> index 814de57c4a..86181770f2 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> /* could be on an unborn branch */
> !strcmp("HEAD", s->revision) &&
> repo_get_oid(the_repository, "HEAD", &oid) ?
> - empty_tree_oid_hex() : s->revision);
> + empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
It's not obvious from this hunk but there is a repository instance in
"s->s->r" which we should use instead of "the_repository"
> diff --git a/sequencer.c b/sequencer.c
> index 68d62a12ff..823691e379 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
> unborn = 1;
> } else if (unborn)
> oidcpy(&head, the_hash_algo->empty_tree);
> - if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
> + if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
The hunk fragment shows that we already have a struct repository
instance in "r" which we should use instead of "the_repository" here.
> diff --git a/wt-status.c b/wt-status.c
> index ff4be071ca..5051f5e599 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
>
> repo_init_revisions(s->repo, &rev, NULL);
> memset(&opt, 0, sizeof(opt));
> - opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
> + opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
The context line above shows us that we have a repository instance
available so we should use "s->repo" instead of "the_repository"
> @@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
> rev.diffopt.ita_invisible_in_index = 1;
>
> memset(&opt, 0, sizeof(opt));
> - opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
> + opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
We should use "s->repo" here as well
Best Wishes
Phillip
next prev parent reply other threads:[~2024-06-13 10:01 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 11:57 [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 01/21] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 02/21] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 03/21] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 04/21] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-11 11:57 ` [PATCH 05/21] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 06/21] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 07/21] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 08/21] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 09/21] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 10/21] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 11/21] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 12/21] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 13/21] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 14/21] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 15/21] replace-object: " Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 16/21] compat/fsmonitor: remove dependency on `the_repository` in Darwin IPC Patrick Steinhardt
2024-06-11 23:16 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 17/21] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-11 11:58 ` [PATCH 18/21] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-11 13:23 ` Ghanshyam Thakkar
2024-06-11 11:59 ` [PATCH 19/21] t/helper: remove dependency on `the_repository` in "oidtree" Patrick Steinhardt
2024-06-11 12:57 ` Ghanshyam Thakkar
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 23:17 ` brian m. carlson
2024-06-12 7:38 ` Patrick Steinhardt
2024-06-11 11:59 ` [PATCH 20/21] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-11 11:59 ` [PATCH 21/21] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-11 23:24 ` [PATCH 00/21] Introduce `USE_THE_REPOSITORY_VARIABLE` macro brian m. carlson
2024-06-12 7:37 ` Patrick Steinhardt
2024-06-12 10:12 ` Ghanshyam Thakkar
2024-06-13 6:13 ` [PATCH v2 00/20] " Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-13 6:13 ` [PATCH v2 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-13 10:01 ` Phillip Wood [this message]
2024-06-13 15:39 ` Junio C Hamano
2024-06-14 5:23 ` Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 15/20] replace-object: " Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-13 6:14 ` [PATCH v2 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-13 18:01 ` [PATCH v2 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Junio C Hamano
2024-06-13 18:48 ` Junio C Hamano
2024-06-13 23:14 ` Ramsay Jones
2024-06-13 23:18 ` Junio C Hamano
2024-06-13 23:55 ` Ramsay Jones
2024-06-14 0:17 ` Junio C Hamano
2024-06-14 5:28 ` Patrick Steinhardt
2024-06-14 15:54 ` Junio C Hamano
2024-06-14 6:49 ` [PATCH v3 " Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 01/20] hash: drop (mostly) unused `is_empty_{blob,tree}_sha1()` functions Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 02/20] hash: require hash algorithm in `hasheq()`, `hashcmp()` and `hashclr()` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 03/20] hash: require hash algorithm in `oidread()` and `oidclr()` Patrick Steinhardt
2024-06-14 6:49 ` [PATCH v3 04/20] global: ensure that object IDs are always padded Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 05/20] hash: convert `oidcmp()` and `oideq()` to compare whole hash Patrick Steinhardt
2024-06-17 9:18 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 06/20] hash: make `is_null_oid()` independent of `the_repository` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 07/20] hash: require hash algorithm in `is_empty_{blob,tree}_oid()` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 08/20] hash: require hash algorithm in `empty_tree_oid_hex()` Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 09/20] global: introduce `USE_THE_REPOSITORY_VARIABLE` macro Patrick Steinhardt
2024-06-17 9:30 ` Karthik Nayak
2024-06-18 5:16 ` Patrick Steinhardt
2024-06-18 9:25 ` Karthik Nayak
2024-06-18 15:58 ` Junio C Hamano
2024-06-18 16:56 ` Junio C Hamano
2024-06-18 20:20 ` Karthik Nayak
2024-06-14 6:50 ` [PATCH v3 10/20] refs: avoid include cycle with "repository.h" Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 11/20] hash-ll: merge with "hash.h" Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 12/20] http-fetch: don't crash when parsing packfile without a repo Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 13/20] oidset: pass hash algorithm when parsing file Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 14/20] protocol-caps: use hash algorithm from passed-in repository Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 15/20] replace-object: " Patrick Steinhardt
2024-06-14 6:50 ` [PATCH v3 16/20] compat/fsmonitor: fix socket path in networked SHA256 repos Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 17/20] t/helper: use correct object hash in partial-clone helper Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 18/20] t/helper: fix segfault in "oid-array" command without repository Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 19/20] t/helper: remove dependency on `the_repository` in "proc-receive" Patrick Steinhardt
2024-06-14 6:51 ` [PATCH v3 20/20] hex: guard declarations with `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2024-06-18 9:56 ` [PATCH v3 00/20] Introduce `USE_THE_REPOSITORY_VARIABLE` macro Phillip Wood
2024-06-18 20:22 ` Karthik Nayak
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=66763b5a-3ea6-481f-b4d3-5fad76f5da0c@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
--cc=shyamthakkar001@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).