@@ -11,13 +11,13 @@ local M = {}
11
11
--- @param details ? boolean Fetching details is slow ! Don ' t loop over a plugin to fetch all details!
12
12
--- @return GitInfo ?
13
13
function M .info (repo , details )
14
- local line = Util .head (repo .. " /.git/HEAD " )
14
+ local line = M .head (repo )
15
15
if line then
16
16
--- @type string , string
17
- local ref , branch = line :match (" ref: ( refs/heads/(.*))" )
17
+ local ref , branch = line :match (" ref: refs/( heads/(.*))" )
18
18
local ret = ref and {
19
19
branch = branch ,
20
- commit = Util . head (repo .. " /.git/ " .. ref ),
20
+ commit = M . ref (repo , ref ),
21
21
} or { commit = line }
22
22
23
23
if details then
@@ -33,6 +33,10 @@ function M.info(repo, details)
33
33
end
34
34
end
35
35
36
+ function M .head (repo )
37
+ return Util .head (repo .. " /.git/HEAD" )
38
+ end
39
+
36
40
--- @class TaggedSemver : Semver
37
41
--- @field tag string
38
42
@@ -41,17 +45,32 @@ function M.get_versions(repo, spec)
41
45
local range = Semver .range (spec or " *" )
42
46
--- @type TaggedSemver[]
43
47
local versions = {}
44
- Util . ls ( repo .. " /.git/refs/tags " , function ( _ , name )
45
- local v = Semver .version (name )
48
+ for _ , tag in ipairs ( M . get_tags ( repo )) do
49
+ local v = Semver .version (tag )
46
50
--- @cast v TaggedSemver
47
51
if v and range :matches (v ) then
48
- v .tag = name
52
+ v .tag = tag
49
53
table.insert (versions , v )
50
54
end
51
- end )
55
+ end
52
56
return versions
53
57
end
54
58
59
+ function M .get_tags (repo )
60
+ --- @type string[]
61
+ local ret = {}
62
+ Util .ls (repo .. " /.git/refs/tags" , function (_ , name )
63
+ ret [# ret + 1 ] = name
64
+ end )
65
+ for name in pairs (M .packed_refs (repo )) do
66
+ local tag = name :match (" ^tags/(.*)" )
67
+ if tag then
68
+ ret [# ret + 1 ] = tag
69
+ end
70
+ end
71
+ return ret
72
+ end
73
+
55
74
--- @param plugin LazyPlugin
56
75
--- @return string ?
57
76
function M .get_branch (plugin )
@@ -69,7 +88,7 @@ function M.get_branch(plugin)
69
88
end
70
89
71
90
-- fallback to local HEAD
72
- main = assert (Util .head (plugin .dir .. " /.git/HEAD " ))
91
+ main = assert (M .head (plugin .dir ))
73
92
return main and main :match (" ref: refs/heads/(.*)" )
74
93
end
75
94
end
@@ -133,7 +152,22 @@ function M.ref(repo, ...)
133
152
end
134
153
135
154
-- otherwise just get the ref
136
- return Util .head (repo .. " /.git/refs/" .. ref )
155
+ return Util .head (repo .. " /.git/refs/" .. ref ) or M .packed_refs (repo )[ref ]
156
+ end
157
+
158
+ function M .packed_refs (repo )
159
+ local ok , refs = pcall (Util .read_file , repo .. " /.git/packed-refs" )
160
+ --- @type table<string,string>
161
+ local ret = {}
162
+ if ok then
163
+ for _ , line in ipairs (vim .split (refs , " \n " )) do
164
+ local ref , name = line :match (" ^(.*) refs/(.*)$" )
165
+ if ref then
166
+ ret [name ] = ref
167
+ end
168
+ end
169
+ end
170
+ return ret
137
171
end
138
172
139
173
-- this is slow, so don't use on a loop over all plugins!
0 commit comments