Class: Amp::Core::Repositories::Git::PackFileIndexV1
- Inherits:
-
PackFileIndex
- Object
- PackFileIndex
- Amp::Core::Repositories::Git::PackFileIndexV1
- Defined in:
- lib/amp-git/repo_format/packfile_index.rb
Overview
This class is for the older version of index files. They are structured as simply a fanout table and a list of [offset] entries. There’s a checksum at the bottom for verification.
Initialization only reads in the fanout table, and the file is left open.
Constant Summary collapse
- ENTRY_TABLE_START =
256 * 4
- ENTRY_TABLE_ENTRY_SIZE =
20 + 4
- ENTRY_TABLE_FORMAT =
"Na20"
Constants inherited from PackFileIndex
Amp::Core::Repositories::Git::PackFileIndex::FANOUT_TABLE_SIZE
Instance Attribute Summary
Attributes inherited from PackFileIndex
Instance Method Summary collapse
-
#offset_for_hash(hsh) ⇒ Fixnum?
Looks up the offset in a packfile of a given hash.
Methods inherited from PackFileIndex
#initialize, parse, #search_range_for_hash
Constructor Details
This class inherits a constructor from Amp::Core::Repositories::Git::PackFileIndex
Instance Method Details
#offset_for_hash(hsh) ⇒ Fixnum?
Looks up the offset in a packfile of a given hash. nil is returned if the sha1 isn’t found.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/amp-git/repo_format/packfile_index.rb', line 111 def offset_for_hash(hsh) range = search_range_for_hash hsh @fp.seek(FANOUT_TABLE_START + range.begin * ENTRY_TABLE_ENTRY_SIZE, IO::SEEK_SET) # linear search for now. # TODO: binary search! range.each do |_| offset, sha1 = @fp.read(ENTRY_TABLE_ENTRY_SIZE).unpack(ENTRY_TABLE_FORMAT) return offset if sha1 == hsh end raise PackFileIndexLookupError.new("Couldn't find the hash #{hsh.inspect} in the packfile index.") end |