Skip to content

Commit 07fee42

Browse files
committed
remove semver
1 parent d5c993c commit 07fee42

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ toolchain go1.24.2
77
require (
88
filippo.io/edwards25519 v1.1.0
99
github.com/BurntSushi/toml v1.3.2
10-
github.com/Masterminds/semver/v3 v3.3.1
1110
github.com/go-sql-driver/mysql v1.7.1
1211
github.com/goccy/go-json v0.10.2
1312
github.com/google/uuid v1.3.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
22
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
33
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
44
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
5-
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
6-
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
75
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
86
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
97
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

mysql/util.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mysql
22

33
import (
44
"bytes"
5+
"cmp"
56
"compress/zlib"
67
"crypto/rand"
78
"crypto/rsa"
@@ -13,11 +14,11 @@ import (
1314
"io"
1415
mrand "math/rand"
1516
"runtime"
17+
"strconv"
1618
"strings"
1719
"time"
1820

1921
"filippo.io/edwards25519"
20-
"github.com/Masterminds/semver/v3"
2122
"github.com/go-mysql-org/go-mysql/utils"
2223
"github.com/pingcap/errors"
2324
)
@@ -452,21 +453,43 @@ func ErrorEqual(err1, err2 error) bool {
452453
return e1.Error() == e2.Error()
453454
}
454455

456+
func compareSubVersion(typ, a, b, aFull, bFull string) (int, error) {
457+
var aNum, bNum int
458+
var err error
459+
460+
if aNum, err = strconv.Atoi(a); err != nil {
461+
return 0, fmt.Errorf("cannot parse %s version %s of %s", typ, a, aFull)
462+
}
463+
if bNum, err = strconv.Atoi(b); err != nil {
464+
return 0, fmt.Errorf("cannot parse %s version %s of %s", typ, b, bFull)
465+
}
466+
467+
return cmp.Compare(aNum, bNum), nil
468+
}
469+
455470
func CompareServerVersions(a, b string) (int, error) {
456-
var (
457-
aVer, bVer *semver.Version
458-
err error
459-
)
471+
aNumbers, _, _ := strings.Cut(a, "-")
472+
bNumbers, _, _ := strings.Cut(b, "-")
473+
474+
aMajor, aRest, _ := strings.Cut(aNumbers, ".")
475+
bMajor, bRest, _ := strings.Cut(bNumbers, ".")
476+
477+
if majorCompare, err := compareSubVersion("major", aMajor, bMajor, a, b); err != nil || majorCompare != 0 {
478+
return majorCompare, err
479+
}
480+
481+
aMinor, aPatch, _ := strings.Cut(aRest, ".")
482+
bMinor, bPatch, _ := strings.Cut(bRest, ".")
460483

461-
if aVer, err = semver.NewVersion(a); err != nil {
462-
return 0, fmt.Errorf("cannot parse %q as semver: %w", a, err)
484+
if minorCompare, err := compareSubVersion("minor", aMinor, bMinor, a, b); err != nil || minorCompare != 0 {
485+
return minorCompare, err
463486
}
464487

465-
if bVer, err = semver.NewVersion(b); err != nil {
466-
return 0, fmt.Errorf("cannot parse %q as semver: %w", b, err)
488+
if patchCompare, err := compareSubVersion("patch", aPatch, bPatch, a, b); err != nil || patchCompare != 0 {
489+
return patchCompare, err
467490
}
468491

469-
return aVer.Compare(bVer), nil
492+
return 0, nil
470493
}
471494

472495
var encodeRef = map[byte]byte{

0 commit comments

Comments
 (0)