github.com/erikjuhani/git-gong@v0.0.0-20220213141213-6b9fa82d4e7c/gong/commit.go (about)

     1  package gong
     2  
     3  import (
     4  	git "github.com/libgit2/git2go/v31"
     5  )
     6  
     7  type Commit struct {
     8  	ID      *git.Oid
     9  	Message string
    10  	essence *git.Commit
    11  }
    12  
    13  func (commit *Commit) Essence() *git.Commit {
    14  	return commit.essence
    15  }
    16  
    17  func NewCommit(commit *git.Commit) *Commit {
    18  	id := commit.Id()
    19  	msg := commit.Message()
    20  
    21  	return &Commit{
    22  		ID:      id,
    23  		Message: msg,
    24  		essence: commit,
    25  	}
    26  }
    27  
    28  func (commit *Commit) Parent() *Commit {
    29  	return NewCommit(commit.essence.Parent(0))
    30  }
    31  
    32  func (commit *Commit) HasChildren() bool {
    33  	return commit.essence.ParentCount() != 0
    34  }
    35  
    36  func (commit *Commit) Tree() (*git.Tree, error) {
    37  	return commit.essence.Tree()
    38  }
    39  
    40  func (commit *Commit) Free() {
    41  	commit.Essence().Free()
    42  }