lib/grit/git-ruby/internal/mmap.rb in schacon-grit-0.9.1 vs lib/grit/git-ruby/internal/mmap.rb in schacon-grit-0.9.3
- old
+ new
@@ -7,21 +7,22 @@
# Scott Chacon <schacon@gmail.com>
#
# provides native ruby access to git objects and pack files
#
-begin
- require 'mmap'
-rescue LoadError
-
module Grit
module GitRuby
module Internal
class Mmap
- def initialize(file)
+ def initialize(file, version = 1)
@file = file
@offset = nil
+ if version == 2
+ @global_offset = 8
+ else
+ @global_offset = 0
+ end
end
def unmap
@file = nil
end
@@ -39,11 +40,11 @@
offset, len = idx
else
raise RuntimeError, "invalid index param: #{idx.class}"
end
if @offset != offset
- @file.seek(offset)
+ @file.seek(offset + @global_offset)
end
@offset = offset + len ? len : 1
if not len
@file.read(1)[0]
else
@@ -52,8 +53,6 @@
end
end
end
end
end
-
-end # rescue LoadError