Skip to content
This repository has been archived by the owner on Nov 25, 2018. It is now read-only.

Commit

Permalink
Replace stringy crap with real bitwise arithmetic
Browse files Browse the repository at this point in the history
Besides it being retarded to use strings for this stuff, it was broken on JRuby
  • Loading branch information
tarcieri committed Aug 10, 2013
1 parent ca5e6c6 commit 7a743e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/cryptosphere/git/pack_object.rb
Expand Up @@ -16,22 +16,23 @@ class PackObject
# @param [String] buffer to be processed
# @return [PackObject, nil] PackObject or nil if more data is needed
def self.parse_header(buffer)
byte = buffer[0].unpack("B8").first
byte = buffer[0].ord
consumed = 1

more = byte[0,1]
type = Integer(byte[1,3], 2)
length = Integer(byte[4,4], 2)
more = byte >> 7 & 0x1
type = byte >> 4 & 0x7
length = byte & 0xf

while more == "1"
while more == 1
raise FormatError, "object header too long" if consumed >= HEADER_SANITY_LIMIT

# Need more data
return nil if consumed >= buffer.length

byte = buffer[consumed].unpack("B8").first
more = byte[0,1]
length += Integer(byte[1,7], 2)
byte = buffer[consumed].ord
more = byte >> 7 & 0x1
length += byte & 0x7f

consumed += 1
end

Expand Down
3 changes: 2 additions & 1 deletion spec/cryptosphere/git/pack_reader_spec.rb
Expand Up @@ -3,7 +3,8 @@
require 'stringio'

describe Cryptosphere::Git::PackReader do
subject { described_class.new(StringIO.new(fixture('packfile'))) }
let(:stringio) { StringIO.new(fixture('packfile')).set_encoding("ASCII-8BIT") }
subject { described_class.new(stringio) }

it "returns the next object in the pack" do
obj = subject.next_object
Expand Down

0 comments on commit 7a743e1

Please sign in to comment.