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
# File 'lib/simple_git/commit.rb', line 5

def initialize(repo, oid)
  wrapper = CommitWrapper.new
  Git2.git_commit_lookup(wrapper, repo.ptr, oid.ptr)

  @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



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

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

#diff(new_commit, options = nil) ⇒ Object



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

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

#messageObject



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

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

#oidObject



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

def oid
  @oid
end

#parent(n) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/simple_git/commit.rb', line 16

def parent(n)
  wrapper = CommitWrapper.new
  Git2.git_commit_parent(wrapper, @ptr, n)

  c = Commit.allocate
  c.ptr = wrapper[:commit]
  ObjectSpace.define_finalizer(c, c.class.finalize(c.ptr))

  c
end

#parent_countObject



27
28
29
# File 'lib/simple_git/commit.rb', line 27

def parent_count
  Git2.git_commit_parentcount(@ptr)
end

#treeObject



31
32
33
# File 'lib/simple_git/commit.rb', line 31

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