Skip to content

Commit

Permalink
Make sure the unpacking of objects works on 1.9 correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jun 4, 2009
1 parent 95615f2 commit e639a17
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/git_store/pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ def unpack_object(packfile, offset, options = {})
obj_offset = offset
packfile.seek(offset)

c = packfile.read(1)[0]
c = packfile.read(1)[0].ord
size = c & 0xf
type = (c >> 4) & 7
shift = 4
offset += 1
while c & 0x80 != 0
c = packfile.read(1)[0]
c = packfile.read(1)[0].ord
size |= ((c & 0x7f) << shift)
shift += 7
offset += 1
Expand All @@ -326,10 +326,10 @@ def unpack_deltified(packfile, type, offset, obj_offset, size, options = {})

if type == OBJ_OFS_DELTA
i = 0
c = data[i]
c = data[i].ord
base_offset = c & 0x7f
while c & 0x80 != 0
c = data[i += 1]
c = data[i += 1].ord
base_offset += 1
base_offset <<= 7
base_offset |= c & 0x7f
Expand Down Expand Up @@ -380,21 +380,21 @@ def patch_delta(base, delta)
dest_size, pos = patch_delta_header_size(delta, pos)
dest = ""
while pos < delta.size
c = delta[pos]
c = delta[pos].ord
pos += 1
if c & 0x80 != 0
pos -= 1
cp_off = cp_size = 0
cp_off = delta[pos += 1] if c & 0x01 != 0
cp_off |= delta[pos += 1] << 8 if c & 0x02 != 0
cp_off |= delta[pos += 1] << 16 if c & 0x04 != 0
cp_off |= delta[pos += 1] << 24 if c & 0x08 != 0
cp_size = delta[pos += 1] if c & 0x10 != 0
cp_size |= delta[pos += 1] << 8 if c & 0x20 != 0
cp_size |= delta[pos += 1] << 16 if c & 0x40 != 0
cp_off = delta[pos += 1].ord if c & 0x01 != 0
cp_off |= delta[pos += 1].ord << 8 if c & 0x02 != 0
cp_off |= delta[pos += 1].ord << 16 if c & 0x04 != 0
cp_off |= delta[pos += 1].ord << 24 if c & 0x08 != 0
cp_size = delta[pos += 1].ord if c & 0x10 != 0
cp_size |= delta[pos += 1].ord << 8 if c & 0x20 != 0
cp_size |= delta[pos += 1].ord << 16 if c & 0x40 != 0
cp_size = 0x10000 if cp_size == 0
pos += 1
dest += base[cp_off,cp_size]
dest += base[cp_off, cp_size]
elsif c != 0
dest += delta[pos,c]
pos += c
Expand All @@ -414,6 +414,7 @@ def patch_delta_header_size(delta, pos)
if c == nil
raise PackFormatError, 'invalid delta header'
end
c = c.ord
pos += 1
size |= (c & 0x7f) << shift
shift += 7
Expand Down

0 comments on commit e639a17

Please sign in to comment.