Class: Amp::RevlogSupport::IndexInlineNG

Inherits:
IndexVersionNG show all
Defined in:
lib/amp/revlogs/index.rb

Overview

IndexInlineNG

This is a variant of the current version of the index format, in which the data is stored in the actual index file itself, right after the little revision entry block (see IndexEntry). This means less IO, which is good.

Constant Summary collapse

VERSION_FORMAT =
"N"
INDEX_FORMAT_NG =

We’re inline!

"Q NNNNNN a20 x12"
SHA1_OFFSET =

The distance into the entry to go to find the SHA1 hash

32
BLOCK_SIZE =

The size of a single block in the index

8 + (6 * 4) + 20 + 12

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

Methods inherited from IndexVersionNG

#entry_size, #initialize

Methods inherited from Index

#<<, #[], #each, #has_node?, parse, #size

Methods included from Enumerable

#inject, #select_map

Methods included from Support

#compress, #decompress, #get_offset, #get_version, #history_hash, #offset_version

Constructor Details

This class inherits a constructor from Amp::RevlogSupport::IndexVersionNG

Instance Method Details

#inline?Boolean

Returns:



428
# File 'lib/amp/revlogs/index.rb', line 428

def inline?; true; end

#pack_entry(entry, rev) ⇒ Object



430
431
432
433
434
435
436
437
# File 'lib/amp/revlogs/index.rb', line 430

def pack_entry(entry, rev)
  entry = IndexEntry.new(*entry) if entry.kind_of? Array
  p = entry.to_s
  if rev == 0 || rev == 1
    p = [version].pack(VERSION_FORMAT) + p[4..-1] # initial entry
  end
  p
end

#parse_fileObject

TODO:

“not sure what the 0 is for yet or i’d make this a hash” (see code)

This method overrides the parent class’ method that reads entries sequentially from the index file. Each entry is followed by the data for that revision so we have to skip over that data for our purposes.



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/amp/revlogs/index.rb', line 445

def parse_file
  n = offset = 0
  begin
    @opener.open(@indexfile,"r") do |f|
      return false if f.eof?
      while !f.eof?
        # read 1 entry
        entry = IndexEntry.new(f).fix_signs
        # store it in the map
        @node_map[entry.node_id] = n
        # add it to the index
        @index << entry
        n += 1
        break if entry.compressed_len < 0
        
        # skip past the data, too!
        f.seek(entry.compressed_len, IO::SEEK_CUR)
      end
    end
    return true
  rescue Errno::ENOENT
    return false
  end
end

#versionObject



429
# File 'lib/amp/revlogs/index.rb', line 429

def version; REVLOG_VERSION_NG | REVLOG_NG_INLINE_DATA; end

#write_entry(index_file, entry, journal, data, index_file_handle = nil) ⇒ Object

This method writes the index to file. Pretty 1337h4><.

Parameters:

  • index_file (String)

    the path to the index file.



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/amp/revlogs/index.rb', line 474

def write_entry(index_file, entry, journal, data, index_file_handle = nil)
  curr = self.size - 1
  link = (entry.is_a? Array) ? entry[4] : entry.link_rev
  
  entry = pack_entry entry, curr
  
  index_file_handle ||= (opened = true && @opener.open(index_file, "a+"))
  
  index_file_handle.write entry
  index_file_handle.write data[:compression] if data[:compression].any?
  index_file_handle.write data[:text]
  
  index_file_handle.close if opened
  
end