Handle versions as returned from transformVersion (#16)

This commit is contained in:
Simon Frei 2018-03-24 09:08:58 +01:00 committed by Jakob Borg
parent c126831108
commit 69d05a3637
2 changed files with 21 additions and 12 deletions

View File

@ -190,27 +190,33 @@ func versionLess(a, b string) bool {
} }
} }
if apre != bpre { // Longer version is newer, when the preceding parts are equal
return apre < bpre
}
if len(arel) != len(brel) { if len(arel) != len(brel) {
return len(arel) < len(brel) return len(arel) < len(brel)
} }
if apre != bpre {
// "(+dev)" versions are ahead
if apre == plusStr {
return false
}
if bpre == plusStr {
return true
}
return apre < bpre
}
// don't actually care how the prerelease stuff compares for our purposes // don't actually care how the prerelease stuff compares for our purposes
return false return false
} }
// Split a version into parts. // Split a version as returned from transformVersion into parts.
// "1.2.3-beta.2" -> []int{1, 2, 3}, "beta.2"} // "1.2.3-beta.2" -> []int{1, 2, 3}, "beta.2"}
func versionParts(v string) ([]int, string) { func versionParts(v string) ([]int, string) {
if strings.HasPrefix(v, "v") || strings.HasPrefix(v, "V") { parts := strings.SplitN(v[1:], " ", 2) // " (+dev)" versions
// Strip initial 'v' or 'V' prefix if present. if len(parts) == 1 {
v = v[1:] parts = strings.SplitN(parts[0], "-", 2) // "-rc.1" type versions
} }
parts := strings.SplitN(v, "+", 2)
parts = strings.SplitN(parts[0], "-", 2)
fields := strings.Split(parts[0], ".") fields := strings.Split(parts[0], ".")
release := make([]int, len(fields)) release := make([]int, len(fields))

View File

@ -1350,7 +1350,10 @@ func ensureDir(dir string, mode int) {
} }
} }
var plusRe = regexp.MustCompile(`\+.*$`) var (
plusRe = regexp.MustCompile(`\+.*$`)
plusStr = "(+dev)"
)
// transformVersion returns a version number formatted correctly, with all // transformVersion returns a version number formatted correctly, with all
// development versions aggregated into one. // development versions aggregated into one.
@ -1361,7 +1364,7 @@ func transformVersion(v string) string {
if !strings.HasPrefix(v, "v") { if !strings.HasPrefix(v, "v") {
v = "v" + v v = "v" + v
} }
v = plusRe.ReplaceAllString(v, " (+dev)") v = plusRe.ReplaceAllString(v, " "+plusStr)
return v return v
} }