@@ -193,9 +193,9 @@ local function openRepo(path, bare)
193193 function M .head ()
194194 local ref = ffi .new (" git_reference*[1]" )
195195 check (lib .git_repository_head (ref , repo ))
196- --- @type git2.ffi.Reference
197- local r = ffi . gc (ref [0 ], lib . git_reference_free )
198- return oidStr ( lib . git_reference_target ( r ))
196+ local sha = oidStr ( lib . git_reference_target ( ref [ 0 ]))
197+ lib . git_reference_free (ref [0 ])
198+ return sha
199199 end
200200
201201 --- @param sha string
@@ -205,19 +205,19 @@ local function openRepo(path, bare)
205205 check (lib .git_oid_fromstr (oid , sha ))
206206 local cp = ffi .new (" git_commit*[1]" )
207207 check (lib .git_commit_lookup (cp , repo , oid ))
208- --- @type git2.ffi.Commit
209- local c = ffi . gc (cp [0 ], lib . git_commit_free )
210- return wrapCommit ( c )
208+ local info = wrapCommit ( cp [ 0 ])
209+ lib . git_commit_free (cp [0 ])
210+ return info
211211 end
212212
213213 --- @param spec string
214214 --- @return string
215215 function M .revparse (spec )
216216 local op = ffi .new (" git_object*[1]" )
217217 check (lib .git_revparse_single (op , repo , spec ))
218- --- @type git2.ffi.Object
219- local o = ffi . gc (op [0 ], lib . git_object_free )
220- return oidStr ( lib . git_object_id ( o ))
218+ local sha = oidStr ( lib . git_object_id ( op [ 0 ]))
219+ lib . git_object_free (op [0 ])
220+ return sha
221221 end
222222
223223 --- @generic T
@@ -226,9 +226,9 @@ local function openRepo(path, bare)
226226 local function withIndex (fn )
227227 local ip = ffi .new (" git_index*[1]" )
228228 check (lib .git_repository_index (ip , repo ))
229- --- @type git2.ffi.Index
230- local idx = ffi . gc (ip [0 ], lib . git_index_free )
231- return fn ( idx )
229+ local result = fn ( ip [ 0 ])
230+ lib . git_index_free (ip [0 ])
231+ return result
232232 end
233233
234234 --- @param relpath string
@@ -252,9 +252,8 @@ local function openRepo(path, bare)
252252 function M .fetch (remoteName )
253253 local rmt = ffi .new (" git_remote*[1]" )
254254 check (lib .git_remote_lookup (rmt , repo , remoteName ))
255- --- @type git2.ffi.Remote
256- local remote = ffi .gc (rmt [0 ], lib .git_remote_free )
257- check (lib .git_remote_fetch (remote , nil , nil , nil ))
255+ check (lib .git_remote_fetch (rmt [0 ], nil , nil , nil ))
256+ lib .git_remote_free (rmt [0 ])
258257 end
259258
260259 return M
0 commit comments