Class: Amp::RevlogSupport::IndexVersion0
- Defined in:
- lib/amp/revlogs/index.rb
Overview
IndexVersion0
This handles old versions of the index file format. These are apparently so old they were version 0.
Constant Summary collapse
- INDEX_FORMAT_V0 =
Binary data format for each revision entry
"N4 a20 a20 a20"
- BLOCK_SIZE =
The size of each revision entry
(4 * 4) + (3 * 20)
- SHA1_OFFSET =
The offset into the entry where the SHA1 is stored for validation
56
Constants inherited from Index
Amp::RevlogSupport::Index::VERSION_FORMAT
Constants included from Support
Support::REVLOG_DEFAULT_FLAGS, Support::REVLOG_DEFAULT_FORMAT, Support::REVLOG_DEFAULT_VERSION, Support::REVLOG_NG_INLINE_DATA, Support::REVLOG_VERSION_0, Support::REVLOG_VERSION_NG
Instance Attribute Summary
Attributes inherited from Index
#cache, #chunk_cache, #index, #indexfile, #node_map
Instance Method Summary collapse
-
#entry_size ⇒ Object
Return the size of 1 entry.
-
#initialize(opener, inputfile) ⇒ IndexVersion0
constructor
Initializes the index by reading from the provided filename.
-
#inline? ⇒ Boolean
Does the index store the data with the revision index entries?.
-
#pack_entry(entry, rev) ⇒ String
This takes an entry and packs it into binary data for writing to the file.
-
#version ⇒ Object
Return what version this index is.
-
#write_entry(index_file, entry, journal, data) ⇒ Object
This method writes the index to file.
Methods inherited from Index
#<<, #[], #each, #has_node?, parse, #size
Methods included from Enumerable
Methods included from Support
#compress, #decompress, #get_offset, #get_version, #history_hash, #offset_version
Constructor Details
#initialize(opener, inputfile) ⇒ IndexVersion0
Initializes the index by reading from the provided filename. Users probably don’t need this because Amp::RevlogSupport::Index#Amp::RevlogSupport::Index.parse will do this for you.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/amp/revlogs/index.rb', line 220 def initialize(opener, inputfile) @opener = opener @indexfile = inputfile @node_map = {Node::NULL_ID => Node::NULL_REV} @index = [] n = offset = 0 if File.exists?(opener.join(inputfile)) opener.open(inputfile) do |f| while !f.eof? current = f.read(BLOCK_SIZE) entry = current.unpack(INDEX_FORMAT_V0) new_entry = IndexEntry.new(offset_version(entry[0],0), entry[1], -1, entry[2], entry[3], (@node_map[entry[4]] || nullrev), (@node_map[entry[5]] || nullrev), entry[6]) @index << new_entry.fix_signs @node_map[entry[6]] = n n += 1 end end end @cache = nil self end |
Instance Method Details
#entry_size ⇒ Object
Return the size of 1 entry
210 |
# File 'lib/amp/revlogs/index.rb', line 210 def entry_size; BLOCK_SIZE; end |
#inline? ⇒ Boolean
Does the index store the data with the revision index entries?
214 |
# File 'lib/amp/revlogs/index.rb', line 214 def inline?; false; end |
#pack_entry(entry, rev) ⇒ String
This takes an entry and packs it into binary data for writing to the file.
278 279 280 281 282 283 284 285 286 |
# File 'lib/amp/revlogs/index.rb', line 278 def pack_entry(entry, rev) entry = IndexEntry.new(*entry) if entry.kind_of? Array entry.fix_signs e2 = [RevlogSupport::Support.offset_type(entry.offset_flags), entry.compressed_len, entry.base_rev, entry.link_rev, @index[entry.parent_one_rev].node_id, @index[entry.parent_two_rev].node_id, entry.node_id] e2.pack(INDEX_FORMAT_V0) end |
#version ⇒ Object
Return what version this index is
212 |
# File 'lib/amp/revlogs/index.rb', line 212 def version; REVLOG_VERSION_0; end |
#write_entry(index_file, entry, journal, data) ⇒ Object
This method writes the index to file. Pretty 1337h4><.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/amp/revlogs/index.rb', line 249 def write_entry(index_file, entry, journal, data) curr = self.size - 1 node_map[entry.last] = curr link = entry[4] data_file = index_file[0..-3] + ".d" entry = pack_entry entry, link data_file_handle = open(data_file, "a") index_file_handle = open(index_file, "a+") journal << [data_file, offset] journal << [index_file, curr * entry.size] data_file_handle.write data[:compression] if data[:compression].any? data_file_handle.write data[:text] data_file_handle.flush index_file_handle.write entry end |