本文整理匯總了Golang中github.com/libgit2/git2go.Commit.Free方法的典型用法代碼示例。如果您正苦於以下問題:Golang Commit.Free方法的具體用法?Golang Commit.Free怎麽用?Golang Commit.Free使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/libgit2/git2go.Commit
的用法示例。
在下文中一共展示了Commit.Free方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CommitToRef
func CommitToRef(r *git.Repository, tree *git.Tree, parent *git.Commit, refname, msg string) (*git.Commit, error) {
// Retry loop in case of conflict
// FIXME: use a custom inter-process lock as a first attempt for performance
var (
needMerge bool
tmpCommit *git.Commit
)
for {
if !needMerge {
// Create simple commit
commit, err := mkCommit(r, refname, msg, tree, parent)
if isGitConcurrencyErr(err) {
needMerge = true
continue
}
return commit, err
} else {
if tmpCommit == nil {
var err error
// Create a temporary intermediary commit, to pass to MergeCommits
// NOTE: this commit will not be part of the final history.
tmpCommit, err = mkCommit(r, "", msg, tree, parent)
if err != nil {
return nil, err
}
defer tmpCommit.Free()
}
// Lookup tip from ref
tip := lookupTip(r, refname)
if tip == nil {
// Ref may have been deleted after previous merge error
needMerge = false
continue
}
// Merge simple commit with the tip
opts, err := git.DefaultMergeOptions()
if err != nil {
return nil, err
}
idx, err := r.MergeCommits(tmpCommit, tip, &opts)
if err != nil {
return nil, err
}
conflicts, err := idx.ConflictIterator()
if err != nil {
return nil, err
}
defer conflicts.Free()
for {
c, err := conflicts.Next()
if isGitIterOver(err) {
break
} else if err != nil {
return nil, err
}
if c.Our != nil {
idx.RemoveConflict(c.Our.Path)
if err := idx.Add(c.Our); err != nil {
return nil, fmt.Errorf("error resolving merge conflict for '%s': %v", c.Our.Path, err)
}
}
}
mergedId, err := idx.WriteTreeTo(r)
if err != nil {
return nil, fmt.Errorf("WriteTree: %v", err)
}
mergedTree, err := lookupTree(r, mergedId)
if err != nil {
return nil, err
}
// Create new commit from merged tree (discarding simple commit)
commit, err := mkCommit(r, refname, msg, mergedTree, parent, tip)
if isGitConcurrencyErr(err) {
// FIXME: enforce a maximum number of retries to avoid infinite loops
continue
}
return commit, err
}
}
return nil, fmt.Errorf("too many failed merge attempts, giving up")
}