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

Re: [PATCH v3] show-index: fix uninitialized hash function

From
Abhijeet Sonar <abhijeet.nkt@gmail.com>
Date
Oct 29, 2024, 11:54 UTC
Message-ID
<26d1bd3c-4f90-4406-8a1f-2eb085c46bab@gmail.com>
In-Reply-To
<Zx8ijtkn7y6eBQ-n@pks.im>
On 28/10/24 11:05, Patrick Steinhardt wrote:
Show 18 quoted lines
> On Sun, Oct 27, 2024 at 08:10:16PM -0400, Taylor Blau wrote:
>> On Sat, Oct 26, 2024 at 05:39:50PM +0530, Abhijeet Sonar wrote:
>>> diff --git a/builtin/show-index.c b/builtin/show-index.c
>>> index f164c01bbe..978ae70470 100644
>>> --- a/builtin/show-index.c
>>> +++ b/builtin/show-index.c
>>> @@ -38,6 +38,9 @@ int cmd_show_index(int argc,
>>>  		repo_set_hash_algo(the_repository, hash_algo);
>>>  	}
>>>
>>> +	if (!the_hash_algo)
>>> +		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> 
> Let's add a todo-comment here. The behaviour with this patch is somewhat
> broken as you cannot inspect indices that use any other object hash than
> SHA256 outside of a repository. This is fine from my point of view and
> nothing that you have to fix here, as you simply fix up the broken
> behaviour. But in the future, we should either:
I will add those comments, thanks.
> 
>   - Add logic to detect the format of the passed-in index and set that
>     up as the hash algorithm

I am very interested in hacking around and trying to implement this. I read about the index format here: https://git-scm.com/docs/index-format and (assuming I am looking at the right thing) it does not seem like index files contain information about the hash algorithm used in their headers or anywhere else. Are there other leads I should follow?

> 
>   - If that is impossible, add a command line option to pick the hash
>     algo.
>

Actually there is already an option (--object-format) that allows changing the hash algo used, it's just that default format is SHA1 when one is not specified. (or at least will be, after this patch)

Show 24 quoted lines
>>>  	hashsz = the_hash_algo->rawsz;
>>>
>>>  	if (fread(top_index, 2 * 4, 1, stdin) != 1)
>>> diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
>>> index 3b9dae331a..51fed26cc4 100755
>>> --- a/t/t5300-pack-object.sh
>>> +++ b/t/t5300-pack-object.sh
>>> @@ -523,6 +523,10 @@ test_expect_success 'index-pack --strict <pack> works in non-repo' '
>>>  	test_path_is_file foo.idx
>>>  '
>>>
>>> +test_expect_success SHA1 'show-index works OK outside a repository' '
>>> +	nongit git show-index <foo.idx
>>> +'
> 
> So how does this behave with SHA256? Does it raise an error? Does it
> segfault?
> 
> I think it's okay to fail with SHA256 for now, but I'd like the
> failure behaviour to be cleanish. So I'd prefer to not skip the test
> completely, but adapt our expectations based on the hash algo. Or have
> two separate tests, one for each hash, that explicitly init the repo
> with `git init --ref-format=$hash`, and then exercise the behaviour for
> each of the>

Running show-index outside of a repository with a SHA256 based index file gives:

$ git show-index <foo.idx fatal: inconsistent 64b offset index

At the very least, it does not crash.
Show 13 quoted lines
>>>  test_expect_success !PTHREADS,!FAIL_PREREQS \
>>>  	'index-pack --threads=N or pack.threads=N warns when no pthreads' '
>>>  	test_must_fail git index-pack --threads=2 2>err &&
>>> --
>>> 2.47.0.107.g34b6ce9b30
>>
>> These all look reasonable and as-expected to me. Patrick (CC'd) has been
>> reviewing similar changes elsewhere, so I'd like him to chime in as well
>> on whether or not this looks good to go.
> 
> Ah, thanks. I've missed this topic somehow.
> 
> Patrick
Thanks
Previous: Junio C HamanoNext: Abhijeet Sonar
Message 22 of 27 in “show-index: fix uninitialized hash function”
  1. show-index: fix uninitialized hash functionAbhijeet Sonar, Jul 12, 2024
  2. Junio C HamanoJul 12, 2024
  3. show-index: fix uninitialized hash functionAbhijeet Sonar, Jul 15, 2024
  4. Re* [PATCH v2] show-index: fix uninitialized hash functionJunio C Hamano, Jul 15, 2024
  5. show-index: fix uninitialized hash functionAbhijeet Sonar, Oct 26, 2024
  6. Taylor BlauOct 28, 2024
  7. Patrick SteinhardtOct 28, 2024
  8. Taylor BlauOct 28, 2024
  9. show-index: fix uninitialized hash functionAbhijeet Sonar, Nov 1, 2024
  10. Junio C HamanoNov 2, 2024
  11. Abhijeet SonarNov 2, 2024
  12. 0/2 show-index: fix uninitialized hash functionAbhijeet Sonar, Nov 4, 2024
  13. 1/2 show-index: fix uninitialized hash functionAbhijeet Sonar, Nov 4, 2024
  14. 2/2 t5300: add test for 'show-index --object-format'Abhijeet Sonar, Nov 4, 2024
  15. Junio C HamanoNov 5, 2024
  16. 0/2 show-index: fix uninitialized hash functionAbhijeet Sonar, Nov 9, 2024
  17. 1/2 show-index: fix uninitialized hash functionAbhijeet Sonar, Nov 9, 2024
  18. 2/2 t5300: add test for 'show-index --object-format'Abhijeet Sonar, Nov 9, 2024
  19. Junio C HamanoNov 11, 2024
  20. Patrick SteinhardtDec 16, 2024
  21. Junio C HamanoDec 16, 2024
  22. Abhijeet SonarOct 29, 2024
  23. Abhijeet SonarOct 29, 2024
  24. Abhijeet SonarOct 26, 2024
  25. brian m. carlsonJul 15, 2024
  26. Abhijeet SonarJul 15, 2024
  27. Eric SunshineJul 12, 2024

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.