All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Gareth Hayes" <gareth.hayes@bitcoin.org.hk>
Cc: git@vger.kernel.org
Subject: Re: Problem: `fatal: too-short tree object` when executing hash-object on tree
Date: Thu, 31 Aug 2023 10:25:52 -0700	[thread overview]
Message-ID: <xmqqjztbw2cf.fsf@gitster.g> (raw)
In-Reply-To: <0de414f8-f409-467f-a504-06a78f088981@app.fastmail.com> (Gareth Hayes's message of "Thu, 31 Aug 2023 18:58:30 +0800")

"Gareth Hayes" <gareth.hayes@bitcoin.org.hk> writes:

> Problem: I'm trying to reproduce the identifier of a tree object using `git cat-file -p <tree object identifier> | git hash-object -t tree --stdin`
>
> This results in an error:
> `fatal: too-short tree object`
>
> To replicate: 
> `git cat-file -p HEAD`
> `git cat-file -p <tree object identifier from output of above> | git hash-object -t tree --stdin`
>
> This works for other object types but not trees. What am I doing wrong?

It would work *ONLY* for blob, and not commit or tag object types,
no?

The "-p" option is to present the object in a human-friendly format,
as opposed to giving the raw stream of bytes that is suitable for
machine consumption and required by hash-object.  It so happens that
for "blob", the raw stream of bytes is just as human-friendly as the
tool can make, without having a deep knowledge of the content type
(e.g. it may be possible to make "cat-file -p <blob>" to somehow
apply an appropriate textconv filter if the path to <blob> is known
as a future enhancement, but such a code does not exist yet, and
when it happens, even "cat-file -p <blob> | hash-object --stdin"
would not round-trip).

So, that is what you are doing wrong, I think.

      parent reply	other threads:[~2023-08-31 17:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 10:58 Problem: `fatal: too-short tree object` when executing hash-object on tree Gareth Hayes
2023-08-31 17:10 ` Johannes Sixt
2023-08-31 17:25 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqjztbw2cf.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=gareth.hayes@bitcoin.org.hk \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.