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

#oidObject

Returns the value of attribute oid.



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

def oid
  @oid
end

#ptrObject

Returns the value of attribute ptr.



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

def ptr
  @ptr
end

#repoObject

Returns the value of attribute repo.



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

def repo
  @repo
end

Instance Method Details

#authorObject



45
46
47
# File 'lib/simple_git/commit.rb', line 45

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

#diff(new_commit, options = nil) ⇒ Object



61
62
63
64
# 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

#messageObject



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

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

#parent(n) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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_countObject



37
38
39
# File 'lib/simple_git/commit.rb', line 37

def parent_count
  Git2.git_commit_parentcount(@ptr)
end

#timeObject



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

def time
  Time.at(Git2.git_commit_time(@ptr))
end

#treeObject



41
42
43
# File 'lib/simple_git/commit.rb', line 41

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