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.
Class Method Summary collapse
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 |
# 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
#ptr ⇒ Object
Returns the value of attribute ptr.
3 4 5 |
# File 'lib/simple_git/commit.rb', line 3 def ptr @ptr end |
Class Method Details
.finalize(ptr) ⇒ Object
54 55 56 |
# File 'lib/simple_git/commit.rb', line 54 def self.finalize(ptr) proc { Git2.git_commit_free(ptr) } end |
Instance Method Details
#author ⇒ Object
35 36 37 |
# File 'lib/simple_git/commit.rb', line 35 def @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, = nil) @diffs ||= {} @diffs[] ||= Diff.new.from_trees(@repo, tree, new_commit.tree, || DiffOptions.new) end |
#message ⇒ Object
39 40 41 |
# File 'lib/simple_git/commit.rb', line 39 def @message ||= Git2.(@ptr).read_string end |
#oid ⇒ Object
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_count ⇒ Object
27 28 29 |
# File 'lib/simple_git/commit.rb', line 27 def parent_count Git2.git_commit_parentcount(@ptr) end |
#tree ⇒ Object
31 32 33 |
# File 'lib/simple_git/commit.rb', line 31 def tree @tree ||= Tree.new.from_commit(self) end |