-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLibRevision.lua
90 lines (74 loc) · 2.15 KB
/
LibRevision.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--[[
-- LibRevision.lua
-- Finds the revisions of a given addon and works out the version.
-- Written by Ken Allan <[email protected]>
-- This code is hereby released into the Public Domain without warranty.
--
-- Usage:
-- local libRevision = LibStub("LibRevision")
--
-- libRevision:Set("svnUrl", "svnRev", "5.1.DEV.", ...)
-- libRevision:Get("addon")
--]]
local LIBRARY_VERSION_MAJOR = "LibRevision"
local LIBRARY_VERSION_MINOR = 3
local lib = LibStub:NewLibrary(LIBRARY_VERSION_MAJOR, LIBRARY_VERSION_MINOR)
if not lib then return end
if not lib.versions then
lib.versions = {}
end
function lib:Get(addon)
return lib.versions[addon:lower()]
end
function lib:Set(url, revision, dev, ...)
local repo,file
if not (url and revision) then return end
local n = select("#", ...)
for i=1, n do
local sub = select(i, ...)
repo, file = url:match("%$URL: .*/("..sub..")/([^%$]+) %$")
if repo then break end
end
local rev = tonumber(revision:match("(%d+)")) or 0
if repo then
local branch,name = file:match("^(trunk)/([^/]+)/")
if not branch then
branch,name = file:match("^branches/([^/]+)/([^/]+)/")
end
if branch then
local embed, addition
local addon = name:lower()
local vaddon = lib.versions[addon]
if not vaddon then
vaddon = {}
lib.versions[addon] = vaddon
end
local vrev = max(vaddon['x-revision'] or 0, rev)
local ver = GetAddOnMetadata(addon, "Version")
if not ver or ver:sub(0,2) == "<%" then
ver = (dev or "DEV.")..vrev
if branch ~= "trunk" then -- if a DEV side branch, add to additional info
addition = branch
end
end
if not IsAddOnLoaded(addon) then
embed = true
addition = (addition or "").."/embedded"
end
if not vaddon["x-revisions"] then
vaddon["x-revisions"] = {}
end
vaddon.name = name
vaddon.version = ver
vaddon["x-branch"] = branch
vaddon["x-revision"] = vrev
vaddon["x-revisions"][file] = rev
vaddon["x-embedded"] = embed
vaddon["x-swatter-extra"] = addition
if SetAddOnDetail then
SetAddOnDetail(name, vaddon)
end
return vaddon, file, rev
end
end
end