From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, vdye@github.com,
newren@gmail.com, Jacob Keller <jacob.keller@gmail.com>,
Derrick Stolee <derrickstolee@github.com>
Subject: Re: [PATCH v3 2/4] read-cache: add index.skipHash config option
Date: Thu, 15 Dec 2022 17:12:01 +0100 [thread overview]
Message-ID: <221215.861qp03agm.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <00738c81a1212970910da6f29fe3ecef87c2ec3a.1671116820.git.gitgitgadget@gmail.com>
On Thu, Dec 15 2022, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <derrickstolee@github.com>
> + end = (unsigned char *)hdr + size;
Commentary: The "unsigned char *" cast has moved up here from the below,
that's needed (we're casting from the struct), and we should get rid of
it from below, good.
> + start = end - the_hash_algo->rawsz;
Okey, so here we mark the start, which is the end minus the rawsz,
but...
> + oidread(&oid, start);
> + if (oideq(&oid, null_oid()))
> + return 0;
> +
> the_hash_algo->init_fn(&c);
> the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
> the_hash_algo->final_fn(hash, &c);
> - if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
> + if (!hasheq(hash, end - the_hash_algo->rawsz))
...here we got rid of the cast, which is good, but let's not use "end -
the_hash_algo->rawsz" here, let's use "start", which you already
computed as "end - the_hash_algo->rawsz". This is just repeating it.
I wondered if I just missed it being modified in the interim before
carefully re-reading this, but we pass your tests with:
- if (!hasheq(hash, end - the_hash_algo->rawsz))
+ assert((end - the_hash_algo->rawsz) == start);
+ if (!hasheq(hash, start))
So, we can indeed juse the simpler "start" here, and it makes it easier
to read, as we're assured that it didn't move in the interim.
> + git_config_get_maybe_bool("index.skiphash", (int *)&f->skip_hash);
Aside from the question of whether we use the repo_*() variant here,
which I noted in my reply to the CL. The cast is suspicious.
So, in the 1/4 we added this as *unsigned*:
+ * If set to 1, skip_hash indicates that we should
+ * not actually compute the hash for this hashfile and
+ * instead only use it as a buffered write.
+ */
+ unsigned int skip_hash;
But you need the cast here since the config API can and will set the
"dest" to -1. See the "*dest == -1" test in git_configset_get_value().
So, here we're relying on a "unsigned int" cast'd to "int" correctly
doing the right thing on a "-1" assignment.
I'm not sure if that's portable or leads to undefined behavior, but in
any case, won't such a -1 value be read back as ~0 from that "unsigned
int" variable on most modern platforms?
Just bypassing that entirely and making it "int" seems better here, or
having an intermediate variable.
I also wondered if this was all my fault, in your original version you
were doing:
int skip_hash;
[...]
if (!git_config_get_maybe_bool("index.skiphash", &skip_hash))
f->skip_hash = skip_hash;
And I suggested that this was redundant, and that you could just write
to "f->skip_hash" directly.
But I didn't notice it was "unsigned", and in any case your original
version had the same issue of assigning a -1 to the unsigned variable...
next prev parent reply other threads:[~2022-12-15 16:20 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 17:25 [PATCH 0/4] Optionally skip hashing index on write Derrick Stolee via GitGitGadget
2022-12-07 17:25 ` [PATCH 1/4] hashfile: allow skipping the hash function Derrick Stolee via GitGitGadget
2022-12-07 22:13 ` Ævar Arnfjörð Bjarmason
2022-12-08 7:32 ` Jeff King
2022-12-07 17:25 ` [PATCH 2/4] read-cache: add index.skipHash config option Derrick Stolee via GitGitGadget
2022-12-07 18:59 ` Eric Sunshine
2022-12-12 13:59 ` Derrick Stolee
2022-12-12 18:55 ` Eric Sunshine
2022-12-07 22:25 ` Ævar Arnfjörð Bjarmason
2022-12-07 23:06 ` Ævar Arnfjörð Bjarmason
2022-12-08 0:05 ` Junio C Hamano
2022-12-12 14:05 ` Derrick Stolee
2022-12-12 18:01 ` Ævar Arnfjörð Bjarmason
2022-12-07 17:25 ` [PATCH 3/4] test-lib-functions: add helper for trailing hash Derrick Stolee via GitGitGadget
2022-12-07 22:27 ` Ævar Arnfjörð Bjarmason
2022-12-12 14:10 ` Derrick Stolee
2022-12-07 17:25 ` [PATCH 4/4] features: feature.manyFiles implies fast index writes Derrick Stolee via GitGitGadget
2022-12-07 22:30 ` Ævar Arnfjörð Bjarmason
2022-12-12 14:18 ` Derrick Stolee
2022-12-12 18:27 ` Ævar Arnfjörð Bjarmason
2022-12-07 23:27 ` [PATCH 0/4] Optionally skip hashing index on write Junio C Hamano
2022-12-07 23:42 ` Ævar Arnfjörð Bjarmason
2022-12-08 16:38 ` Derrick Stolee
2022-12-12 22:22 ` Jacob Keller
2022-12-12 16:31 ` [PATCH v2 " Derrick Stolee via GitGitGadget
2022-12-12 16:31 ` [PATCH v2 1/4] hashfile: allow skipping the hash function Derrick Stolee via GitGitGadget
2022-12-12 16:31 ` [PATCH v2 2/4] read-cache: add index.skipHash config option Derrick Stolee via GitGitGadget
2022-12-12 16:31 ` [PATCH v2 3/4] test-lib-functions: add helper for trailing hash Derrick Stolee via GitGitGadget
2022-12-12 18:14 ` SZEDER Gábor
2022-12-13 0:55 ` Junio C Hamano
2022-12-17 17:37 ` SZEDER Gábor
2022-12-12 16:31 ` [PATCH v2 4/4] features: feature.manyFiles implies fast index writes Derrick Stolee via GitGitGadget
2022-12-15 15:06 ` [PATCH v3 0/4] Optionally skip hashing index on write Derrick Stolee via GitGitGadget
2022-12-15 15:06 ` [PATCH v3 1/4] hashfile: allow skipping the hash function Derrick Stolee via GitGitGadget
2022-12-15 15:06 ` [PATCH v3 2/4] read-cache: add index.skipHash config option Derrick Stolee via GitGitGadget
2022-12-15 16:12 ` Ævar Arnfjörð Bjarmason [this message]
2022-12-15 15:06 ` [PATCH v3 3/4] test-lib-functions: add helper for trailing hash Derrick Stolee via GitGitGadget
2022-12-15 15:07 ` [PATCH v3 4/4] features: feature.manyFiles implies fast index writes Derrick Stolee via GitGitGadget
2022-12-15 15:56 ` [PATCH v3 0/4] Optionally skip hashing index on write Ævar Arnfjörð Bjarmason
2022-12-16 13:41 ` Derrick Stolee
2022-12-16 15:31 ` [PATCH v4 " Derrick Stolee via GitGitGadget
2022-12-16 15:31 ` [PATCH v4 1/4] hashfile: allow skipping the hash function Derrick Stolee via GitGitGadget
2022-12-16 15:31 ` [PATCH v4 2/4] read-cache: add index.skipHash config option Derrick Stolee via GitGitGadget
2022-12-16 15:31 ` [PATCH v4 3/4] test-lib-functions: add helper for trailing hash Derrick Stolee via GitGitGadget
2022-12-16 15:31 ` [PATCH v4 4/4] features: feature.manyFiles implies fast index writes Derrick Stolee via GitGitGadget
2022-12-16 15:43 ` [PATCH v4 0/4] Optionally skip hashing index on write Ævar Arnfjörð Bjarmason
2023-01-06 15:33 ` Derrick Stolee
2023-01-06 22:45 ` Junio C Hamano
2023-01-06 23:40 ` Derrick Stolee
2023-01-09 17:15 ` Ævar Arnfjörð Bjarmason
2023-01-09 18:00 ` Derrick Stolee
2023-01-09 19:22 ` Ævar Arnfjörð Bjarmason
2023-01-06 16:31 ` [PATCH v5 " Derrick Stolee via GitGitGadget
2023-01-06 16:31 ` [PATCH v5 1/4] hashfile: allow skipping the hash function Derrick Stolee via GitGitGadget
2023-01-06 16:31 ` [PATCH v5 2/4] read-cache: add index.skipHash config option Derrick Stolee via GitGitGadget
2023-01-06 16:31 ` [PATCH v5 3/4] test-lib-functions: add helper for trailing hash Derrick Stolee via GitGitGadget
2023-01-06 16:31 ` [PATCH v5 4/4] features: feature.manyFiles implies fast index writes Derrick Stolee via GitGitGadget
2023-01-15 9:31 ` [PATCH v5 0/4] Optionally skip hashing index on write Junio C Hamano
2023-01-17 14:49 ` Derrick Stolee
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=221215.861qp03agm.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=newren@gmail.com \
--cc=vdye@github.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).