From 4be6a54bc0835ea4c8da0ea7eb89b226c1c269a6 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 5 Aug 2014 19:38:31 +0200 Subject: [PATCH] Hide build version behind plus character (fixes #473) --- build.sh | 4 ++++ cmd/syncthing/main.go | 2 +- upgrade/upgrade_common.go | 3 ++- upgrade/upgrade_test.go | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 99f36dab..7066612b 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,11 @@ export COPYFILE_DISABLE=true export GO386=387 # Don't use SSE on 32 bit builds distFiles=(README.md LICENSE CONTRIBUTORS) # apart from the binary itself + +# replace "...-12-g123abc" with "...+12-g123abc" to remain semver compatible-ish version=$(git describe --always --dirty) +version=$(echo "$version" | sed 's/-\([0-9]\{1,3\}-g[0-9a-f]\{5,10\}\)/+\1/') + date=$(git show -s --format=%ct) user=$(whoami) host=$(hostname) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 872e6304..a1c50d0a 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -54,7 +54,7 @@ var l = logger.DefaultLogger func init() { if Version != "unknown-dev" { // If not a generic dev build, version string should come from git describe - exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-beta\d+)?(-\d+-g[0-9a-f]+)?(-dirty)?$`) + exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z0-9]+)*(\+\d+-g[0-9a-f]+)?(-dirty)?$`) if !exp.MatchString(Version) { l.Fatalf("Invalid version string %q;\n\tdoes not match regexp %v", Version, exp) } diff --git a/upgrade/upgrade_common.go b/upgrade/upgrade_common.go index 6dd06442..e3e5c633 100644 --- a/upgrade/upgrade_common.go +++ b/upgrade/upgrade_common.go @@ -114,7 +114,8 @@ func CompareVersions(a, b string) int { // Split a version into parts. // "1.2.3-beta.2" -> []int{1, 2, 3}, []interface{}{"beta", 2} func versionParts(v string) ([]int, []interface{}) { - parts := strings.SplitN(v, "-", 2) + parts := strings.SplitN(v, "+", 2) + parts = strings.SplitN(parts[0], "-", 2) fields := strings.Split(parts[0], ".") release := make([]int, len(fields)) diff --git a/upgrade/upgrade_test.go b/upgrade/upgrade_test.go index b369baf0..ccfb22f8 100644 --- a/upgrade/upgrade_test.go +++ b/upgrade/upgrade_test.go @@ -28,6 +28,9 @@ var testcases = []struct { {"1.0.0-beta.2", "1.0.0-beta.11", -1}, {"1.0.0-beta.11", "1.0.0-rc.1", -1}, {"1.0.0-rc.1", "1.0.0", -1}, + {"1.0.0+45", "1.0.0+23-dev-foo", 0}, + {"1.0.0-beta.23+45", "1.0.0-beta.23+23-dev-foo", 0}, + {"1.0.0-beta.3+99", "1.0.0-beta.24+0", -1}, } func TestCompareVersions(t *testing.T) {