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


Golang Commit.Tree方法代碼示例

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


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

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


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