"path/filepath"
"strings"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/setting"
)
// use old en-US as the base, and copy the new translations to the old locales
enUsOld := inisOld["options/locale/locale_en-US.ini"]
- brokenWarned := map[string]bool{}
+ brokenWarned := make(container.Set[string])
for path, iniOld := range inisOld {
if iniOld == enUsOld {
continue
broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
if broken {
- brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true
+ brokenWarned.Add(secOld.Name() + "." + keyEnUs.Name())
fmt.Println("----")
fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name())
fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n"))
broken = broken || strings.HasPrefix(str, "`\"")
broken = broken || strings.Count(str, `"`)%2 == 1
broken = broken || strings.Count(str, "`")%2 == 1
- if broken && !brokenWarned[sec.Name()+"."+key.Name()] {
+ if broken && !brokenWarned.Contains(sec.Name()+"."+key.Name()) {
fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name())
fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n"))
fmt.Println("----")
"regexp"
"sort"
"strings"
+
+ "code.gitea.io/gitea/modules/container"
)
// regexp is based on go-license, excluding README and NOTICE
// yml
//
// It could be removed once we have a better regex.
- excludedExt := map[string]bool{
- ".gitignore": true,
- ".go": true,
- ".mod": true,
- ".sum": true,
- ".toml": true,
- ".yml": true,
- }
+ excludedExt := container.SetOf(".gitignore", ".go", ".mod", ".sum", ".toml", ".yml")
+
var paths []string
err := filepath.WalkDir(base, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
- if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt[filepath.Ext(entry.Name())] {
+ if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt.Contains(filepath.Ext(entry.Name())) {
return nil
}
paths = append(paths, path)
"strings"
"code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
// FindUnitTypes give the unit key names and return valid unique units and invalid keys
func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string) {
- m := map[Type]struct{}{}
+ m := make(container.Set[Type])
for _, key := range nameKeys {
t := TypeFromKey(key)
if t == TypeInvalid {
invalidKeys = append(invalidKeys, key)
- } else if _, ok := m[t]; !ok {
+ } else if m.Add(t) {
res = append(res, t)
- m[t] = struct{}{}
}
}
return res, invalidKeys
"sort"
"time"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/util"
// * false: only directories will be returned.
// The returned files are sorted by name.
func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
- fileMap := map[string]bool{}
+ fileSet := make(container.Set[string])
for _, layer := range l.layers {
infos, err := readDir(layer, name)
if err != nil {
}
for _, info := range infos {
if shouldInclude(info, fileMode...) {
- fileMap[info.Name()] = true
+ fileSet.Add(info.Name())
}
}
}
- files := make([]string, 0, len(fileMap))
- for file := range fileMap {
- files = append(files, file)
- }
+ files := fileSet.Values()
sort.Strings(files)
return files, nil
}
}
func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, error) {
- fileMap := map[string]bool{}
+ fileSet := make(container.Set[string])
var list func(dir string) error
list = func(dir string) error {
for _, layer := range layers {
for _, info := range infos {
path := util.PathJoinRelX(dir, info.Name())
if shouldInclude(info, fileMode...) {
- fileMap[path] = true
+ fileSet.Add(path)
}
if info.IsDir() {
if err = list(path); err != nil {
if err := list(name); err != nil {
return nil, err
}
- var files []string
- for file := range fileMap {
- files = append(files, file)
- }
+ files := fileSet.Values()
sort.Strings(files)
return files, nil
}
"html/template"
"reflect"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
)
return m, nil
}
-func dumpVarMarshalable(v any, dumped map[uintptr]bool) (ret any, ok bool) {
+func dumpVarMarshalable(v any, dumped container.Set[uintptr]) (ret any, ok bool) {
if v == nil {
return nil, true
}
}
if e.CanAddr() {
addr := e.UnsafeAddr()
- if dumped[addr] {
+ if !dumped.Add(addr) {
return "[dumped]", false
}
- dumped[addr] = true
- defer delete(dumped, addr)
+ defer dumped.Remove(addr)
}
switch e.Kind() {
case reflect.Bool, reflect.String,
if setting.IsProd {
return "<pre>dumpVar: only available in dev mode</pre>"
}
- m, ok := dumpVarMarshalable(v, map[uintptr]bool{})
+ m, ok := dumpVarMarshalable(v, make(container.Set[uintptr]))
var dumpStr string
jsonBytes, err := json.MarshalIndent(m, "", " ")
if err != nil {
actions_model "code.gitea.io/gitea/models/actions"
secret_model "code.gitea.io/gitea/models/secret"
actions_module "code.gitea.io/gitea/modules/actions"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
if len(task.Job.Needs) == 0 {
return nil, nil
}
- needs := map[string]struct{}{}
- for _, v := range task.Job.Needs {
- needs[v] = struct{}{}
- }
+ needs := container.SetOf(task.Job.Needs...)
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: task.Job.RunID})
if err != nil {
ret := make(map[string]*runnerv1.TaskNeed, len(needs))
for _, job := range jobs {
- if _, ok := needs[job.JobID]; !ok {
+ if !needs.Contains(job.JobID) {
continue
}
if job.TaskID == 0 || !job.Status.IsDone() {
// Remove repositories that should not be shown,
// which are repositories that have no issues and are not selected by the user.
- selectedReposMap := make(map[int64]struct{}, len(selectedRepoIDs))
- for _, repoID := range selectedRepoIDs {
- selectedReposMap[repoID] = struct{}{}
- }
+ selectedRepos := container.SetOf(selectedRepoIDs...)
for k, v := range issueCountByRepo {
- if _, ok := selectedReposMap[k]; !ok && v == 0 {
+ if v == 0 && !selectedRepos.Contains(k) {
delete(issueCountByRepo, k)
}
}
"code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
auth_module "code.gitea.io/gitea/modules/auth"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
source_service "code.gitea.io/gitea/services/auth/source"
usernameUsers := make(map[string]*user_model.User, len(users))
mailUsers := make(map[string]*user_model.User, len(users))
- keepActiveUsers := make(map[int64]struct{})
+ keepActiveUsers := make(container.Set[int64])
for _, u := range users {
usernameUsers[u.LowerName] = u
}
if usr != nil {
- keepActiveUsers[usr.ID] = struct{}{}
+ keepActiveUsers.Add(usr.ID)
} else if len(su.Username) == 0 {
// we cannot create the user if su.Username is empty
continue
// Deactivate users not present in LDAP
if updateExisting {
for _, usr := range users {
- if _, ok := keepActiveUsers[usr.ID]; ok {
+ if keepActiveUsers.Contains(usr.ID) {
continue
}
"strings"
"time"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/structs"
func (g *GitlabDownloader) awardsToReactions(awards []*gitlab.AwardEmoji) []*base.Reaction {
result := make([]*base.Reaction, 0, len(awards))
- uniqCheck := make(map[string]struct{})
+ uniqCheck := make(container.Set[string])
for _, award := range awards {
uid := fmt.Sprintf("%s%d", award.Name, award.User.ID)
- if _, ok := uniqCheck[uid]; !ok {
+ if uniqCheck.Add(uid) {
result = append(result, &base.Reaction{
UserID: int64(award.User.ID),
UserName: award.User.Username,
Content: award.Name,
})
- uniqCheck[uid] = struct{}{}
}
}
return result