lib/grit/git-ruby/internal/loose.rb in mojombo-grit-0.9.4 vs lib/grit/git-ruby/internal/loose.rb in mojombo-grit-1.1.1
- old
+ new
@@ -27,11 +27,11 @@
def [](sha1)
sha1 = sha1.unpack("H*")[0]
begin
return nil unless sha1[0...2] && sha1[2..39]
path = @directory + '/' + sha1[0...2] + '/' + sha1[2..39]
- get_raw_object(File.read(path))
+ get_raw_object(File.open(path, 'rb').read)
rescue Errno::ENOENT
nil
end
end
@@ -74,11 +74,11 @@
if !File.exists?(path)
content = Zlib::Deflate.deflate(store)
FileUtils.mkdir_p(@directory+'/'+sha1[0...2])
- File.open(path, 'w') do |f|
+ File.open(path, 'wb') do |f|
f.write content
end
end
return sha1
end
@@ -100,21 +100,21 @@
end
# private
def unpack_object_header_gently(buf)
used = 0
- c = buf[used]
+ c = buf.getord(used)
used += 1
type = (c >> 4) & 7;
size = c & 15;
shift = 4;
while c & 0x80 != 0
if buf.length <= used
raise LooseObjectError, "object file too short"
end
- c = buf[used]
+ c = buf.getord(used)
used += 1
size += (c & 0x7f) << shift
shift += 7
end
@@ -125,11 +125,11 @@
return [type, size, used]
end
private :unpack_object_header_gently
def legacy_loose_object?(buf)
- word = (buf[0] << 8) + buf[1]
- buf[0] == 0x78 && word % 31 == 0
+ word = (buf.getord(0) << 8) + buf.getord(1)
+ buf.getord(0) == 0x78 && word % 31 == 0
end
private :legacy_loose_object?
end
end
end