Class: Gitrb::Pack
- Inherits:
-
Object
- Object
- Gitrb::Pack
- Defined in:
- lib/gitrb/pack.rb
Constant Summary collapse
- OBJ_OFS_DELTA =
6- OBJ_REF_DELTA =
7- FanOutCount =
256- SHA1Size =
20- IdxOffsetSize =
4- OffsetSize =
4- CrcSize =
4- OffsetStart =
FanOutCount * IdxOffsetSize
- SHA1Start =
OffsetStart + OffsetSize
- EntrySize =
OffsetSize + SHA1Size
- EntrySizeV2 =
SHA1Size + CrcSize + OffsetSize
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #each_object ⇒ Object
- #get_object(offset) ⇒ Object
-
#initialize(file) ⇒ Pack
constructor
A new instance of Pack.
Constructor Details
#initialize(file) ⇒ Pack
Returns a new instance of Pack.
60 61 62 63 64 |
# File 'lib/gitrb/pack.rb', line 60 def initialize(file) file = file[0...-3] + 'pack' if file =~ /\.idx$/ @name = file init_pack end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
58 59 60 |
# File 'lib/gitrb/pack.rb', line 58 def name @name end |
Instance Method Details
#each_object ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gitrb/pack.rb', line 66 def each_object with_idx do |idx| if @version == 2 data = read_data_v2(idx) data.each do |sha1, crc, offset| sha1 = sha1.unpack("H*").first yield sha1, offset end else pos = OffsetStart @size.times do offset = idx[pos,OffsetSize].unpack('N')[0] sha1 = idx[pos+OffsetSize,SHA1Size] pos += EntrySize sha1 = sha1.unpack("H*").first yield sha1, offset end end end end |
#get_object(offset) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/gitrb/pack.rb', line 87 def get_object(offset) data, type = with_pack do |packfile| unpack_object(packfile, offset) end [data, OBJ_TYPES[type]] end |