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

Re: [PATCH 2/3] commit-graph: use the hash version byte

From
Derrick Stolee <stolee@gmail.com>
Date
Aug 14, 2020, 20:36 UTC
Message-ID
<7082f3c9-652e-36d9-26ae-d1f86e872480@gmail.com>
In-Reply-To
<20200814201153.GK8085@camp.crustytoothpaste.net>
On 8/14/2020 4:11 PM, brian m. carlson wrote:
Show 72 quoted lines
> On 2020-08-14 at 18:07:19, Derrick Stolee via GitGitGadget wrote:
>> 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.
> 
>>  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.

I appreciate the suggested improvements here. I'm happy to do something more similar to other places in the code.

These will be part of my v2 to be re-rolled early next week.

Thanks, -Stolee

Previous: Junio C HamanoNext: Martin Ågren
Message 11 of 22 in “SHA-256: Update commit-graph and multi-pack-index formats”
  1. 0/3 SHA-256: Update commit-graph and multi-pack-index formatsDerrick Stolee via GitGitGadget, Aug 14, 2020
  2. 1/3 t/README: document GIT_TEST_DEFAULT_HASHDerrick Stolee via GitGitGadget, Aug 14, 2020
  3. Junio C HamanoAug 14, 2020
  4. Eric SunshineAug 14, 2020
  5. Derrick StoleeAug 14, 2020
  6. 2/3 commit-graph: use the hash version byteDerrick Stolee via GitGitGadget, Aug 14, 2020
  7. Junio C HamanoAug 14, 2020
  8. Taylor BlauAug 14, 2020
  9. brian m. carlsonAug 14, 2020
  10. Junio C HamanoAug 14, 2020
  11. Derrick StoleeAug 14, 2020
  12. Martin ÅgrenAug 15, 2020
  13. 3/3 multi-pack-index: use hash version byteDerrick Stolee via GitGitGadget, Aug 14, 2020
  14. brian m. carlsonAug 14, 2020
  15. Junio C HamanoAug 14, 2020
  16. Derrick StoleeAug 14, 2020
  17. Junio C HamanoAug 14, 2020
  18. 0/3 SHA-256: Update commit-graph and multi-pack-index formatsDerrick Stolee via GitGitGadget, Aug 17, 2020
  19. 1/3 t/README: document GIT_TEST_DEFAULT_HASHDerrick Stolee via GitGitGadget, Aug 17, 2020
  20. 2/3 commit-graph: use the "hash version" byteDerrick Stolee via GitGitGadget, Aug 17, 2020
  21. 3/3 multi-pack-index: use hash version byteDerrick Stolee via GitGitGadget, Aug 17, 2020
  22. brian m. carlsonAug 17, 2020

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.