From: Jeff King <peff@peff.net>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>
Cc: Florian Steenbuck <steenbuckflorian@gmail.com>, git@vger.kernel.org
Subject: Re: Confusion about the PACK format
Date: Mon, 11 Feb 2019 19:41:30 -0500 [thread overview]
Message-ID: <20190212004130.GI13301@sigill.intra.peff.net> (raw)
In-Reply-To: <a0e1ad5b-8d6b-7fa0-54f3-dc0b4b275533@ramsayjones.plus.com>
On Sun, Feb 10, 2019 at 07:35:38PM +0000, Ramsay Jones wrote:
> > Now, the 'n-byte type and length' is a variable length encoding of
> > the object type and length. The number of bytes used to encode this
> > data is content dependant. If the top bit of a byte is set, then we
> > need to process the next byte, otherwise we are done. So, looking
> > at the first 'object entry' byte (at offset 12) '9d', we take the
> > top nibble, remove the top bit, and shift right 4 bits to get the
> > object type. ie. (0x9d >> 4) & 7 which gives an object type of 1
> > (which is a commit object). The lower nibble of the first byte
> > contains the first (or only) 4 bits of the size, here (0x9d & 15)
> > which is 0xd. Given that the top bit of this byte is set, we now
> > process the next byte. After the first byte, each byte contains 7
> > bits of the size field which is combined with the value from the
> > previous byte by shifting and adding (first by 4 bits, then 11, 18,
> > 25 etc.). So, in this case we have (0x13 << 4) + 0xd = 317.
>
> Sorry, to be clear, I should have said, "mask off the top bit,
> shift and add", so:
>
> ((0x13 & 0x7f) << 4) + 0xd = 317
Yes. Also, see the first 10 or so lines of builtin/index-pack.c's
unpack_raw_entry() for real-world example code.
-Peff
prev parent reply other threads:[~2019-02-12 0:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-10 16:02 Confusion about the PACK format Florian Steenbuck
2019-02-10 19:05 ` Ramsay Jones
2019-02-10 19:35 ` Ramsay Jones
2019-02-12 0:41 ` Jeff King [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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190212004130.GI13301@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=ramsay@ramsayjones.plus.com \
--cc=steenbuckflorian@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).