Re: [PATCH 2/3] commit-graph: use the hash version byte
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Aug 14, 2020, 20:11 UTC
- Message-ID
- <20200814201153.GK8085@camp.crustytoothpaste.net>
- In-Reply-To
- <4bbfd345d16da4604dd20decda8ecb12372e4223.1597428440.git.gitgitgadget@gmail.com>
On 2020-08-14 at 18:07:19, Derrick Stolee via GitGitGadget wrote:
Show 15 quoted lines
> diff --git a/commit-graph.c b/commit-graph.c
> index e51c91dd5b..d03328d64c 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -179,7 +179,11 @@ static char *get_chain_filename(struct object_directory *odb)
>
> static uint8_t oid_version(void)
> {
> - return 1;
> + if (the_hash_algo->rawsz == GIT_SHA1_RAWSZ)
> + return 1;
> + if (the_hash_algo->rawsz == GIT_SHA256_RAWSZ)
> + return 2;
> + die(_("invalid hash version"));
> }Can we maybe say something like this?
switch (hash_algo_by_ptr(the_hash_algo)) {
case GIT_HASH_SHA1:
return 1;
case GIT_HASH_SHA256:
return 2;
default:
die(_("invalid hash version"));
}That way if SHA-256 gets broken and we switch to another 256-bit hash (SHA-3-256?), we'll be forced to update this properly.
Show 14 quoted lines
> static struct commit_graph *alloc_commit_graph(void) > diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh > index c21cc160f3..906af2799d 100755 > --- a/t/t4216-log-bloom.sh > +++ b/t/t4216-log-bloom.sh > @@ -6,6 +6,12 @@ test_description='git log for a path with Bloom filters' > GIT_TEST_COMMIT_GRAPH=0 > GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 > > +OID_VERSION=1 > +if [ "$GIT_DEFAULT_HASH" = "sha256" ] > +then > + OID_VERSION=2 > +fi
Can we do something like this in the setup test instead?
test_oid_cache <<-EOF oid_version sha1:1 oid_version sha256:2 EOF
OID_VERSION=$(test_oid oid_version) # or, inline $(test_oid oid_version)
That uses the existing test framework to ensure we produce the right results if someone adds another hash algorithm and that we produce a BUG if the value is missing. It will also make it easier to write tests if we end up creating SHA-1- or SHA-256-specific tests, since we can look up those values directly with test_oid.
Since you're using this across several tests, you could even just add this to t/oid-info/hash-info like so:
commit_graph_oid_version sha1:1 commit_graph_oid_version sha256:2
and then it's set in one place and can be used without any required test_oid_cache invocations at all. I think three tests is sufficient basis for us to add an entry there.
-- brian m. carlson: Houston, Texas, US