mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:
@@ -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]
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user