当前位置: 首页>>代码示例>>Golang>>正文


Golang Commit.ParentId方法代码示例

本文整理汇总了Golang中github.com/libgit2/git2go.Commit.ParentId方法的典型用法代码示例。如果您正苦于以下问题:Golang Commit.ParentId方法的具体用法?Golang Commit.ParentId怎么用?Golang Commit.ParentId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/libgit2/git2go.Commit的用法示例。


在下文中一共展示了Commit.ParentId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例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


注:本文中的github.com/libgit2/git2go.Commit.ParentId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。