Class: Amp::RevlogSupport::IndexEntry

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/amp/revlogs/index.rb

Overview

This class represents one revision entry in the index.

Format on disk (in BitStruct notation):

default_options :endian => :network

signed :offset_flags, 64
signed :compressed_len, 32
signed :uncompressed_len, 32
signed :base_rev, 32
signed :link_rev, 32
signed :parent_one_rev, 32
signed :parent_two_rev, 32
char :node_id, 160
pad  :padding, 96
offset_flags
  • this is a double-word (8 bytes) - that combines the offset into the data file

and any flags about the entry

compressed_len
  • this is the length of the data when compressed

uncompresed_len
  • length of the data uncompresed

base_rev
  • the revision of the filelog

link_rev
  • the revision of the whole repo where this was attached

parent_one_rev
  • the parent revision the revision. Even if it’s not a merge,

it will have at least this parent entry

parent_two_rev
  • if the revision is a merge, then it will have a second parent.

Constant Summary collapse

INDEX_FORMAT_NG =
"Q NNNNNN a20 x12"
BLOCK_SIZE =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ IndexEntry

Returns a new instance of IndexEntry.



36
37
38
39
40
41
42
# File 'lib/amp/revlogs/index.rb', line 36

def initialize(*args)
  if args.size == 1 && args[0].respond_to?(:read)
    super(*(args[0].read(BLOCK_SIZE).unpack(INDEX_FORMAT_NG)))
  else
    super(*args)
  end
end

Instance Attribute Details

#base_revObject

Returns the value of attribute base_rev

Returns:

  • (Object)

    the current value of base_rev



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def base_rev
  @base_rev
end

#compressed_lenObject

Returns the value of attribute compressed_len

Returns:

  • (Object)

    the current value of compressed_len



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def compressed_len
  @compressed_len
end

Returns the value of attribute link_rev

Returns:

  • (Object)

    the current value of link_rev



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def link_rev
  @link_rev
end

#node_idObject

Returns the value of attribute node_id

Returns:

  • (Object)

    the current value of node_id



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def node_id
  @node_id
end

#offset_flagsObject

Returns the value of attribute offset_flags

Returns:

  • (Object)

    the current value of offset_flags



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def offset_flags
  @offset_flags
end

#parent_one_revObject

Returns the value of attribute parent_one_rev

Returns:

  • (Object)

    the current value of parent_one_rev



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def parent_one_rev
  @parent_one_rev
end

#parent_two_revObject

Returns the value of attribute parent_two_rev

Returns:

  • (Object)

    the current value of parent_two_rev



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def parent_two_rev
  @parent_two_rev
end

#uncompressed_lenObject

Returns the value of attribute uncompressed_len

Returns:

  • (Object)

    the current value of uncompressed_len



31
32
33
# File 'lib/amp/revlogs/index.rb', line 31

def uncompressed_len
  @uncompressed_len
end

Instance Method Details

#<=>(other_entry) ⇒ Object

Compares this entry to another



67
68
69
# File 'lib/amp/revlogs/index.rb', line 67

def <=> other_entry
  this.base_rev <=> other_entry.base_rev
end

#fix_signsObject

Fixes the values to force them to be signed (possible to be negative)



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/amp/revlogs/index.rb', line 52

def fix_signs
  require 'amp/dependencies/amp_support/ruby_amp_support'

  self.offset_flags     = self.offset_flags.byte_swap_64
  self.compressed_len   = self.compressed_len.to_signed_32
  self.uncompressed_len = self.uncompressed_len.to_signed_32
  self.base_rev         = self.base_rev.to_signed_32
  self.link_rev         = self.link_rev.to_signed_32
  self.parent_one_rev   = self.parent_one_rev.to_signed_32
  self.parent_two_rev   = self.parent_two_rev.to_signed_32
  
  self
end

#hashObject

Gives a hash value so we can stick these entries into a hash



72
73
74
# File 'lib/amp/revlogs/index.rb', line 72

def hash
  node_id.hash
end

#to_sObject



44
45
46
47
48
49
# File 'lib/amp/revlogs/index.rb', line 44

def to_s
  fix_signs
  ret = self.to_a.pack(INDEX_FORMAT_NG)
  fix_signs
  ret
end