Replace list.List
with slices (#16311)
* Replaced list with slice. * Fixed usage of pointer to temporary variable. * Replaced LIFO list with slice. * Lint * Removed type check. * Removed duplicated code. * Lint * Fixed merge. Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
23d438f565
commit
d9ef43a712
29 changed files with 183 additions and 302 deletions
|
@ -190,20 +190,14 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||
|
||||
userCache := make(map[string]*models.User)
|
||||
|
||||
apiCommits := make([]*api.Commit, commits.Len())
|
||||
|
||||
i := 0
|
||||
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
|
||||
commit := commitPointer.Value.(*git.Commit)
|
||||
|
||||
apiCommits := make([]*api.Commit, len(commits))
|
||||
for i, commit := range commits {
|
||||
// Create json struct
|
||||
apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "toCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
// kept for backwards compatibility
|
||||
|
|
|
@ -1211,7 +1211,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
|||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
totalNumberOfCommits := commits.Len()
|
||||
totalNumberOfCommits := len(commits)
|
||||
totalNumberOfPages := int(math.Ceil(float64(totalNumberOfCommits) / float64(listOptions.PageSize)))
|
||||
|
||||
userCache := make(map[string]*models.User)
|
||||
|
@ -1222,29 +1222,14 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
|||
end = totalNumberOfCommits
|
||||
}
|
||||
|
||||
apiCommits := make([]*api.Commit, end-start)
|
||||
|
||||
i := 0
|
||||
addedCommitsCount := 0
|
||||
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
|
||||
if i < start {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if i >= end {
|
||||
break
|
||||
}
|
||||
|
||||
commit := commitPointer.Value.(*git.Commit)
|
||||
|
||||
// Create json struct
|
||||
apiCommits[addedCommitsCount], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
|
||||
addedCommitsCount++
|
||||
apiCommits := make([]*api.Commit, 0, end-start)
|
||||
for i := start; i < end; i++ {
|
||||
apiCommit, err := convert.ToCommit(ctx.Repo.Repository, commits[i], userCache)
|
||||
if err != nil {
|
||||
ctx.ServerError("toCommit", err)
|
||||
return
|
||||
}
|
||||
i++
|
||||
apiCommits = append(apiCommits, apiCommit)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(totalNumberOfCommits), listOptions.PageSize)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
"html"
|
||||
gotemplate "html/template"
|
||||
|
@ -138,15 +137,15 @@ func RefBlame(ctx *context.Context) {
|
|||
ctx.HTML(http.StatusOK, tplBlame)
|
||||
}
|
||||
|
||||
func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]models.UserCommit, map[string]string) {
|
||||
func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*models.UserCommit, map[string]string) {
|
||||
// store commit data by SHA to look up avatar info etc
|
||||
commitNames := make(map[string]models.UserCommit)
|
||||
commitNames := make(map[string]*models.UserCommit)
|
||||
// previousCommits contains links from SHA to parent SHA,
|
||||
// if parent also contains the current TreePath.
|
||||
previousCommits := make(map[string]string)
|
||||
// and as blameParts can reference the same commits multiple
|
||||
// times, we cache the lookup work locally
|
||||
commits := list.New()
|
||||
commits := make([]*git.Commit, 0, len(blameParts))
|
||||
commitCache := map[string]*git.Commit{}
|
||||
commitCache[ctx.Repo.Commit.ID.String()] = ctx.Repo.Commit
|
||||
|
||||
|
@ -190,22 +189,18 @@ func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[st
|
|||
}
|
||||
}
|
||||
|
||||
commits.PushBack(commit)
|
||||
|
||||
commitNames[commit.ID.String()] = models.UserCommit{}
|
||||
commits = append(commits, commit)
|
||||
}
|
||||
|
||||
// populate commit email addresses to later look up avatars.
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
for e := commits.Front(); e != nil; e = e.Next() {
|
||||
c := e.Value.(models.UserCommit)
|
||||
for _, c := range models.ValidateCommitsWithEmails(commits) {
|
||||
commitNames[c.ID.String()] = c
|
||||
}
|
||||
|
||||
return commitNames, previousCommits
|
||||
}
|
||||
|
||||
func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]models.UserCommit, previousCommits map[string]string) {
|
||||
func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*models.UserCommit, previousCommits map[string]string) {
|
||||
repoLink := ctx.Repo.RepoLink
|
||||
|
||||
var lines = make([]string, 0)
|
||||
|
|
|
@ -72,10 +72,7 @@ func Commits(ctx *context.Context) {
|
|||
ctx.ServerError("CommitsByRange", err)
|
||||
return
|
||||
}
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
|
||||
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
|
||||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
|
@ -193,10 +190,8 @@ func SearchCommits(ctx *context.Context) {
|
|||
ctx.ServerError("SearchCommits", err)
|
||||
return
|
||||
}
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
|
||||
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["CommitCount"] = len(commits)
|
||||
ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
|
||||
|
||||
ctx.Data["Keyword"] = query
|
||||
if all {
|
||||
|
@ -204,7 +199,6 @@ func SearchCommits(ctx *context.Context) {
|
|||
}
|
||||
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(http.StatusOK, tplCommits)
|
||||
}
|
||||
|
@ -239,10 +233,7 @@ func FileHistory(ctx *context.Context) {
|
|||
ctx.ServerError("CommitsByFileAndRange", err)
|
||||
return
|
||||
}
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
|
||||
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository)
|
||||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
|
|
|
@ -551,14 +551,12 @@ func PrepareCompareDiff(
|
|||
return false
|
||||
}
|
||||
|
||||
compareInfo.Commits = models.ValidateCommitsWithEmails(compareInfo.Commits)
|
||||
compareInfo.Commits = models.ParseCommitsWithSignature(compareInfo.Commits, headRepo)
|
||||
compareInfo.Commits = models.ParseCommitsWithStatus(compareInfo.Commits, headRepo)
|
||||
ctx.Data["Commits"] = compareInfo.Commits
|
||||
ctx.Data["CommitCount"] = compareInfo.Commits.Len()
|
||||
commits := models.ConvertFromGitCommit(compareInfo.Commits, headRepo)
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["CommitCount"] = len(commits)
|
||||
|
||||
if compareInfo.Commits.Len() == 1 {
|
||||
c := compareInfo.Commits.Front().Value.(models.SignCommitWithStatuses)
|
||||
if len(commits) == 1 {
|
||||
c := commits[0]
|
||||
title = strings.TrimSpace(c.UserCommit.Summary())
|
||||
|
||||
body := strings.Split(strings.TrimSpace(c.UserCommit.Message()), "\n")
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -327,11 +326,11 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
|
|||
ctx.ServerError("GetCompareInfo", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
|
||||
ctx.Data["NumCommits"] = len(compareInfo.Commits)
|
||||
ctx.Data["NumFiles"] = compareInfo.NumFiles
|
||||
|
||||
if compareInfo.Commits.Len() != 0 {
|
||||
sha := compareInfo.Commits.Front().Value.(*git.Commit).ID.String()
|
||||
if len(compareInfo.Commits) != 0 {
|
||||
sha := compareInfo.Commits[0].ID.String()
|
||||
commitStatuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, sha, models.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
|
@ -411,7 +410,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||
return nil
|
||||
}
|
||||
|
||||
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
|
||||
ctx.Data["NumCommits"] = len(compareInfo.Commits)
|
||||
ctx.Data["NumFiles"] = compareInfo.NumFiles
|
||||
return compareInfo
|
||||
}
|
||||
|
@ -543,7 +542,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
|||
ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
|
||||
}
|
||||
|
||||
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
|
||||
ctx.Data["NumCommits"] = len(compareInfo.Commits)
|
||||
ctx.Data["NumFiles"] = compareInfo.NumFiles
|
||||
return compareInfo
|
||||
}
|
||||
|
@ -559,7 +558,6 @@ func ViewPullCommits(ctx *context.Context) {
|
|||
}
|
||||
pull := issue.PullRequest
|
||||
|
||||
var commits *list.List
|
||||
var prInfo *git.CompareInfo
|
||||
if pull.HasMerged {
|
||||
prInfo = PrepareMergedViewPullInfo(ctx, issue)
|
||||
|
@ -576,12 +574,10 @@ func ViewPullCommits(ctx *context.Context) {
|
|||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
commits = prInfo.Commits
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
|
||||
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
|
||||
|
||||
commits := models.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository)
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["CommitCount"] = len(commits)
|
||||
|
||||
getBranchData(ctx, issue)
|
||||
ctx.HTML(http.StatusOK, tplPullCommits)
|
||||
|
|
|
@ -312,10 +312,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
|||
ctx.ServerError("CommitsByFileAndRangeNoFollow", err)
|
||||
return nil, nil
|
||||
}
|
||||
commitsHistory = models.ValidateCommitsWithEmails(commitsHistory)
|
||||
commitsHistory = models.ParseCommitsWithSignature(commitsHistory, ctx.Repo.Repository)
|
||||
|
||||
ctx.Data["Commits"] = commitsHistory
|
||||
ctx.Data["Commits"] = models.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository)
|
||||
|
||||
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue