1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Run gopls modernize on codebase (#34751)

Recent modernize fixes:
https://github.com/golang/tools/commits/master/gopls/internal/analysis/modernize
This commit is contained in:
silverwind
2025-06-18 03:48:09 +02:00
committed by GitHub
parent 71e4740946
commit 1f35435b81
190 changed files with 369 additions and 696 deletions

View File

@@ -139,7 +139,7 @@ func CleanUploadFileName(name string) string {
// Rebase the filename
name = util.PathJoinRel(name)
// Git disallows any filenames to have a .git directory in them.
for _, part := range strings.Split(name, "/") {
for part := range strings.SplitSeq(name, "/") {
if strings.ToLower(part) == ".git" {
return ""
}

View File

@@ -128,7 +128,7 @@ func (t *TemporaryUploadRepository) LsFiles(ctx context.Context, filenames ...st
}
fileList := make([]string, 0, len(filenames))
for _, line := range bytes.Split(stdOut.Bytes(), []byte{'\000'}) {
for line := range bytes.SplitSeq(stdOut.Bytes(), []byte{'\000'}) {
fileList = append(fileList, string(line))
}

View File

@@ -94,11 +94,7 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
if len(entries) > perPage {
tree.Truncated = true
}
if rangeStart+perPage < len(entries) {
rangeEnd = rangeStart + perPage
} else {
rangeEnd = len(entries)
}
rangeEnd = min(rangeStart+perPage, len(entries))
tree.Entries = make([]api.GitEntry, rangeEnd-rangeStart)
for e := rangeStart; e < rangeEnd; e++ {
i := e - rangeStart

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"path"
"slices"
"strings"
"time"
@@ -203,13 +204,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
}
// Find the file we want to delete in the index
inFilelist := false
for _, indexFile := range filesInIndex {
if indexFile == file.TreePath {
inFilelist = true
break
}
}
inFilelist := slices.Contains(filesInIndex, file.TreePath)
if !inFilelist {
return nil, ErrRepoFileDoesNotExist{
Path: file.TreePath,
@@ -467,11 +462,9 @@ func CreateUpdateRenameFile(ctx context.Context, t *TemporaryUploadRepository, f
}
// If is a new file (not updating) then the given path shouldn't exist
if file.Operation == "create" {
for _, indexFile := range filesInIndex {
if indexFile == file.TreePath {
return ErrRepoFileAlreadyExists{
Path: file.TreePath,
}
if slices.Contains(filesInIndex, file.TreePath) {
return ErrRepoFileAlreadyExists{
Path: file.TreePath,
}
}
}