Class: SimpleGit::Commit
- Inherits:
-
Object
- Object
- SimpleGit::Commit
- Defined in:
- lib/simple_git/commit.rb
Defined Under Namespace
Classes: CommitWrapper
Instance Attribute Summary collapse
-
#ptr ⇒ Object
Returns the value of attribute ptr.
Instance Method Summary collapse
- #author ⇒ Object
- #diff(new_commit, options = nil) ⇒ Object
-
#initialize(repo, oid) ⇒ Commit
constructor
A new instance of Commit.
- #message ⇒ Object
- #oid ⇒ Object
- #parent(n) ⇒ Object
- #parent_count ⇒ Object
- #tree ⇒ Object
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
#ptr ⇒ Object
Returns the value of attribute ptr.
3 4 5 |
# File 'lib/simple_git/commit.rb', line 3 def ptr @ptr end |
Instance Method Details
#author ⇒ Object
43 44 45 |
# File 'lib/simple_git/commit.rb', line 43 def @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, = nil) @diffs ||= {} @diffs[] ||= Diff.new.from_trees(@repo, tree, new_commit.tree, || DiffOptions.new) end |
#message ⇒ Object
47 48 49 |
# File 'lib/simple_git/commit.rb', line 47 def @message ||= Git2.(@ptr)&.read_string end |
#oid ⇒ Object
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_count ⇒ Object
35 36 37 |
# File 'lib/simple_git/commit.rb', line 35 def parent_count Git2.git_commit_parentcount(@ptr) end |
#tree ⇒ Object
39 40 41 |
# File 'lib/simple_git/commit.rb', line 39 def tree @tree ||= Tree.new.from_commit(self) end |