From 1f29de4805a603704ed437fc22e969ff656315c1 Mon Sep 17 00:00:00 2001 From: Jguer Date: Mon, 30 Oct 2017 21:19:05 +0900 Subject: [PATCH] References #61 --- Gopkg.lock | 2 +- upgrade.go | 4 +-- .../mikkeloscar/gopkgbuild/pkgbuild.go | 12 ++++----- .../mikkeloscar/gopkgbuild/pkgbuild_test.go | 26 +++++++++---------- .../mikkeloscar/gopkgbuild/version.go | 15 +++++------ .../mikkeloscar/gopkgbuild/version_test.go | 4 ++- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 52596c13..ca500686 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -17,7 +17,7 @@ branch = "master" name = "github.com/mikkeloscar/gopkgbuild" packages = ["."] - revision = "46d010163d87513b0f05fb67400475348bd50cc9" + revision = "a185f55210904932d0a58aaf30890f2c17218604" [solve-meta] analyzer-name = "dep" diff --git a/upgrade.go b/upgrade.go index 89b69d0c..14f896ba 100644 --- a/upgrade.go +++ b/upgrade.go @@ -80,11 +80,11 @@ func (u upSlice) Print(start int) { fmt.Printf("\x1b[1;%dm%s\x1b[0m/\x1b[1;39m%-25s\t\t\x1b[0m", f(i.Repository), i.Repository, i.Name) if old.Version != new.Version { - fmt.Printf("\x1b[31m%18s\x1b[0m-%d -> \x1b[1;32m%s\x1b[0m-%d\x1b[0m", + fmt.Printf("\x1b[31m%18s\x1b[0m-%s -> \x1b[1;32m%s\x1b[0m-%s\x1b[0m", old.Version, old.Pkgrel, new.Version, new.Pkgrel) } else { - fmt.Printf("\x1b[0m%18s-\x1b[31m%d\x1b[0m -> %s-\x1b[32m%d\x1b[0m", + fmt.Printf("\x1b[0m%18s-\x1b[31m%s\x1b[0m -> %s-\x1b[32m%s\x1b[0m", old.Version, old.Pkgrel, new.Version, new.Pkgrel) } diff --git a/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild.go b/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild.go index 8e7b0519..b6657613 100644 --- a/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild.go +++ b/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild.go @@ -64,7 +64,7 @@ type Dependency struct { type PKGBUILD struct { Pkgnames []string Pkgver Version // required - Pkgrel int // required + Pkgrel Version // required Pkgdir string Epoch int Pkgbase string @@ -132,10 +132,10 @@ func (p *PKGBUILD) Older(p2 *PKGBUILD) bool { // Version returns the full version of the PKGBUILD (including epoch and rel) func (p *PKGBUILD) Version() string { if p.Epoch > 0 { - return fmt.Sprintf("%d:%s-%d", p.Epoch, p.Pkgver, p.Pkgrel) + return fmt.Sprintf("%d:%s-%s", p.Epoch, p.Pkgver, p.Pkgrel) } - return fmt.Sprintf("%s-%d", p.Pkgver, p.Pkgrel) + return fmt.Sprintf("%s-%s", p.Pkgver, p.Pkgrel) } // CompleteVersion returns a Complete version struct including version, rel and @@ -144,7 +144,7 @@ func (p *PKGBUILD) CompleteVersion() CompleteVersion { return CompleteVersion{ Version: p.Pkgver, Epoch: uint8(p.Epoch), - Pkgrel: uint8(p.Pkgrel), + Pkgrel: p.Pkgrel, } } @@ -257,11 +257,11 @@ Loop: pkgbuild.Pkgver = version case itemPkgrel: next = lexer.nextItem() - rel, err := strconv.ParseInt(next.val, 10, 0) + rel, err := parseVersion(next.val) if err != nil { return nil, err } - pkgbuild.Pkgrel = int(rel) + pkgbuild.Pkgrel = rel case itemPkgdir: next = lexer.nextItem() pkgbuild.Pkgdir = next.val diff --git a/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild_test.go b/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild_test.go index 70ce285d..599a9f9e 100644 --- a/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild_test.go +++ b/vendor/github.com/mikkeloscar/gopkgbuild/pkgbuild_test.go @@ -31,9 +31,9 @@ func TestVersionParsing(t *testing.T) { // Test complete-version parsing func TestCompleteVersionParsing(t *testing.T) { versions := map[string]*CompleteVersion{ - "1:1.0beta": &CompleteVersion{Version("1.0beta"), 1, 0}, - "1.0": &CompleteVersion{Version("1.0"), 0, 0}, - "2.3-2": &CompleteVersion{Version("2.3"), 0, 2}, + "1:1.0beta": &CompleteVersion{Version("1.0beta"), 1, ""}, + "1.0": &CompleteVersion{Version("1.0"), 0, ""}, + "2.3-2": &CompleteVersion{Version("2.3"), 0, "2"}, "1::": nil, "4.3--1": nil, "4.1-a": nil, @@ -60,22 +60,22 @@ func TestNewer(t *testing.T) { a := &PKGBUILD{ Epoch: 0, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } b := &PKGBUILD{ Epoch: 0, Pkgver: Version("2.0"), - Pkgrel: 1, + Pkgrel: "1", } c := &PKGBUILD{ Epoch: 1, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } d := &PKGBUILD{ Epoch: 0, Pkgver: Version("1.0"), - Pkgrel: 2, + Pkgrel: "2", } if a.Newer(b) { @@ -100,22 +100,22 @@ func TestOlder(t *testing.T) { a := &PKGBUILD{ Epoch: 0, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } b := &PKGBUILD{ Epoch: 0, Pkgver: Version("2.0"), - Pkgrel: 1, + Pkgrel: "1", } c := &PKGBUILD{ Epoch: 1, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } d := &PKGBUILD{ Epoch: 0, Pkgver: Version("1.0"), - Pkgrel: 2, + Pkgrel: "2", } if !a.Older(b) { @@ -140,7 +140,7 @@ func TestVersionMethod(t *testing.T) { a := &PKGBUILD{ Epoch: 0, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } version := "1.0-1" @@ -152,7 +152,7 @@ func TestVersionMethod(t *testing.T) { b := &PKGBUILD{ Epoch: 4, Pkgver: Version("1.0"), - Pkgrel: 1, + Pkgrel: "1", } version = "4:1.0-1" diff --git a/vendor/github.com/mikkeloscar/gopkgbuild/version.go b/vendor/github.com/mikkeloscar/gopkgbuild/version.go index c57889a7..3a770ae8 100644 --- a/vendor/github.com/mikkeloscar/gopkgbuild/version.go +++ b/vendor/github.com/mikkeloscar/gopkgbuild/version.go @@ -12,7 +12,7 @@ type Version string type CompleteVersion struct { Version Version Epoch uint8 - Pkgrel uint8 + Pkgrel Version } func (c *CompleteVersion) String() string { @@ -24,7 +24,7 @@ func (c *CompleteVersion) String() string { func NewCompleteVersion(s string) (*CompleteVersion, error) { var err error epoch := 0 - rel := 0 + rel := Version("") // handle possible epoch versions := strings.Split(s, ":") @@ -46,10 +46,7 @@ func NewCompleteVersion(s string) (*CompleteVersion, error) { } if len(versions) > 1 { - rel, err = strconv.Atoi(versions[1]) - if err != nil { - return nil, err - } + rel = Version(versions[1]) } // finally check that the actual version is valid @@ -57,7 +54,7 @@ func NewCompleteVersion(s string) (*CompleteVersion, error) { return &CompleteVersion{ Version: Version(versions[0]), Epoch: uint8(epoch), - Pkgrel: uint8(rel), + Pkgrel: rel, }, nil } @@ -115,11 +112,11 @@ func (a *CompleteVersion) cmp(b *CompleteVersion) int8 { return -1 } - if a.Pkgrel > b.Pkgrel { + if a.Pkgrel.bigger(b.Pkgrel) { return 1 } - if a.Pkgrel < b.Pkgrel { + if b.Pkgrel.bigger(a.Pkgrel) { return -1 } diff --git a/vendor/github.com/mikkeloscar/gopkgbuild/version_test.go b/vendor/github.com/mikkeloscar/gopkgbuild/version_test.go index c8d5b61e..fcc23446 100644 --- a/vendor/github.com/mikkeloscar/gopkgbuild/version_test.go +++ b/vendor/github.com/mikkeloscar/gopkgbuild/version_test.go @@ -86,12 +86,13 @@ func TestCompleteVersionComparison(t *testing.T) { a := &CompleteVersion{ Version: "2", Epoch: 1, - Pkgrel: 2, + Pkgrel: Version("2"), } older := []string{ "0-3-4", "1-2-1", + "1-2-1.5", "1-1-1", } @@ -105,6 +106,7 @@ func TestCompleteVersionComparison(t *testing.T) { "2-1-1", "1-3-1", "1-2-3", + "1-2-2.1", } for _, n := range newer {