class GitObjectBrowser::Models::IndexTreeExtension

Attributes

entries[R]
signature[R]
total_length[R]

Public Class Methods

new(input) click to toggle source
Calls superclass method GitObjectBrowser::Models::Bindata::new
# File lib/git-object-browser/models/index_tree_extension.rb, line 9
def initialize(input)
  super(input)
end

Public Instance Methods

parse() click to toggle source
# File lib/git-object-browser/models/index_tree_extension.rb, line 13
def parse
  @signature = raw(4) # TREE
  @total_length = int
  @entries = []

  length = 0
  while (length < @total_length)
    entry = {}
    entry[:path_component] = find_char "\0"
    entry[:entry_count]    = find_char " "
    entry[:subtree_count]  = find_char "\n"

    length += entry[:path_component].bytesize + 1
    length += entry[:entry_count].bytesize + 1
    length += entry[:subtree_count].bytesize + 1

    entry[:entry_count]    = entry[:entry_count].to_i
    entry[:subtree_count]  = entry[:subtree_count].to_i

    if 0 <= entry[:entry_count]
      entry[:sha1] = hex(20)
      length += 20
    end
    @entries << entry
  end

  self
end
to_hash() click to toggle source
# File lib/git-object-browser/models/index_tree_extension.rb, line 42
def to_hash
  return {
    :signature     => @signature,
    :total_length  => @total_length,
    :entries       => @entries
  }
end