You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2017/11/28 08:39:30 UTC

[GitHub] utzig closed pull request #110: newt - 1-dev and 1.0-dev should not compare equal

utzig closed pull request #110: newt - 1-dev and 1.0-dev should not compare equal
URL: https://github.com/apache/mynewt-newt/pull/110
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services