mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 12:53:43 +01:00 
			
		
		
		
	Upgrade to [v0.19.0](https://github.com/golang/tools/releases/tag/gopls%2Fv0.19.0) and fix issues. Runs with new `warning` serverity setting. This likely does less checks than before. Additionally, add `make fix` which runs modernize. This is also verified on CI. For the record, here are the issues discoverd when running with `info` severity, in case we want to fix these: ``` tests/integration/repo_test.go:95:5-14: could use tagged switch on i tests/integration/api_packages_generic_test.go:149:4-64: could use tagged switch on setting.Packages.Storage.Type services/webhook/msteams_test.go:33:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:59:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:85:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:111:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:138:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:161:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:187:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:213:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:239:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:266:4-33: could use tagged switch on fact.Name services/webhook/msteams_test.go:407:4-33: could use tagged switch on fact.Name tests/integration/api_packages_conan_test.go:350:6-33: could use tagged switch on pf.Name models/issues/tracked_time_test.go:98:3-18: could use tagged switch on user.ID tests/integration/api_token_test.go:505:5-43: could use tagged switch on minRequiredLevel services/gitdiff/gitdiff.go:220:33-46: method "getLineLegacy" is unused ``` --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
		
			
				
	
	
		
			109 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2025 The Gitea Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: MIT
 | 
						|
 | 
						|
package arch
 | 
						|
 | 
						|
import (
 | 
						|
	"strings"
 | 
						|
	"unicode"
 | 
						|
)
 | 
						|
 | 
						|
// https://gitlab.archlinux.org/pacman/pacman/-/blob/d55b47e5512808b67bc944feb20c2bcc6c1a4c45/lib/libalpm/version.c
 | 
						|
 | 
						|
import (
 | 
						|
	"strconv"
 | 
						|
)
 | 
						|
 | 
						|
func parseEVR(evr string) (epoch, version, release string) {
 | 
						|
	if before, after, f := strings.Cut(evr, ":"); f {
 | 
						|
		epoch = before
 | 
						|
		evr = after
 | 
						|
	} else {
 | 
						|
		epoch = "0"
 | 
						|
	}
 | 
						|
 | 
						|
	if before, after, f := strings.Cut(evr, "-"); f {
 | 
						|
		version = before
 | 
						|
		release = after
 | 
						|
	} else {
 | 
						|
		version = evr
 | 
						|
		release = "1"
 | 
						|
	}
 | 
						|
	return epoch, version, release
 | 
						|
}
 | 
						|
 | 
						|
func compareSegments(a, b []string) int {
 | 
						|
	lenA, lenB := len(a), len(b)
 | 
						|
	l := min(lenA, lenB)
 | 
						|
	for i := range l {
 | 
						|
		if r := compare(a[i], b[i]); r != 0 {
 | 
						|
			return r
 | 
						|
		}
 | 
						|
	}
 | 
						|
	if lenA == lenB {
 | 
						|
		return 0
 | 
						|
	} else if l == lenA {
 | 
						|
		return -1
 | 
						|
	}
 | 
						|
	return 1
 | 
						|
}
 | 
						|
 | 
						|
func compare(a, b string) int {
 | 
						|
	if a == b {
 | 
						|
		return 0
 | 
						|
	}
 | 
						|
 | 
						|
	aNumeric := isNumeric(a)
 | 
						|
	bNumeric := isNumeric(b)
 | 
						|
 | 
						|
	if aNumeric && bNumeric {
 | 
						|
		aInt, _ := strconv.Atoi(a)
 | 
						|
		bInt, _ := strconv.Atoi(b)
 | 
						|
		switch {
 | 
						|
		case aInt < bInt:
 | 
						|
			return -1
 | 
						|
		case aInt > bInt:
 | 
						|
			return 1
 | 
						|
		default:
 | 
						|
			return 0
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	if aNumeric {
 | 
						|
		return 1
 | 
						|
	}
 | 
						|
	if bNumeric {
 | 
						|
		return -1
 | 
						|
	}
 | 
						|
 | 
						|
	return strings.Compare(a, b)
 | 
						|
}
 | 
						|
 | 
						|
func isNumeric(s string) bool {
 | 
						|
	for _, c := range s {
 | 
						|
		if !unicode.IsDigit(c) {
 | 
						|
			return false
 | 
						|
		}
 | 
						|
	}
 | 
						|
	return true
 | 
						|
}
 | 
						|
 | 
						|
func compareVersions(a, b string) int {
 | 
						|
	if a == b {
 | 
						|
		return 0
 | 
						|
	}
 | 
						|
 | 
						|
	epochA, versionA, releaseA := parseEVR(a)
 | 
						|
	epochB, versionB, releaseB := parseEVR(b)
 | 
						|
 | 
						|
	if res := compareSegments([]string{epochA}, []string{epochB}); res != 0 {
 | 
						|
		return res
 | 
						|
	}
 | 
						|
 | 
						|
	if res := compareSegments(strings.Split(versionA, "."), strings.Split(versionB, ".")); res != 0 {
 | 
						|
		return res
 | 
						|
	}
 | 
						|
 | 
						|
	return compareSegments([]string{releaseA}, []string{releaseB})
 | 
						|
}
 |