class SimpleGit::Commit

Attributes

oid[RW]
ptr[RW]
repo[RW]

Public Class Methods

new(repo, oid) click to toggle source
# File lib/simple_git/commit.rb, line 5
def initialize(repo, oid)
  wrapper = CommitWrapper.new
  ret = Git2.git_commit_lookup(wrapper, repo.ptr, oid.ptr)
  if ret != 0
    error = Git2::GitError.new(Git2.giterr_last)
    raise ArgumentError, error[:message].read_string
  end

  @repo = repo
  @oid = oid.to_s
  @ptr = wrapper[:commit]

  ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
end

Private Class Methods

finalize(ptr) click to toggle source
# File lib/simple_git/commit.rb, line 68
def self.finalize(ptr)
  proc { Git2.git_commit_free(ptr) }
end

Public Instance Methods

author() click to toggle source
# File lib/simple_git/commit.rb, line 45
def author
  @author ||= Signature.new(self)
end
diff(new_commit, options = nil) click to toggle source
# File lib/simple_git/commit.rb, line 61
def diff(new_commit, options = nil)
  @diffs ||= {}
  @diffs[options] ||= Diff.new.from_trees(@repo, tree, new_commit.tree, options || DiffOptions.new)
end
message() click to toggle source
# File lib/simple_git/commit.rb, line 49
def message
  @message ||= Git2.git_commit_message(@ptr)&.read_string
end
parent(n) click to toggle source
# File lib/simple_git/commit.rb, line 20
def parent(n)
  wrapper = CommitWrapper.new
  ret = Git2.git_commit_parent(wrapper, @ptr, n)
  if ret != 0
    error = Git2::GitError.new(Git2.giterr_last)
    raise ArgumentError, error[:message].read_string
  end

  c = Commit.allocate
  c.repo = @repo
  # fixme: oid
  c.ptr = wrapper[:commit]
  ObjectSpace.define_finalizer(c, c.class.finalize(c.ptr))

  c
end
parent_count() click to toggle source
# File lib/simple_git/commit.rb, line 37
def parent_count
  Git2.git_commit_parentcount(@ptr)
end
time() click to toggle source
# File lib/simple_git/commit.rb, line 57
def time
  Time.at(Git2.git_commit_time(@ptr))
end
tree() click to toggle source
# File lib/simple_git/commit.rb, line 41
def tree
  @tree ||= Tree.new.from_commit(self)
end