chore: remove usages of sort.Sort (#6689)

improve language stats rounding:

- Add tests (I had to omit some edge cases as the current method is
non-determistic in some cases, due to random order of map access).
- Document the algorithm used.
- Lower the amount of calculations that need to be done.
- Because of the aforementioned non-determistic don't use stable sort
and instead regular sort.

better sorting for `RepositoryList`:

- Add testing
- Use `slices.Sortfunc` instead of `sort.Sort`.
- Remove the methods needed for `sort.Sort`.

better git tag sorter:

- Use `slices.SortFunc` instead of `sort.Sort`.
- Remove `tagSorter` and its related methods.
- Added testing.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6689
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-01-26 13:30:00 +00:00 committed by Gusted
parent 048af05db9
commit 270a2c7fa3
8 changed files with 97 additions and 51 deletions

View file

@ -10,7 +10,6 @@ import (
"net/http"
"regexp"
"slices"
"sort"
"strconv"
"strings"
@ -242,7 +241,9 @@ func Milestones(ctx *context.Context) {
ctx.ServerError("SearchRepositoryByCondition", err)
return
}
sort.Sort(showRepos)
slices.SortFunc(showRepos, func(a, b *repo_model.Repository) int {
return strings.Compare(a.FullName(), b.FullName())
})
for i := 0; i < len(milestones); {
for _, repo := range showRepos {