diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-08-09 20:08:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 14:08:51 -0400 |
commit | d9ef43a7126ab83af563c1c9b54cdf0092327b2a (patch) | |
tree | fabc9a9d24d42bb0de6dd9557c9e07e95bd5722b /services | |
parent | 23d438f56524a7c3fc185df66d6d95f797a80eee (diff) | |
download | gitea-d9ef43a7126ab83af563c1c9b54cdf0092327b2a.tar.gz gitea-d9ef43a7126ab83af563c1c9b54cdf0092327b2a.zip |
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>
Diffstat (limited to 'services')
-rw-r--r-- | services/mirror/mirror_pull.go | 2 | ||||
-rw-r--r-- | services/pull/pull.go | 32 | ||||
-rw-r--r-- | services/repository/push.go | 5 |
3 files changed, 17 insertions, 22 deletions
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index a16724b36f..89b5df4638 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -354,7 +354,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { continue } - theCommits := repo_module.ListToPushCommits(commits) + theCommits := repo_module.GitToPushCommits(commits) if len(theCommits.Commits) > setting.UI.FeedMaxCommitNum { theCommits.Commits = theCommits.Commits[:setting.UI.FeedMaxCommitNum] } diff --git a/services/pull/pull.go b/services/pull/pull.go index b33f641130..23407ea67b 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -84,11 +84,11 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6 return err } - if compareInfo.Commits.Len() > 0 { + if len(compareInfo.Commits) > 0 { data := models.PushActionContent{IsForcePush: false} - data.CommitIDs = make([]string, 0, compareInfo.Commits.Len()) - for e := compareInfo.Commits.Back(); e != nil; e = e.Prev() { - data.CommitIDs = append(data.CommitIDs, e.Value.(*git.Commit).ID.String()) + data.CommitIDs = make([]string, 0, len(compareInfo.Commits)) + for i := len(compareInfo.Commits) - 1; i >= 0; i-- { + data.CommitIDs = append(data.CommitIDs, compareInfo.Commits[i].ID.String()) } dataJSON, err := json.Marshal(data) @@ -611,7 +611,7 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { limit := setting.Repository.PullRequest.DefaultMergeMessageCommitsLimit - list, err := gitRepo.CommitsBetweenLimit(headCommit, mergeBase, limit, 0) + commits, err := gitRepo.CommitsBetweenLimit(headCommit, mergeBase, limit, 0) if err != nil { log.Error("Unable to get commits between: %s %s Error: %v", pr.HeadBranch, pr.MergeBase, err) return "" @@ -620,7 +620,7 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { posterSig := pr.Issue.Poster.NewGitSig().String() authorsMap := map[string]bool{} - authors := make([]string, 0, list.Len()) + authors := make([]string, 0, len(commits)) stringBuilder := strings.Builder{} if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages { @@ -635,15 +635,16 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { } // commits list is in reverse chronological order - element := list.Back() - for element != nil { - commit := element.Value.(*git.Commit) + first := true + for i := len(commits) - 1; i >= 0; i-- { + commit := commits[i] if setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages { maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize if maxSize < 0 || stringBuilder.Len() < maxSize { var toWrite []byte - if element == list.Back() { + if first { + first = false toWrite = []byte(strings.TrimPrefix(commit.CommitMessage, pr.Issue.Title)) } else { toWrite = []byte(commit.CommitMessage) @@ -669,7 +670,6 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { authors = append(authors, authorString) authorsMap[authorString] = true } - element = element.Prev() } // Consider collecting the remaining authors @@ -677,25 +677,21 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { skip := limit limit = 30 for { - list, err := gitRepo.CommitsBetweenLimit(headCommit, mergeBase, limit, skip) + commits, err := gitRepo.CommitsBetweenLimit(headCommit, mergeBase, limit, skip) if err != nil { log.Error("Unable to get commits between: %s %s Error: %v", pr.HeadBranch, pr.MergeBase, err) return "" } - if list.Len() == 0 { + if len(commits) == 0 { break } - element := list.Front() - for element != nil { - commit := element.Value.(*git.Commit) - + for _, commit := range commits { authorString := commit.Author.String() if !authorsMap[authorString] && authorString != posterSig { authors = append(authors, authorString) authorsMap[authorString] = true } - element = element.Next() } skip += limit } diff --git a/services/repository/push.go b/services/repository/push.go index 26df6b8e45..cf7060adef 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -5,7 +5,6 @@ package repository import ( - "container/list" "fmt" "time" @@ -147,7 +146,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { refName := opts.RefName() // Push new branch. - var l *list.List + var l []*git.Commit if opts.IsNewRef() { if repo.IsEmpty { // Change default branch and empty status only if pushed ref is non-empty branch. repo.DefaultBranch = refName @@ -191,7 +190,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } } - commits := repo_module.ListToPushCommits(l) + commits := repo_module.GitToPushCommits(l) commits.HeadCommit = repo_module.CommitToPushCommit(newCommit) if err := repofiles.UpdateIssuesCommit(pusher, repo, commits.Commits, refName); err != nil { |