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

Re: How is the ^{sha256} peel syntax supposed to work?

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 29, 2018, 18:41 UTC
Message-ID
<87zhx5c8wo.fsf@evledraar.gmail.com>
In-Reply-To
<20180829175950.GB7547@aiede.svl.corp.google.com>
On Wed, Aug 29 2018, Jonathan Nieder wrote:
Show 15 quoted lines
> Stefan Beller wrote:
>
>>                  And with that model, <hexdigits>^{sha256}^{tree}
>> could mean to obtain the sha256 value of <hexvalue> and then derive
>> the tree from that object,
>
> What does "the sha256 value of <hexvalue>" mean?
>
> For example, in a repository with two objects:
>
>  1. an object with sha1-name abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
>     and sha256-name ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01
>
>  2. an object with sha1-name ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01
>     and sha256-name abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd...

I'm not saying this makes sense, or that it doesn't honestly my head's still spinning a bit from this mail exchange (these are the patches I need to re-submit): https://public-inbox.org/git/878t8txfyf.fsf@evledraar.gmail.com/#t

But paraphrasing my understanding of what Junio & Jeff are saying in that thread, basically what the peel syntax means is different in the two completely different scenarios it's used:

 1. When it's being used as <object>^{<thing>}[...^{<thing2>}] AND
    <object> is an unambiguous SHA1 it's fairly straightforward, i.e. if
    <object> is a commit and you say ^{tree} it lists the tree SHA-1,
    but if <object> is e.g. a tree and you say ^{blob} it produces an
    error, since there's no one blob.
 2. When it's used in the same way, but <object> is an ambiguous SHA1 we
    fall back on a completely different sort of behavior.
    Now it's, or well, supposed to be, I haven't worked through the
    feedback and rewritten the patches, this weird sort of filter syntax
    where <ambiguous_object>^{<type>} will return SHA1s of starting with
    a prefix of <ambiguous_object> IF the types of such SHA1s could be
    contained within that type of object.
    So e.g. abcabc^{tree} is supposed to list all tree and blob objects
    starting with a prefix of abcabc, even though some of the blobs
    could not be reachable from those trees.
    It doesn't make sense to me, but there it is.
Now, because of this SHA1 v.s. SHA256 thing we have a third case.
Show 6 quoted lines
> what objects would you expect the following to refer to?
>
>   abcdabcd^{sha1}
>   abcdabcd^{sha256}
>   ef01ef01^{sha1}
>   ef01ef01^{sha256}

I still can't really make any sense of why anyone would even want #2 as described above, but for this third case I think we should do this:

    abcdabcd^{sha1}   = abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
    abcdabcd^{sha256} = ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01
    ef01ef01^{sha1}   = ef01ef01ef01ef01ef01ef01ef01ef01ef01ef01
    ef01ef01^{sha256} = abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd...

I.e. a really useful thing about this peel syntax is that it's forgiving, and will try to optimistically look up what you want.

So e.g. <hash>^{commit} is not an error if <hash> is already a commit, it could be (why are you trying to peel something already peeled!), because it's useful to be able to feed it a set of things, some of which are commits, some of which are tags, and have it always resolve things without error handling on the caller side.

Similarly, I think it would be very useful if we just make this work:
    git rev-parse $some_hash^{sha256}^{commit}

And not care whether $some_hash is SHA-1 or SHA-256, if it's the former we'd consult the SHA-1 <-> SHA-256 lookup table and go from there, and always return a useful value.

Previous: Stefan BellerNext: Jonathan Nieder
Message 21 of 33 in “Questions about the hash function transition”
  1. Ævar Arnfjörð BjarmasonAug 23, 2018
  2. Junio C HamanoAug 23, 2018
  3. Ævar Arnfjörð BjarmasonAug 23, 2018
  4. Junio C HamanoAug 23, 2018
  5. brian m. carlsonAug 24, 2018
  6. Jonathan NiederAug 24, 2018
  7. brian m. carlsonAug 24, 2018
  8. Jonathan NiederAug 24, 2018
  9. Jonathan NiederAug 24, 2018
  10. Johannes SchindelinAug 28, 2018
  11. Derrick StoleeAug 28, 2018
  12. Jonathan NiederAug 28, 2018
  13. Jonathan NiederAug 28, 2018
  14. Johannes SchindelinAug 29, 2018
  15. Derrick StoleeAug 29, 2018
  16. Derrick StoleeAug 29, 2018
  17. How is the ^{sha256} peel syntax supposed to work?Ævar Arnfjörð Bjarmason, Aug 29, 2018
  18. Stefan BellerAug 29, 2018
  19. Jonathan NiederAug 29, 2018
  20. Stefan BellerAug 29, 2018
  21. Ævar Arnfjörð BjarmasonAug 29, 2018
  22. Jonathan NiederAug 29, 2018
  23. Ævar Arnfjörð BjarmasonAug 29, 2018
  24. Jonathan NiederAug 29, 2018
  25. Jeff KingAug 29, 2018
  26. Junio C HamanoAug 29, 2018
  27. Jonathan NiederAug 29, 2018
  28. Jonathan NiederAug 29, 2018
  29. Jonathan NiederAug 24, 2018
  30. Ævar Arnfjörð BjarmasonAug 28, 2018
  31. Edward ThomsonAug 28, 2018
  32. Ævar Arnfjörð BjarmasonAug 28, 2018
  33. Junio C HamanoAug 28, 2018

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.