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 /routers/api | |
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 'routers/api')
-rw-r--r-- | routers/api/v1/repo/commits.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 25 |
2 files changed, 7 insertions, 28 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index e4bea4dee7..9950a7d456 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -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 diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 3ae7b2683e..9be6228bfd 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -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) |