--- /dev/null
+begin
+ require 'mmap'
+rescue LoadError
+
+module Git module Internal
+ class Mmap
+ def initialize(file)
+ @file = file
+ @offset = nil
+ end
+
+ def [](*idx)
+ idx = idx[0] if idx.length == 1
+ case idx
+ when Range
+ offset = idx.first
+ len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
+ when Fixnum
+ offset = idx
+ len = nil
+ when Array
+ offset, len = idx
+ else
+ raise RuntimeError, "invalid index param: #{idx.class}"
+ end
+ if @offset != offset
+ @file.seek(offset)
+ end
+ @offset = offset + len ? len : 1
+ if not len
+ @file.read(1)[0]
+ else
+ @file.read(len)
+ end
+ end
+ end
+end end
+
+end # rescue LoadError
+
require 'zlib'
-
-class MmapHelp
- def initialize(file)
- @file = file
- @offset = nil
- end
-
- def [](*idx)
- idx = idx[0] if idx.length == 1
- case idx
- when Range
- offset = idx.first
- len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
- when Fixnum
- offset = idx
- len = nil
- when Array
- offset, len = idx
- else
- raise RuntimeError, "invalid index param: #{idx.class}"
- end
- if @offset != offset
- @file.seek(offset)
- end
- @offset = offset + len ? len : 1
- if not len
- @file.read(1)[0]
- else
- @file.read(len)
- end
- end
-end
+require 'git/internal/mmap'
module Git module Internal
class PackFormatError < StandardError
@@ -53,7 +22,7 @@ module Git module Internal
@name = file
@packfile = File.open(file)
@idxfile = File.open(file[0...-4]+'idx')
- @idx = MmapHelp.new(@idxfile)
+ @idx = Mmap.new(@idxfile)
@offsets = [0]
FanOutCount.times do |i|
@@ -249,3 +218,18 @@ module Git module Internal
private :patch_delta_header_size
end
end end
+
+if $0 == __FILE__
+ p = Git::Internal::PackStorage.new(ARGV[0])
+
+ if ARGV.length == 1
+ p.each_sha1 do |sha1|
+ puts sha1.unpack('H*')
+ end
+ end
+
+ ARGV[1..-1].each do |sha1|
+ sha1 = [sha1].pack('H*')
+ puts p[sha1]
+ end
+end