@@ -37,9 +37,25 @@ dt.configuration.check_version(...,{2,0,0})
37
37
-- returns -1, 0, 1 if the first version is smaller, equal, greater than the second version,
38
38
-- or nil if one or both are of the wrong format
39
39
-- strings like "release-1.2.3" and "1.2.3+456~gb00b5" are fine, too
40
+ local function parse_version (s )
41
+ local rc = 0
42
+ local major , minor , patch = s :match (" (%d+)%.(%d+)%.(%d+)" )
43
+ if not major then
44
+ patch = 0
45
+ major , minor , rc = s :match (" (%d+)%.(%d+)rc(%d+)" )
46
+ end
47
+ if not major then
48
+ patch = 0
49
+ rc = 0
50
+ major , minor = s :match (" (%d+)%.(%d+)" )
51
+ end
52
+ return tonumber (major ), tonumber (minor ), tonumber (patch ), tonumber (rc )
53
+ end
54
+
40
55
local function compare_versions (a , b )
41
- local a_major , a_minor , a_patch = a :match (" (%d+)%.(%d+)%.(%d+)" )
42
- local b_major , b_minor , b_patch = b :match (" (%d+)%.(%d+)%.(%d+)" )
56
+ local a_major , a_minor , a_patch , a_rc = parse_version (a )
57
+ local b_major , b_minor , b_patch , b_rc = parse_version (b )
58
+
43
59
if a_major and a_minor and a_patch and b_major and b_minor and b_patch then
44
60
if a_major < b_major then return - 1 end
45
61
if a_major > b_major then return 1 end
@@ -50,13 +66,43 @@ local function compare_versions(a, b)
50
66
if a_patch < b_patch then return - 1 end
51
67
if a_patch > b_patch then return 1 end
52
68
69
+ -- when rc == 0 then it's a proper release and newer than the rcs
70
+ local m = math.max (a_rc , b_rc ) + 1
71
+ if a_rc == 0 then a_rc = m end
72
+ if b_rc == 0 then b_rc = m end
73
+ if a_rc < b_rc then return - 1 end
74
+ if a_rc > b_rc then return 1 end
75
+
53
76
return 0
54
77
else
55
78
return
56
79
end
57
80
end
58
81
59
82
83
+ -- local function test(a, b, r)
84
+ -- local cmp = compare_versions(a, b)
85
+ -- if(not cmp) then
86
+ -- print(a .. " ./. " .. b .. " => MALFORMED INPUT")
87
+ -- elseif(cmp == r) then
88
+ -- print(a .. " ./. " .. b .. " => PASSED")
89
+ -- else
90
+ -- print(a .. " ./. " .. b .. " => FAILED")
91
+ -- end
92
+ -- end
93
+ --
94
+ -- test("malformed", "1.0.0", 0)
95
+ -- test("2.0rc1+135~ge456b2b-dirty", "release-1.6.9", 1)
96
+ -- test("release-1.6.9", "2.0rc1+135~ge456b2b-dirty", -1)
97
+ -- test("2.0rc1+135~ge456b2b-dirty", "2.0rc2+135~ge456b2b-dirty", -1)
98
+ -- test("2.0rc2+135~ge456b2b-dirty", "2.0rc1+135~ge456b2b-dirty", 1)
99
+ -- test("2.0rc3+135~ge456b2b-dirty", "release-2.0", -1)
100
+ -- test("2.0rc3+135~ge456b2b-dirty", "release-2.0.0", -1)
101
+ -- test("1.0.0", "2.0.0", -1)
102
+ -- test("2.0.0", "1.0.0", 1)
103
+ -- test("3.0.0", "3.0.0", 0)
104
+
105
+
60
106
-- check stored timestamp and skip the check if the last time was not too long ago
61
107
-- for now we are assuming that os.time() returns seconds. that's not guaranteed but the case on many systems.
62
108
-- the reference date doesn't matter, as long as it's currently positive (we start with 0 the first time)
0 commit comments