class Gollum::Git::Index

Public Class Methods

new(index, repo) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 429
def initialize(index, repo)
  @index = index
  @rugged_repo = repo
  @treemap = {}
end

Public Instance Methods

add(path, data) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 450
def add(path, data)
  blob = @rugged_repo.write(data, :blob)
  @index.add(:path => path, :oid => blob, :mode => 0100644)
  update_treemap(path, data)
  data
end
commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master') click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 461
def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
  commit_options = {}
  head = "refs/heads/#{head}" if head && head !~ %r(^refs/heads/)
  parents = get_parents(parents, head) || []
  actor = Gollum::Git::Actor.default_actor if actor.nil?
  commit_options[:tree] = @index.write_tree
  commit_options[:author] = actor.to_h
  commit_options[:committer] = actor.to_h
  commit_options[:message] = message.to_s
  commit_options[:parents] = parents
  commit_options[:update_ref] = head
  Rugged::Commit.create(@rugged_repo, commit_options)
end
current_tree() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 488
def current_tree
  @current_tree
end
delete(path) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 435
def delete(path)
  @index.remove(path)
  update_treemap(path, false)
  false
end
delete_all(glob) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 441
def delete_all(glob)
  # if the path start with escape it and avoid treating it as a comment
  escaped_glob = glob[0] == '#' ? glob.sub('#', '\#') : glob

  @index.remove_all(escaped_glob)
  update_treemap(glob, false)
  false
end
index() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 457
def index
  @index
end
read_tree(id) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 479
def read_tree(id)
  id = Gollum::Git::Git.new(@rugged_repo).ref_to_sha(id)
  return nil if id.nil?
  current_tree = @rugged_repo.lookup(id)
  current_tree = current_tree.tree unless current_tree.is_a?(Rugged::Tree)
  @index.read_tree(current_tree)
  @current_tree = Gollum::Git::Tree.new(current_tree)
end
tree() click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 475
def tree
  @treemap
end

Private Instance Methods

get_parents(parents, head) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 494
def get_parents(parents, head)
  if parents
    parents.map{|parent| parent.commit}
  elsif ref = @rugged_repo.references[head]
    ref = ref.target
    ref = ref.target if ref.respond_to?(:target)
    [ref]
  end
end
update_treemap(path, data) click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 504
def update_treemap(path, data)
  # From RJGit::Plumbing::Index
  path = path[1..-1] if path[0] == ::File::SEPARATOR
  path = path.split(::File::SEPARATOR)
  last = path.pop

  current = @treemap

  path.each do |dir|
    current[dir] ||= {}
    node = current[dir]
    current = node
  end

  current[last] = data
  @treemap
end