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

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

From
ZheNing Hu <adlternative@gmail.com>
Date
Jul 26, 2023, 18:00 UTC
Message-ID
<CAOLTT8R84Zrtpd=j6o2V=Y_uD54XAS5EA7NWHsdfL+XCkD5cqA@mail.gmail.com>
In-Reply-To
<xmqqo7k7c1yw.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2023年7月20日周四 00:15写道:
Show 31 quoted lines
>
> ZheNing Hu <adlternative@gmail.com> writes:
>
> > I want to diff two blobs right now, and one of them
> > may be empty, so I tried using
> > 0000000000000000000000000000000000000000 or
> > e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (empty blobID)
> > to test its effect, and the result I found was:
> >
> > git diff 00750edc07d6415dcc07ae0351e9397b0222b7ba
> > 0000000000000000000000000000000000000000
> > fatal: bad object 0000000000000000000000000000000000000000
>
> As the object name for an empty blob is not all-0, this is expected.
>
> > git diff 00750edc07d6415dcc07ae0351e9397b0222b7ba
> > e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
> > fatal: bad object e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
> >
> > Since the "empty object" has not been created, the
> > git diff operation fails.
>
> If you haven't created one, of course it would fail.  It should help
> to do
>
>     $ git hash-object -w --stdin </dev/null
>
> before running
>
>     $ git diff 00750edc e69de29bb
>

This is a viable solution, but it's a bit ugly since a read-only "diff" requires ”write“ an empty blob.

> Long time ago, with 346245a1 (hard-code the empty tree object,
> 2008-02-13) we taught git what an empty-tree looks like, but it
> seems that we never did the same for an empty blob, perhaps?
>
It would be great to have that capability.
> Interesting.  I am not sure if it is a good idea to teach empty_blob
> to find_cached_object() and leaning negative but I haven't thought
> things through on this.
>

I currently don't have time to delve into implementation details, so I went with the approach that requires writing an empty blob, but I'll take a closer look at it later.

>
>

Thanks, ZheNing Hu

Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.