| 1 | -- resty-gitweb@git/repo.lua |
| 2 | -- git repository utilities |
| 3 |
|
| 4 | -- Copyright (c) 2020 Joshua 'joshuas3' Stockin |
| 5 | -- <https://git.joshstock.in/resty-gitweb> |
| 6 | -- This software is licensed under the MIT License. |
| 7 |
|
| 8 | local ffi = require("ffi") |
| 9 |
|
| 10 | local _M = {} |
| 11 |
|
| 12 | -- Returns [bool exists, git_repository* repo] |
| 13 | _M.open = function(repo_dir) |
| 14 | local repo_obj = ffi.new("git_repository*[1]") |
| 15 | err = git2.git_repository_open(ffi.cast("git_repository**", repo_obj), repo_dir) |
| 16 | ret_obj = nil |
| 17 | if err == 0 then |
| 18 | ret_obj = repo_obj[0] |
| 19 | end |
| 20 | return err == 0, ret_obj |
| 21 | end |
| 22 |
|
| 23 | _M.free = function(repo_obj) |
| 24 | git2.git_repository_free(repo_obj) |
| 25 | end |
| 26 |
|
| 27 | return _M |
| 28 |
|