本文整理汇总了Golang中github.com/libgit2/git2go.Commit类的典型用法代码示例。如果您正苦于以下问题:Golang Commit类的具体用法?Golang Commit怎么用?Golang Commit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Commit类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: BranchBehind
// BranchBehind is not yet implemented. Determines if the current branch
// behind master and requires that it be "merged up".
func (r *Reviewer) BranchBehind() (bool, error) {
if r.Repo == nil {
return false, errors.New("repo not initialized")
}
var (
rg runGuard
mBranch *gg.Branch
mCom *gg.Commit
hRef *gg.Reference
hCom *gg.Commit
behind bool
)
defer func() {
objs := [...]freeable{
mBranch,
mCom,
hRef,
hCom,
}
for _, obj := range objs {
obj.Free()
}
}()
rg.maybeRun(func() {
var err error
if mBranch, err = r.Repo.LookupBranch("master", gg.BranchLocal); err != nil {
rg.err = err
rg.msg = "Issue opening master branch"
}
})
rg.maybeRun(func() {
var err error
if mCom, err = r.Repo.LookupCommit(mBranch.Reference.Target()); err != nil {
rg.err = err
rg.msg = "Issue opening master commit"
}
})
rg.maybeRun(func() {
var err error
if hRef, err = r.Repo.Head(); err != nil {
rg.err = err
rg.msg = "Issue opening HEAD reference"
}
})
rg.maybeRun(func() {
var err error
if hCom, err = r.Repo.LookupCommit(hRef.Target()); err != nil {
rg.err = err
rg.msg = "Issue opening HEAD commit"
}
})
rg.maybeRun(func() {
behind = hCom.Committer().When.Before(mCom.Committer().When)
})
return behind, rg.err
}
开发者ID:davidann,项目名称:git-reviewer,代码行数:62,代码来源:reviewers.go
示例2: makeCommit
func (r *Repository) makeCommit(c *git2go.Commit) *vcs.Commit {
var parents []vcs.CommitID
if pc := c.ParentCount(); pc > 0 {
parents = make([]vcs.CommitID, pc)
for i := 0; i < int(pc); i++ {
parents[i] = vcs.CommitID(c.ParentId(uint(i)).String())
}
}
au, cm := c.Author(), c.Committer()
return &vcs.Commit{
ID: vcs.CommitID(c.Id().String()),
Author: vcs.Signature{au.Name, au.Email, pbtypes.NewTimestamp(au.When)},
Committer: &vcs.Signature{cm.Name, cm.Email, pbtypes.NewTimestamp(cm.When)},
Message: strings.TrimSuffix(c.Message(), "\n"),
Parents: parents,
}
}
开发者ID:shazow,项目名称:go-vcs,代码行数:18,代码来源:repo.go
示例3: revWalkSyncHandler
// revWalkSyncHandler adds new commits to the repo graph.
// The walk stops when reaching the previous lastest commit in the database.
func revWalkSyncHandler(commit *git.Commit) bool {
// Get repo path.
r := commit.Owner()
path := r.Path()
// Commit info.
hash := commit.Id().String()
settings := GetSettings()
db, err := neoism.Connect(settings.DbUrl)
if err != nil {
panic(err)
}
res := []struct {
Hash string `json:"c.hash"`
}{}
cq := neoism.CypherQuery{
Statement: `
MATCH (:Repository {path: {path}})-[:HAS_COMMIT]->(c:Commit {hash: {hash}})
RETURN c.hash
`,
Parameters: neoism.Props{
"hash": hash,
"path": path,
},
Result: &res,
}
if err = db.Cypher(&cq); err != nil {
panic(err)
}
// When reaching an existing commit in the database, stop the walk.
if size := len(res); size > 0 {
return false
}
// Else, add the commit to the database.
message := strings.Replace(commit.Message(), "\"", "'", -1)
// Parent info.
parentCount := commit.ParentCount()
var buffer bytes.Buffer
for i := uint(0); i < parentCount; i = i + 1 {
buffer.WriteString(commit.ParentId(i).String())
if i < parentCount-1 {
buffer.WriteString(" ")
}
}
parents := buffer.String()
// Author info.
authorSig := commit.Author()
authorName := authorSig.Name
authorEmail := authorSig.Email
authorTime := authorSig.When.Format("2006-01-02 15:04:05 +0000")
authorTimestamp := strconv.Itoa(int(authorSig.When.Unix()))
// Committer info.
committerSig := commit.Committer()
commitTime := committerSig.When.Format("2006-01-02 15:04:05 +0000")
commitTimestamp := strconv.Itoa(int(committerSig.When.Unix()))
// Add accoding info to the graph.
commitCq := neoism.CypherQuery{
Statement: `
MATCH (r:Repository {path: {path}})
CREATE (r)-[:HAS_COMMIT]->(c:Commit {
message: {message},
author_time: {author_time},
author_timestamp: toInt({author_timestamp}),
commit_time: {commit_time},
commit_timestamp: toInt({commit_timestamp}),
hash: {hash},
parents: split({parents}, ' ')})
MERGE (u:User:Author {email: {author_email}}) ON CREATE SET u.name = {author_name}
MERGE (u)-[:AUTHORED]->(c)
MERGE (c)-[:AUTHORED_BY]->(u)
MERGE (u)-[:CONTRIBUTED_TO]->(r)
WITH c
WHERE {parents} <> ''
FOREACH (parent_hash in split({parents}, ' ') |
MERGE (parent:Commit {hash: parent_hash})
MERGE (c)-[:HAS_PARENT]->(parent))
`,
Parameters: neoism.Props{
"path": path,
"hash": hash,
"message": message,
"author_name": authorName,
"author_email": authorEmail,
"author_time": authorTime,
"author_timestamp": authorTimestamp,
"commit_time": commitTime,
"commit_timestamp": commitTimestamp,
"parents": parents,
},
}
if err = db.Cypher(&commitCq); err != nil {
return false
}
return true
}
开发者ID:nathandao,项目名称:git2neo4j,代码行数:98,代码来源:repository.go
示例4: revWalkHandler
// revWalkHandler goes through each commit and creates relevant info for each
// commit.
func revWalkHandler(commit *git.Commit) bool {
// Commit info.
hash := commit.Id().String()
if hash == "" {
return false
}
message := strings.Replace(commit.Message(), "\"", "'", -1)
// Parent info.
parentCount := commit.ParentCount()
var buffer bytes.Buffer
for i := uint(0); i < parentCount; i = i + 1 {
buffer.WriteString(commit.ParentId(i).String())
if i < parentCount-1 {
buffer.WriteString(" ")
}
}
parents := buffer.String()
// Author info.
authorSig := commit.Author()
authorName := authorSig.Name
authorEmail := authorSig.Email
authorTime := authorSig.When.Format("2006-01-02 15:04:05 +0000")
authorTimestamp := strconv.Itoa(int(authorSig.When.Unix()))
// Committer info.
committerSig := commit.Committer()
commitTime := committerSig.When.Format("2006-01-02 15:04:05 +0000")
commitTimestamp := strconv.Itoa(int(committerSig.When.Unix()))
// Write to csvFile
r := commit.Owner()
csvPath, err := TemporaryCsvPath(r)
if err != nil {
panic(err)
}
csvFile, err := os.OpenFile(csvPath, os.O_RDWR|os.O_APPEND, 0666)
if err != nil {
panic(err)
}
defer csvFile.Close()
w := csv.NewWriter(csvFile)
err = w.Write([]string{
hash, message, authorName, authorEmail, authorTime, authorTimestamp,
commitTime, commitTimestamp, parents,
})
if err != nil {
panic(err)
}
w.Flush()
if err = w.Error(); err != nil {
panic(err)
}
return true
}
开发者ID:nathandao,项目名称:git2neo4j,代码行数:54,代码来源:repository.go
示例5: FindFiles
// FindFiles returns a list of paths to files that have been changed
// in this branch with respect to `master`.
func (r *Reviewer) FindFiles() ([]string, error) {
var (
rg runGuard
lines []string
mBranch *gg.Branch
hRef *gg.Reference
hCom *gg.Commit
mCom *gg.Commit
mTree *gg.Tree
hTree *gg.Tree
opts gg.DiffOptions
diff *gg.Diff
)
if r.Repo == nil {
return lines, errors.New("repo not initialized")
}
defer func() {
objs := [...]freeable{
mBranch,
hRef,
hCom,
mCom,
mTree,
hTree,
}
for _, obj := range objs {
if obj != nil {
obj.Free()
}
}
if err := diff.Free(); err != nil && r.Verbose {
fmt.Printf("Issue cleaning up diff: '%s'\n", err)
}
}()
rg.maybeRun(func() {
var err error
if mBranch, err = r.Repo.LookupBranch("master", gg.BranchLocal); err != nil {
rg.err = err
rg.msg = "issue opening master branch"
}
})
rg.maybeRun(func() {
var err error
if mCom, err = r.Repo.LookupCommit(mBranch.Reference.Target()); err != nil {
rg.err = err
rg.msg = "issue opening commit at master"
}
})
rg.maybeRun(func() {
var err error
if hRef, err = r.Repo.Head(); err != nil {
rg.err = err
rg.msg = "issue opening repo at HEAD"
}
})
rg.maybeRun(func() {
var err error
if hCom, err = r.Repo.LookupCommit(hRef.Target()); err != nil {
rg.err = err
rg.msg = "issue opening commit at HEAD"
}
})
rg.maybeRun(func() {
var err error
if mTree, err = mCom.Tree(); err != nil {
rg.err = err
rg.msg = "issue opening tree at master"
}
})
rg.maybeRun(func() {
var err error
if hTree, err = hCom.Tree(); err != nil {
rg.err = err
rg.msg = "issue opening tree at HEAD"
}
})
rg.maybeRun(func() {
var err error
if opts, err = gg.DefaultDiffOptions(); err != nil {
rg.err = err
rg.msg = "issue creating diff options"
}
})
rg.maybeRun(func() {
var err error
if diff, err = r.Repo.DiffTreeToTree(mTree, hTree, &opts); err != nil {
//.........这里部分代码省略.........
开发者ID:davidann,项目名称:git-reviewer,代码行数:101,代码来源:reviewers.go
示例6: 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")
}
开发者ID:pombredanne,项目名称:libpack,代码行数:82,代码来源:db.go
注:本文中的github.com/libgit2/git2go.Commit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论