func SearchCommits(ctx *context.Context) { ctx.Data["PageIsCommits"] = true keyword := ctx.Query("q") if len(keyword) == 0 { ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) return } commits, err := ctx.Repo.Commit.SearchCommits(keyword) if err != nil { ctx.Handle(500, "SearchCommits", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Keyword"] = keyword ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commits.Len() ctx.Data["Branch"] = ctx.Repo.BranchName ctx.HTML(200, COMMITS) }
func Commits(ctx *context.Context) { ctx.Data["PageIsCommits"] = true commitsCount, err := ctx.Repo.Commit.CommitsCount() if err != nil { ctx.Handle(500, "GetCommitsCount", err) return } page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5) // Both `git log branchName` and `git log commitId` work. commits, err := ctx.Repo.Commit.CommitsByRange(page) if err != nil { ctx.Handle(500, "CommitsByRange", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commitsCount ctx.Data["Branch"] = ctx.Repo.BranchName ctx.HTML(200, COMMITS) }
func PrepareCompareDiff( ctx *context.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"] = headRepo.RepoLink() headCommitID, err := headGitRepo.GetBranchCommitID(headBranch) if err != nil { ctx.Handle(500, "GetBranchCommitID", 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 }
func ViewPullCommits(ctx *context.Context) { ctx.Data["PageIsPullCommits"] = true pull := checkPullInfo(ctx) if ctx.Written() { return } ctx.Data["Username"] = pull.HeadUserName ctx.Data["Reponame"] = pull.HeadRepo.Name var commits *list.List if pull.HasMerged { PrepareMergedViewPullInfo(ctx, pull) if ctx.Written() { return } startCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergeBase) if err != nil { ctx.Handle(500, "Repo.GitRepo.GetCommit", err) return } endCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.GetCommit", err) return } commits, err = ctx.Repo.GitRepo.CommitsBetween(endCommit, startCommit) if err != nil { ctx.Handle(500, "Repo.GitRepo.CommitsBetween", err) return } } else { prInfo := PrepareViewPullInfo(ctx, pull) if ctx.Written() { return } else if prInfo == nil { ctx.Handle(404, "ViewPullCommits", nil) return } commits = prInfo.Commits } commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["CommitCount"] = commits.Len() ctx.HTML(200, PULL_COMMITS) }
func CompareDiff(ctx *context.Context) { ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsDiffCompare"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name beforeCommitID := ctx.Params(":before") afterCommitID := ctx.Params(":after") commit, err := ctx.Repo.GitRepo.GetCommit(afterCommitID) if err != nil { ctx.Handle(404, "GetCommit", err) return } diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitID, afterCommitID, setting.Git.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffRange", err) return } commits, err := commit.CommitsBeforeUntil(beforeCommitID) if err != nil { ctx.Handle(500, "CommitsBeforeUntil", err) return } commits = models.ValidateCommitsWithEmails(commits) ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split" ctx.Data["CommitRepoLink"] = ctx.Repo.RepoLink ctx.Data["Commits"] = commits ctx.Data["CommitCount"] = commits.Len() ctx.Data["BeforeCommitID"] = beforeCommitID ctx.Data["AfterCommitID"] = afterCommitID ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = commit.IsImageFile ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + "..." + base.ShortSha(afterCommitID) + " · " + userName + "/" + repoName ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", afterCommitID) ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", beforeCommitID) ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", afterCommitID) ctx.HTML(200, DIFF) }
func FileHistory(ctx *context.Context) { ctx.Data["IsRepoToolbarCommits"] = true fileName := ctx.Repo.TreeName if len(fileName) == 0 { Commits(ctx) return } branchName := ctx.Repo.BranchName commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) if err != nil { ctx.Handle(500, "FileCommitsCount", err) return } else if commitsCount == 0 { ctx.Handle(404, "FileCommitsCount", nil) return } page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5) commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page) if err != nil { ctx.Handle(500, "CommitsByFileAndRange", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["FileName"] = fileName ctx.Data["CommitCount"] = commitsCount ctx.Data["Branch"] = branchName ctx.HTML(200, COMMITS) }