當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Tree.EntryByPath方法代碼示例

本文整理匯總了Golang中github.com/libgit2/git2go.Tree.EntryByPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tree.EntryByPath方法的具體用法?Golang Tree.EntryByPath怎麽用?Golang Tree.EntryByPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/libgit2/git2go.Tree的用法示例。


在下文中一共展示了Tree.EntryByPath方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: assertBlobInTree

func assertBlobInTree(t *testing.T, repo *git.Repository, tree *git.Tree, key, value string) {
	e, err := tree.EntryByPath(key)
	if err != nil || e == nil {
		t.Fatalf("No blob at key %v.\n\ttree=%#v\n", key, tree)
	}
	blob, err := lookupBlob(repo, e.Id)
	if err != nil {
		t.Fatalf("No blob at key %v.\\n\terr=%v\n\ttree=%#v\n", key, err, tree)
	}
	if string(blob.Contents()) != value {
		t.Fatalf("blob at key %v != %v.\n\ttree=%#v\n\treal val = %v\n", key, value, tree, string(blob.Contents()))
	}
	blob.Free()
}
開發者ID:tychoish,項目名稱:libpack-1,代碼行數:14,代碼來源:tree_test.go

示例2: TreeScope

func TreeScope(repo *git.Repository, tree *git.Tree, name string) (*git.Tree, error) {
	if tree == nil {
		return nil, fmt.Errorf("tree undefined")
	}
	name = TreePath(name)
	if name == "/" {
		// Allocate a new Tree object so that the caller
		// can always call Free() on the result
		return lookupTree(repo, tree.Id())
	}
	entry, err := tree.EntryByPath(name)
	if err != nil {
		return nil, err
	}
	return lookupTree(repo, entry.Id)
}
開發者ID:kissthink,項目名稱:libpack,代碼行數:16,代碼來源:tree.go

示例3: TreeGet

func TreeGet(r *git.Repository, t *git.Tree, key string) (string, error) {
	if t == nil {
		return "", os.ErrNotExist
	}
	key = TreePath(key)
	e, err := t.EntryByPath(key)
	if err != nil {
		return "", err
	}
	blob, err := lookupBlob(r, e.Id)
	if err != nil {
		return "", err
	}
	defer blob.Free()
	return string(blob.Contents()), nil

}
開發者ID:kissthink,項目名稱:libpack,代碼行數:17,代碼來源:tree.go

示例4: FindReviewers

// FindReviewers returns up to 3 of the top reviewers information as determined
// by cumulative commit count across all files in `paths`.
func (r *Reviewer) FindReviewers(paths []string) (string, error) {
	var (
		rg        runGuard
		rw        *gg.RevWalk
		since     time.Time
		reviewers map[string]int
		final     Stats
	)

	reviewers = make(map[string]int)

	if len(r.Since) > 0 {
		var err error
		since, err = time.Parse("2006-01-02", r.Since)
		if err != nil {
			if r.Verbose {
				fmt.Println("Unable to parse 'since'")
			}
			return "", err
		}
	} else {
		// Calculate 6 months ago from today's date and set the 'since' argument
		since = time.Now().AddDate(0, -6, 0)
	}

	// Cleanup
	defer func() {
		objs := [...]freeable{
			rw,
		}
		for _, obj := range objs {
			if obj != nil {
				obj.Free()
			}
		}
	}()

	// Iterate through commits in the review period
	rg.maybeRun(func() {
		var err error
		if rw, err = r.Repo.Walk(); err != nil {
			rg.err = err
			rg.msg = "Issue opening revwalk"
		}

		rw.Sorting(gg.SortTime | gg.SortTopological)
	})

	rg.maybeRun(func() {
		var err error
		// TODO push master, not HEAD
		if err = rw.PushHead(); err != nil {
			rg.err = err
			rg.msg = "Issue pushing HEAD onto revwalk"
		}
	})

	// For each of our commits in the review period, see if it affects
	// at least one of the paths changed in the branch. If so, the commit
	// author is added to the count of contributors with experience with one
	// of the changed files in our branch.
	rg.maybeRun(func() {
		var err error

		// Revwalk.Iterate walks through commits until the
		// RevWalkIterator returns false.
		err = rw.Iterate(func(c *gg.Commit) bool {
			var (
				err  error
				tree *gg.Tree
			)
			defer c.Free()

			sig := c.Committer()

			// Stop walking commits since we've passed 'since'
			if sig.When.Before(since) {
				return false
			}

			tree, err = c.Tree()
			if err != nil {
				rg.err = err
				return false
			}

			// Check desired paths to see if one exists in the commit tree
			for _, p := range paths {
				te, err := tree.EntryByPath(p)
				if err != nil {
					continue
				}

				if te != nil {
					k := reviewerKey(sig)
					if _, ok := reviewers[k]; ok {
						reviewers[k]++
					} else {
//.........這裏部分代碼省略.........
開發者ID:davidann,項目名稱:git-reviewer,代碼行數:101,代碼來源:reviewers.go

示例5: assertBlobNotInTree

func assertBlobNotInTree(t *testing.T, repo *git.Repository, tree *git.Tree, key string) {
	_, err := tree.EntryByPath(key)
	if err == nil {
		t.Fatalf("Key %q still exists in tree", key)
	}
}
開發者ID:kissthink,項目名稱:libpack,代碼行數:6,代碼來源:tree_test.go


注:本文中的github.com/libgit2/git2go.Tree.EntryByPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。