Class: SimpleGit::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_git/commit.rb

Defined Under Namespace

Classes: CommitWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, oid) ⇒ Commit

Returns a new instance of Commit.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#ptrObject

Returns the value of attribute ptr.



3
4
5
# File 'lib/simple_git/commit.rb', line 3

def ptr
  @ptr
end

Instance Method Details

#authorObject



43
44
45
# File 'lib/simple_git/commit.rb', line 43

def author
  @author ||= Signature.new(self)
end

#diff(new_commit, options = nil) ⇒ Object



55
56
57
58
# File 'lib/simple_git/commit.rb', line 55

def diff(new_commit, options = nil)
  @diffs ||= {}
  @diffs[options] ||= Diff.new.from_trees(@repo, tree, new_commit.tree, options || DiffOptions.new)
end

#messageObject



47
48
49
# File 'lib/simple_git/commit.rb', line 47

def message
  @message ||= Git2.git_commit_message(@ptr)&.read_string
end

#oidObject



51
52
53
# File 'lib/simple_git/commit.rb', line 51

def oid
  @oid
end

#parent(n) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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.ptr = wrapper[:commit]
  ObjectSpace.define_finalizer(c, c.class.finalize(c.ptr))

  c
end

#parent_countObject



35
36
37
# File 'lib/simple_git/commit.rb', line 35

def parent_count
  Git2.git_commit_parentcount(@ptr)
end

#treeObject



39
40
41
# File 'lib/simple_git/commit.rb', line 39

def tree
  @tree ||= Tree.new.from_commit(self)
end