本文整理匯總了Golang中github.com/gogits/gogs/modules/git.Repository.GetCommit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repository.GetCommit方法的具體用法?Golang Repository.GetCommit怎麽用?Golang Repository.GetCommit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gogits/gogs/modules/git.Repository
的用法示例。
在下文中一共展示了Repository.GetCommit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PrepareCompareDiff
func PrepareCompareDiff(
ctx *middleware.Context,
headUser *models.User,
headRepo *models.Repository,
headGitRepo *git.Repository,
prInfo *git.PullRequestInfo,
baseBranch, headBranch string) bool {
var (
repo = ctx.Repo.Repository
err error
)
// Get diff information.
ctx.Data["CommitRepoLink"], err = headRepo.RepoLink()
if err != nil {
ctx.Handle(500, "RepoLink", err)
return false
}
headCommitID, err := headGitRepo.GetCommitIdOfBranch(headBranch)
if err != nil {
ctx.Handle(500, "GetCommitIdOfBranch", err)
return false
}
ctx.Data["AfterCommitID"] = headCommitID
if headCommitID == prInfo.MergeBase {
ctx.Data["IsNothingToCompare"] = true
return true
}
diff, err := models.GetDiffRange(models.RepoPath(headUser.Name, headRepo.Name),
prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines)
if err != nil {
ctx.Handle(500, "GetDiffRange", err)
return false
}
ctx.Data["Diff"] = diff
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
headCommit, err := headGitRepo.GetCommit(headCommitID)
if err != nil {
ctx.Handle(500, "GetCommit", err)
return false
}
prInfo.Commits = models.ValidateCommitsWithEmails(prInfo.Commits)
ctx.Data["Commits"] = prInfo.Commits
ctx.Data["CommitCount"] = prInfo.Commits.Len()
ctx.Data["Username"] = headUser.Name
ctx.Data["Reponame"] = headRepo.Name
ctx.Data["IsImageFile"] = headCommit.IsImageFile
headTarget := path.Join(headUser.Name, repo.Name)
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", headCommitID)
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", prInfo.MergeBase)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", headCommitID)
return false
}
示例2: ViewPullFiles
func ViewPullFiles(ctx *middleware.Context) {
ctx.Data["PageIsPullFiles"] = true
pull := checkPullInfo(ctx)
if ctx.Written() {
return
}
var (
diffRepoPath string
startCommitID string
endCommitID string
gitRepo *git.Repository
)
if pull.HasMerged {
PrepareMergedViewPullInfo(ctx, pull)
if ctx.Written() {
return
}
diffRepoPath = ctx.Repo.GitRepo.Path
startCommitID = pull.MergeBase
endCommitID = pull.MergedCommitID
gitRepo = ctx.Repo.GitRepo
} else {
prInfo := PrepareViewPullInfo(ctx, pull)
if ctx.Written() {
return
} else if prInfo == nil {
ctx.Handle(404, "ViewPullFiles", nil)
return
}
headRepoPath := models.RepoPath(pull.HeadUserName, pull.HeadRepo.Name)
headGitRepo, err := git.OpenRepository(headRepoPath)
if err != nil {
ctx.Handle(500, "OpenRepository", err)
return
}
headCommitID, err := headGitRepo.GetCommitIdOfBranch(pull.HeadBranch)
if err != nil {
ctx.Handle(500, "GetCommitIdOfBranch", err)
return
}
diffRepoPath = headRepoPath
startCommitID = prInfo.MergeBase
endCommitID = headCommitID
gitRepo = headGitRepo
}
diff, err := models.GetDiffRange(diffRepoPath,
startCommitID, endCommitID, setting.Git.MaxGitDiffLines)
if err != nil {
ctx.Handle(500, "GetDiffRange", err)
return
}
ctx.Data["Diff"] = diff
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
commit, err := gitRepo.GetCommit(endCommitID)
if err != nil {
ctx.Handle(500, "GetCommit", err)
return
}
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name
ctx.Data["IsImageFile"] = commit.IsImageFile
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", endCommitID)
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", startCommitID)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", endCommitID)
ctx.HTML(200, PULL_FILES)
}