-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Only show the latest version in the Arch index #33262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ddea32e
feat4arch
ExplodingDragon 0fca43e
Merge branch 'main' into feat-version-arch
ExplodingDragon 1dbf859
feat4arch
ExplodingDragon 08b3967
fix lint
ExplodingDragon 3b55815
add tests & fix lint
ExplodingDragon cae7f0b
rename settings
ExplodingDragon 8570827
add copyright
ExplodingDragon 0aae7c4
Merge branch 'main' into feat-version-arch
ExplodingDragon a8b043a
rename setting
ExplodingDragon d9c9b6b
Merge remote-tracking branch 'origin/feat-version-arch' into feat-ver…
ExplodingDragon ccfda05
Merge branch 'main' into feat-version-arch
ExplodingDragon 97ed2e7
fix typo
ExplodingDragon 220f23a
Merge branch 'main' into feat-version-arch
ExplodingDragon 39efb64
Merge branch 'main' into feat-version-arch
ExplodingDragon 8dba8a5
Merge branch 'main' into feat-version-arch
ExplodingDragon 7f98d5f
Merge branch 'main' into feat-version-arch
ExplodingDragon fa496e5
Merge branch 'main' into feat-version-arch
ExplodingDragon 9fa32ae
Merge branch 'main' into feat-version-arch
ExplodingDragon c869dc5
Merge branch 'main' into feat-version-arch
ExplodingDragon e7bbefb
remove options
ExplodingDragon 5d25559
Merge branch 'main' into feat-version-arch
ExplodingDragon d98ceb1
Merge branch 'main' into feat-version-arch
GiteaBot ffab002
Merge branch 'main' into feat-version-arch
GiteaBot de4db89
Merge branch 'main' into feat-version-arch
ExplodingDragon 219d872
Update services/packages/arch/repository.go
wxiaoguang fb0e0de
Merge branch 'main' into feat-version-arch
wxiaoguang 2667111
Merge branch 'main' into feat-version-arch
ExplodingDragon 718fc19
Merge branch 'main' into feat-version-arch
ExplodingDragon fed5aac
Merge branch 'main' into feat-version-arch
ExplodingDragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// 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) | ||
var l int | ||
if lenA > lenB { | ||
l = lenB | ||
} else { | ||
l = lenA | ||
} | ||
for i := 0; i < l; i++ { | ||
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}) | ||
} | ||
ExplodingDragon marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package arch | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCompareVersions(t *testing.T) { | ||
// https://man.archlinux.org/man/vercmp.8.en | ||
checks := [][]string{ | ||
{"1.0a", "1.0b", "1.0beta", "1.0p", "1.0pre", "1.0rc", "1.0", "1.0.a", "1.0.1"}, | ||
{"1", "1.0", "1.1", "1.1.1", "1.2", "2.0", "3.0.0"}, | ||
} | ||
for _, check := range checks { | ||
for i := 0; i < len(check)-1; i++ { | ||
require.Equal(t, -1, compareVersions(check[i], check[i+1])) | ||
require.Equal(t, 1, compareVersions(check[i+1], check[i])) | ||
} | ||
} | ||
require.Equal(t, 1, compareVersions("1.0-2", "1.0")) | ||
require.Equal(t, 0, compareVersions("0:1.0-1", "1.0")) | ||
require.Equal(t, 1, compareVersions("1:1.0-1", "2.0")) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.