This is an automated email from the ASF dual-hosted git repository. utzig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push: new 60ae37b newt - 1-dev and 1.0-dev should not compare equal 60ae37b is described below commit 60ae37b707f77a130cbda25678c315200076a43d Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Mon Nov 27 18:12:38 2017 -0800 newt - 1-dev and 1.0-dev should not compare equal Newt generated some false positives when comparing the desired repo version against an actual version. The problem was that unspecified version parts were set to 0. Thus, the following two versions would compare equal to one another: o 1-latest o 1.0-latest The fix is to set unspecified version parts to a special value (-1). --- newt/repo/version.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/newt/repo/version.go b/newt/repo/version.go index f09d38c..2dc723f 100644 --- a/newt/repo/version.go +++ b/newt/repo/version.go @@ -32,8 +32,6 @@ import ( log "github.com/Sirupsen/logrus" ) -const VERSION_FORMAT = "%d.%d.%d-%s" - const ( VERSION_STABILITY_NONE = "none" VERSION_STABILITY_STABLE = "stable" @@ -42,6 +40,10 @@ const ( VERSION_STABILITY_TAG = "tag" ) +// Represents an unspecified part in a version. For example, in "1-latest", +// the minor and revision parts are floating. +const VERSION_FLOATING = -1 + type VersionMatch struct { compareType string Vers *Version @@ -109,8 +111,8 @@ func (v *Version) CompareVersions(vers1 interfaces.VersionInterface, } func (v *Version) SatisfiesVersion(versMatches []interfaces.VersionReqInterface) bool { - if versMatches == nil { - return true + if len(versMatches) == 0 { + return false } for _, match := range versMatches { @@ -154,7 +156,18 @@ func (vers *Version) String() string { if vers.tag != "" { return fmt.Sprintf("%s-tag", vers.tag) } - return fmt.Sprintf(VERSION_FORMAT, vers.Major(), vers.Minor(), vers.Revision(), vers.Stability()) + + s := fmt.Sprintf("%d", vers.Major()) + if vers.Minor() != VERSION_FLOATING { + s += fmt.Sprintf(".%d", vers.Minor()) + } + if vers.Revision() != VERSION_FLOATING { + s += fmt.Sprintf(".%d", vers.Revision()) + } + + s += fmt.Sprintf("-%s", vers.Stability()) + + return s } func (vers *Version) ToNuVersion() newtutil.Version { @@ -182,20 +195,25 @@ func LoadVersion(versStr string) (*Version, error) { fallthrough case VERSION_STABILITY_LATEST: default: - return nil, util.NewNewtError( - fmt.Sprintf("Unknown stability (%s) in version ", stability) + versStr) + return nil, util.FmtNewtError( + "Unknown stability (%s) in version %s", stability, versStr) } } parts := strings.Split(sparts[0], ".") if len(parts) > 3 { - return nil, util.NewNewtError(fmt.Sprintf("Invalid version string: %s", versStr)) + return nil, util.FmtNewtError("Invalid version string: %s", versStr) } if strings.Trim(parts[0], " ") == "" || strings.Trim(parts[0], " ") == "none" { return nil, nil } - vers := &Version{} + // Assume no parts of the version are specified. + vers := &Version{ + major: VERSION_FLOATING, + minor: VERSION_FLOATING, + revision: VERSION_FLOATING, + } vers.stability = stability // convert first string to an int -- To stop receiving notification emails like this one, please contact ['"commits@mynewt.apache.org" <commits@mynewt.apache.org>'].