class GitObjectBrowser::Models::Index

Parse .git/index file

Attributes

entries[R]
entry_count[R]
extensions[R]
sha1[R]
version[R]

Public Class Methods

new(input) click to toggle source
Calls superclass method GitObjectBrowser::Models::Bindata::new
# File lib/git-object-browser/models/index.rb, line 10
def initialize(input)
  super(input)
end
path?(relpath) click to toggle source
# File lib/git-object-browser/models/index.rb, line 73
def self.path?(relpath)
  relpath == "index"
end

Public Instance Methods

parse() click to toggle source
# File lib/git-object-browser/models/index.rb, line 14
def parse
  dirc = raw(4)
  if dirc != "DIRC"
    throw Exception.new("Illegal format.")
  end

  @version     = int
  @entry_count = int
  @entries     = parse_entries
  @extensions  = parse_extensions
  @sha1        = hex(20)

  self
end
parse_entries() click to toggle source
# File lib/git-object-browser/models/index.rb, line 29
def parse_entries
  entries = []
  last_path = nil
  @entry_count.times do |i|
    entries << IndexEntry.new(@in, @version, last_path)
    last_path = entries.last.path
  end
  return entries
end
parse_extensions() click to toggle source
# File lib/git-object-browser/models/index.rb, line 39
def parse_extensions
  extensions = []
  while signature = peek(4)
    if signature == "TREE"
      extensions << IndexTreeExtension.new(@in).parse
    elsif  signature == "REUC"
      extensions << IndexReucExtension.new(@in).parse
    else
      break
    end
  end
  return extensions
end
to_hash() click to toggle source
# File lib/git-object-browser/models/index.rb, line 53
def to_hash
  entries = []
  @entries.each do |entry|
    entries << entry.to_hash
  end

  extensions = []
  @extensions.each do |extension|
    extensions << extension.to_hash
  end

  return {
    :version       => @version,
    :entry_count   => @entry_count,
    :entries       => entries,
    :extensions    => extensions,
    :sha1          => @sha1,
  }
end