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

Re: [QUESTION] how to diff one blob with nothing

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2023, 19:00 UTC
Message-ID
<xmqqmsz6ljk4.fsf@gitster.g>
In-Reply-To
<ZM1EvGVGv2ZYrpuT@nand.local>
Taylor Blau <me@ttaylorr.com> writes:
Show 22 quoted lines
> On Fri, Aug 04, 2023 at 10:28:53AM +0200, Christian Couder wrote:
>> On Fri, Aug 4, 2023 at 6:42 AM ZheNing Hu <adlternative@gmail.com> wrote:
>>
>> > Actually, there is no need to support a default empty blob.
>> > For example, with the command "git diff --no-index <file> /dev/null",
>> > it can compare a file with /dev/null, but it can only compare <file>
>> > and not <oid>.
>> > Therefore, using commands like "git diff <oid> /dev/null",
>> > "git diff --no-index <oid> /dev/null", or even "git diff <oid> --stdin"
>> > could potentially solve this issue.
>>
>> Maybe it would be clearer to have a new option, called for example
>> "--blob-vs-file", for that then. It could support both:
>>
>> $ git diff --blob-vs-file <blob> <file>
>>
>> and:
>>
>> $ git diff --blob-vs-file <file> <blob>
>
> Hmm. This feels like a case of trying to teach 'git diff' to do too
> much.

Worse yet, I do not quite get the original use case in the first place. What is the series of diff output that result in comparing a random pair of blob object names going to be used for?

The reply to <ZMKtcaN7xYaTtkcI@nand.local> says that the original use case was to express the evolution of a single path since its creation until its removal, but the thing is, a diff with an empty blob and a creation or a deletion event are expressed differently in the patch output, exactly because the patch has to be able to express "before this change, a file with zero byte content was there" and "before this change, there was nothing at this path" (vice versa for contents-removal vs deletion).

For that reason, I have a hard time to find any merit in the earlier complaint that said "can be achieved by manually adding them, but it is not very compatible with the original logic", whatever the "original logic" refers to. If creation needs to be recorded as creation and not as a change from an empty and existing blob, there has to be something that needs to be manually done to turn the latter (which is the only thing "diff" between two blobs or even a blob and a file can give) into the former *anyway*. Whatever the thing that is looping over the history/evoluation of a single path needs to have a three-arm switch for each iteration to deal with creation, modification, and removal, and iterating over the contents of the files and prefixing "+" or "-" on each and every line would be the _easiest_ part of such a necessary tweak to turn "diff between an empty contents and something else" into "creation or deletion of a file."

Previous: Taylor BlauNext: ZheNing Hu
Message 12 of 15 in “[QUESTION] how to diff one blob with nothing”
  1. ZheNing HuJul 19, 2023
  2. Junio C HamanoJul 19, 2023
  3. ZheNing HuJul 26, 2023
  4. Junio C HamanoJul 26, 2023
  5. Taylor BlauJul 27, 2023
  6. ZheNing HuJul 28, 2023
  7. ZheNing HuAug 3, 2023
  8. Taylor BlauAug 3, 2023
  9. ZheNing HuAug 4, 2023
  10. Christian CouderAug 4, 2023
  11. Taylor BlauAug 4, 2023
  12. Junio C HamanoAug 4, 2023
  13. ZheNing HuAug 5, 2023
  14. Konstantin KhomoutovJul 27, 2023
  15. ZheNing HuJul 28, 2023

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.