Thread (3 messages) flat view 3 messages, 2 authors, 2020-01-10

Re: Question about the pack OBJ_OFS_DELTA format

From: Jeff King <hidden>
Date: 2020-01-10 09:57:10

On Fri, Jan 10, 2020 at 09:26:27AM +0100, Erik Fastermann wrote:
I get: ee 01 8c 63

The first two bytes, the type and the size are correctly computed.

So the next varint should be the offset.

8c: 10001100 --- 63: 01100011

-> 1100011_0001100

-> 12684 ???

The result is the same when calculating it manually and with my program.
The pack-format.txt file says:

       offset encoding:
            n bytes with MSB set in all but the last one.
            The offset is then the number constructed by
            concatenating the lower 7 bit of each byte, and
            for n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1))
            to the result.

but I think is missing two bits of information:

  - the bytes are in most-significant to least-significant order, which
    IIRC is the opposite of the size varint

  - each 7-bit byte sneaks in some extra data by implicitly adding "1"
    to all but the last byte

So the low seven bits of "8c" is "12". Add one and multiply by 2^7 gets
you 1664. The low seven of "63" is 99. No addition or multiply because
it's the last byte.

The result is 1763, which is what you expected.

It does seem like the documentation could be a lot better. I had to dig
into the source (packfile.c:get_delta_base is pretty clear, but if
you're trying to do a non-GPL clean-room implementation, then obviously
don't look at it).

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help